Search in sources :

Example 11 with ManaCosts

use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.

the class PlayerImpl method restore.

@Override
public void restore(Player player) {
    this.name = player.getName();
    this.human = player.isHuman();
    this.life = player.getLife();
    this.passed = player.isPassed();
    // Don't restore more global states. If restored they are probably cause for unintended draws (https://github.com/magefree/mage/issues/1205).
    // this.wins = player.hasWon();
    // this.loses = player.hasLost();
    // this.left = player.hasLeft();
    // this.quit = player.hasQuit();
    // Makes no sense to restore
    // this.priorityTimeLeft = player.getPriorityTimeLeft();
    // this.idleTimeout = player.hasIdleTimeout();
    // this.timerTimeout = player.hasTimerTimeout();
    // can't change so no need to restore
    // this.isTestMode = player.isTestMode();
    // This is meta data and should'nt be restored by rollback
    // this.userData = player.getUserData();
    this.library = player.getLibrary().copy();
    this.sideboard = player.getSideboard().copy();
    this.hand = player.getHand().copy();
    this.graveyard = player.getGraveyard().copy();
    // noinspection deprecation - it's ok to use it in inner methods
    this.commandersIds = new HashSet<>(player.getCommandersIds());
    this.abilities = player.getAbilities().copy();
    this.counters = player.getCounters().copy();
    this.landsPlayed = player.getLandsPlayed();
    this.landsPerTurn = player.getLandsPerTurn();
    this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn();
    this.maxHandSize = player.getMaxHandSize();
    this.maxAttackedBy = player.getMaxAttackedBy();
    this.manaPool = player.getManaPool().copy();
    // Restore user specific settings in case changed since state save
    this.manaPool.setAutoPayment(this.getUserData().isManaPoolAutomatic());
    this.manaPool.setAutoPaymentRestricted(this.getUserData().isManaPoolAutomaticRestricted());
    this.turns = player.getTurns();
    this.range = player.getRange();
    this.canGainLife = player.isCanGainLife();
    this.canLoseLife = player.isCanLoseLife();
    this.attachments.clear();
    this.attachments.addAll(player.getAttachments());
    this.inRange.clear();
    this.inRange.addAll(player.getInRange());
    this.canPayLifeCost = player.getCanPayLifeCost();
    this.sacrificeCostFilter = player.getSacrificeCostFilter() != null ? player.getSacrificeCostFilter().copy() : null;
    this.loseByZeroOrLessLife = player.canLoseByZeroOrLessLife();
    this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard();
    this.drawsOnOpponentsTurn = player.isDrawsOnOpponentsTurn();
    this.alternativeSourceCosts.clear();
    this.alternativeSourceCosts.addAll(player.getAlternativeSourceCosts());
    this.topCardRevealed = player.isTopCardRevealed();
    this.playersUnderYourControl.clear();
    this.playersUnderYourControl.addAll(player.getPlayersUnderYourControl());
    this.isGameUnderControl = player.isGameUnderControl();
    this.turnController = player.getTurnControlledBy();
    this.turnControllers.clear();
    this.turnControllers.addAll(player.getTurnControllers());
    this.reachedNextTurnAfterLeaving = player.hasReachedNextTurnAfterLeaving();
    this.clearCastSourceIdManaCosts();
    this.castSourceIdWithAlternateMana.clear();
    this.castSourceIdWithAlternateMana.addAll(player.getCastSourceIdWithAlternateMana());
    for (Entry<UUID, ManaCosts<ManaCost>> entry : player.getCastSourceIdManaCosts().entrySet()) {
        this.castSourceIdManaCosts.put(entry.getKey(), (entry.getValue() == null ? null : entry.getValue().copy()));
    }
    for (Entry<UUID, Costs<Cost>> entry : player.getCastSourceIdCosts().entrySet()) {
        this.castSourceIdCosts.put(entry.getKey(), (entry.getValue() == null ? null : entry.getValue().copy()));
    }
    this.phyrexianColors = player.getPhyrexianColors() != null ? player.getPhyrexianColors().copy() : null;
    this.designations.clear();
    for (Designation object : player.getDesignations()) {
        this.designations.add(object.copy());
    }
// Don't restore!
// this.storedBookmark
// this.usersAllowedToSeeHandCards
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Designation(mage.designations.Designation) ManaCosts(mage.abilities.costs.mana.ManaCosts)

Example 12 with ManaCosts

use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.

the class NumaJoragaChieftainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    ManaCosts cost = new ManaCostsImpl("{X}{X}");
    if (!player.chooseUse(Outcome.BoostCreature, "Pay " + cost.getText() + "?", source, game)) {
        return false;
    }
    int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    cost.add(new GenericManaCost(2 * costX));
    if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, costX, false, ""), false, "distribute " + costX + " +1/+1 counters among any number of target Elves");
    ability.addTarget(new TargetCreaturePermanentAmount(costX, filter));
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DistributeCountersEffect(mage.abilities.effects.common.counter.DistributeCountersEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 13 with ManaCosts

use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.

the class ElectropotenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID creatureId = (UUID) getValue("damageSource");
    Permanent creature = game.getPermanentOrLKIBattlefield(creatureId);
    Player controller = game.getPlayer(source.getControllerId());
    if (creature != null && controller != null) {
        if (controller.chooseUse(Outcome.Damage, "Pay {2}{R} to do the damage?", source, game)) {
            // if (controller.chooseUse(Outcome.Damage, "Pay {2}{R}? If you do, " + creature.getName() + " deals damage equal to its power to any target.", game)) {
            ManaCosts manaCosts = new ManaCostsImpl("{2}{R}");
            if (manaCosts.pay(source, game, source, controller.getId(), false, null)) {
                int amount = creature.getPower().getValue();
                UUID target = source.getTargets().getFirstTarget();
                Permanent targetCreature = game.getPermanent(target);
                if (targetCreature != null) {
                    targetCreature.damage(amount, creature.getId(), source, game, false, true);
                } else {
                    Player player = game.getPlayer(target);
                    if (player != null) {
                        player.damage(amount, creature.getId(), source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 14 with ManaCosts

use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.

the class JeskaiInfiltratorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> cardsToManifest = new HashSet<>();
        cardsToManifest.add(source.getSourcePermanentIfItStillExists(game));
        cardsToManifest.add(controller.getLibrary().getFromTop(game));
        UUID exileId = UUID.randomUUID();
        controller.moveCardsToExile(cardsToManifest, source, game, false, exileId, "");
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        for (Card card : exileZone.getCards(game)) {
            card.setFaceDown(true, game);
        }
        // removes Jeskai Infiltrator from Battlefield, so Jeskai Infiltrator returns as a fresh permanent to the battlefield with new position
        game.fireUpdatePlayersEvent();
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        // the Set will mimic the Shuffling
        exileZone.getCards(game).forEach(card -> {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        });
        controller.moveCards(exileZone.getCards(game), Zone.BATTLEFIELD, source, game, false, true, false, null);
        return true;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DealsCombatDamageToAPlayerTriggeredAbility(mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility) Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) HashSet(java.util.HashSet) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 15 with ManaCosts

use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.

the class ScrollOfFateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || controller.getHand().isEmpty()) {
        return false;
    }
    TargetCardInHand targetCard = new TargetCardInHand();
    if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(), targetCard, source, game)) {
        return false;
    }
    Ability newSource = source.copy();
    newSource.setWorksFaceDown(true);
    Set<Card> cards = targetCard.getTargets().stream().map(game::getCard).filter(Objects::nonNull).collect(Collectors.toSet());
    cards.stream().forEach(card -> {
        ManaCosts manaCosts = null;
        if (card.isCreature(game)) {
            manaCosts = card.getSpellAbility() != null ? card.getSpellAbility().getManaCosts() : null;
            if (manaCosts == null) {
                manaCosts = new ManaCostsImpl("{0}");
            }
        }
        MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
        game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED), newSource);
    });
    controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
    cards.stream().map(Card::getId).map(game::getPermanent).filter(permanent -> permanent != null).forEach(permanent -> permanent.setManifested(true));
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInHand(mage.target.common.TargetCardInHand) ManaCosts(mage.abilities.costs.mana.ManaCosts) Zone(mage.constants.Zone) Outcome(mage.constants.Outcome) Set(java.util.Set) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) TapSourceCost(mage.abilities.costs.common.TapSourceCost) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect) Card(mage.cards.Card) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Aggregations

ManaCosts (mage.abilities.costs.mana.ManaCosts)21 Player (mage.players.Player)16 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)15 Permanent (mage.game.permanent.Permanent)8 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)7 MageObjectReference (mage.MageObjectReference)6 Ability (mage.abilities.Ability)6 BecomesFaceDownCreatureEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)6 Card (mage.cards.Card)6 UUID (java.util.UUID)4 OneShotEffect (mage.abilities.effects.OneShotEffect)3 Set (java.util.Set)2 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)2 ManaCost (mage.abilities.costs.mana.ManaCost)2 Effect (mage.abilities.effects.Effect)2 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 FilterPermanent (mage.filter.FilterPermanent)2 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)2