Search in sources :

Example 71 with ManaCostsImpl

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

the class WordOfCommandTestFlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player sourceController = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    MageObject sourceObject = game.getObject(source.getSourceId());
    Card card = null;
    if (sourceController != null && targetPlayer != null && sourceObject != null) {
        Player controller = null;
        Spell wordOfCommand = game.getSpell(source.getSourceId());
        if (wordOfCommand != null) {
            if (wordOfCommand.getCommandedBy() != null) {
                controller = game.getPlayer(wordOfCommand.getCommandedBy());
            } else {
                controller = game.getPlayer(sourceController.getTurnControlledBy());
            }
        }
        if (controller == null) {
            // reset the controller to avoid NPE
            controller = sourceController;
        }
        // Look at target opponent's hand and choose a card from it
        TargetCard targetCard = new TargetCard(Zone.HAND, new FilterCard());
        if (controller.choose(Outcome.Discard, targetPlayer.getHand(), targetCard, game)) {
            card = game.getCard(targetCard.getFirstTarget());
        }
        // You control that player until Word of Command finishes resolving
        CardUtil.takeControlUnderPlayerStart(game, controller, targetPlayer, true);
        // The player plays that card if able
        if (card != null) {
            // While doing so, the player can activate mana abilities only if they're from lands that player controls
            RestrictionEffect effect = new WordOfCommandCantActivateEffect();
            effect.setTargetPointer(new FixedTarget(targetPlayer.getId()));
            game.addEffect(effect, source);
            // and only if mana they produce is spent to activate other mana abilities of lands they control and/or play that card
            ManaPool manaPool = targetPlayer.getManaPool();
            manaPool.setForcedToPay(true);
            manaPool.storeMana();
            int bookmark = game.bookmarkState();
            boolean canPlay = checkPlayability(card, targetPlayer, game, source);
            while (canPlay && targetPlayer.canRespond() && !targetPlayer.playCard(card, game, false, new ApprovingObject(source, game))) {
                SpellAbility spellAbility = card.getSpellAbility();
                if (spellAbility != null) {
                    spellAbility.getManaCostsToPay().clear();
                    spellAbility.getManaCostsToPay().addAll(spellAbility.getManaCosts());
                    // force rollback if card was deemed playable
                    ((ManaCostsImpl) spellAbility.getManaCostsToPay()).forceManaRollback(game, manaPool);
                    canPlay = checkPlayability(card, targetPlayer, game, source);
                } else {
                    break;
                }
            }
            if (!canPlay) {
                game.informPlayers(targetPlayer.getLogName() + " didn't play " + card.getLogName() + " (card can't be played)");
            }
            // duplicate in case of a new mana pool existing - probably not necessary, but just in case
            manaPool.setForcedToPay(false);
            // a rollback creates a new mana pool for the player, so it's necessary to find it again
            manaPool = targetPlayer.getManaPool();
            manaPool.setForcedToPay(false);
            game.removeBookmark(bookmark);
            targetPlayer.resetStoredBookmark(game);
            for (RestrictionEffect eff : game.getContinuousEffects().getRestrictionEffects()) {
                if (eff instanceof WordOfCommandCantActivateEffect) {
                    eff.discard();
                    break;
                }
            }
            game.getContinuousEffects().removeInactiveEffects(game);
            Spell spell = game.getSpell(card.getId());
            if (spell != null) {
                // If the chosen card is cast as a spell, you control the player while that spell is resolving
                spell.setCommandedBy(controller.getId());
            }
        }
        wordOfCommand = game.getSpell(source.getSourceId());
        if (wordOfCommand != null) {
            // You control the player until Word of Command finishes resolving
            wordOfCommand.setCommandedBy(controller.getId());
        } else {
            CardUtil.takeControlUnderPlayerEnd(game, controller, targetPlayer);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) SpellAbility(mage.abilities.SpellAbility) ManaPool(mage.players.ManaPool) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Example 72 with ManaCostsImpl

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

the class TargetPriorityTest method test_targetAmount_Performance.

@Test
// do not enable it in production, only for devs
@Ignore
public void test_targetAmount_Performance() {
    int cardsMultiplier = 3;
    Ability ability = new SimpleActivatedAbility(Zone.ALL, new DamageMultiEffect(3), new ManaCostsImpl("R"));
    ability.addTarget(new TargetCreaturePermanentAmount(3));
    addCustomCardWithAbility("damage 3", playerA, ability);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    // 1/1
    addCard(Zone.BATTLEFIELD, playerB, "Memnite", 1 * cardsMultiplier);
    // 2/2
    addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1 * cardsMultiplier);
    // 2/2 with ability
    addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 1 * cardsMultiplier);
    // 4/3
    addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 1 * cardsMultiplier);
    // 4/4 with ability
    addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 1 * cardsMultiplier);
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{R}: ");
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertAllCommandsUsed();
    assertPermanentCount(playerB, "Memnite", 1 * cardsMultiplier);
    assertPermanentCount(playerB, "Balduvian Bears", 1 * cardsMultiplier);
    assertPermanentCount(playerB, "Ashcoat Bear", 1 * cardsMultiplier);
    assertPermanentCount(playerB, "Golden Bear", 1 * cardsMultiplier - 1);
    assertPermanentCount(playerB, "Battering Sliver", 1 * cardsMultiplier);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DamageMultiEffect(mage.abilities.effects.common.DamageMultiEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 73 with ManaCostsImpl

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

the class TargetPriorityTest method test_targetAmount_NormalCase.

@Test
public void test_targetAmount_NormalCase() {
    Ability ability = new SimpleActivatedAbility(Zone.ALL, new DamageMultiEffect(3), new ManaCostsImpl("R"));
    ability.addTarget(new TargetCreaturePermanentAmount(3));
    addCustomCardWithAbility("damage 3", playerA, ability);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    // 1/1
    addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3);
    // 2/2
    addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3);
    // 2/2 with ability
    addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3);
    // 4/3
    addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3);
    // 4/4 with ability
    addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3);
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{R}: ");
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertAllCommandsUsed();
    assertPermanentCount(playerB, "Memnite", 3);
    assertPermanentCount(playerB, "Balduvian Bears", 3);
    assertPermanentCount(playerB, "Ashcoat Bear", 3);
    assertPermanentCount(playerB, "Golden Bear", 3 - 1);
    assertPermanentCount(playerB, "Battering Sliver", 3);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DamageMultiEffect(mage.abilities.effects.common.DamageMultiEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Test(org.junit.Test)

Example 74 with ManaCostsImpl

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

the class SparkDoubleTest method test_CopyOfSparksCopy_ByAbility.

@Test
public void test_CopyOfSparksCopy_ByAbility() {
    Ability ability = new SimpleActivatedAbility(new CreateTokenCopyTargetEffect(), new ManaCostsImpl(""));
    ability.addTarget(new TargetPermanent());
    addCustomCardWithAbility("copy", playerA, ability);
    // {3}{U}
    addCard(Zone.HAND, playerA, "Spark Double");
    addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
    // 
    // legendary
    addCard(Zone.BATTLEFIELD, playerA, "Akroma, Angel of Wrath", 1);
    // 
    // Create a 1/1 white Bird creature token with flying, then populate. (Create a token that’s a copy of a creature token you control.)
    // {3}{W}
    addCard(Zone.HAND, playerA, "Eyes in the Skies");
    addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
    // make copy of legendary creature (it's not legendary now)
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Spark Double");
    setChoice(playerA, true);
    setChoice(playerA, "Akroma, Angel of Wrath");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, playerA);
    checkPermanentCount("must have copy", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Akroma, Angel of Wrath", 2);
    // make copy of copy by CreateTokenCopyTargetEffect
    // showBattlefield("before last copy", 1, PhaseStep.PRECOMBAT_MAIN, playerA);
    // showAvailableAbilities("before last copy", 1, PhaseStep.PRECOMBAT_MAIN, playerA);
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "create a token that");
    addTarget(playerA, "Akroma, Angel of Wrath[only copy]");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, playerA);
    checkPermanentCount("must have copy", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Akroma, Angel of Wrath", 3);
    // showBattlefield("after all", 1, PhaseStep.BEGIN_COMBAT, playerA);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_COMBAT);
    execute();
    assertAllCommandsUsed();
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) Ability(mage.abilities.Ability) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetPermanent(mage.target.TargetPermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Test(org.junit.Test)

Example 75 with ManaCostsImpl

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

the class CommanderAffinityTest method test_Gained_Affinity.

@Test
public void test_Gained_Affinity() {
    // bug: Mycosynth Golem did not allow my commander, Karn, Silver Golem, to cost 0 even though I had 7+ artifacts on the board.
    Ability ability = new SimpleActivatedAbility(Zone.ALL, new CreateTokenEffect(new ArtifactWallToken(), 7), new ManaCostsImpl("R"));
    addCustomCardWithAbility("generate tokens", playerA, ability);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    // {5}
    addCard(Zone.COMMAND, playerA, "Karn, Silver Golem", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
    // 
    // Destroy target artifact.
    // {1}{R}
    addCard(Zone.HAND, playerA, "Ancient Grudge", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
    // 
    // Artifact creature spells you cast have affinity for artifacts. (They cost {1} less to cast for each artifact you control.)
    addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem", 1);
    // Affinity for artifacts
    // Artifact creature spells you cast have affinity for artifacts.
    // addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem");
    // addCard(Zone.HAND, playerA, "Alpha Myr"); // Creature - Myr  2/1
    checkCommandCardCount("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem", 1);
    checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", true);
    // first cast for 5 and destroy (prepare commander with additional cost)
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ancient Grudge", "Karn, Silver Golem");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkCommandCardCount("after destroy ", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem", 1);
    checkPlayableAbility("after destroy", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", false);
    // move to command zone
    setChoice(playerA, true);
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    // can't do the second cast with additional cost (must pay 2 + 5, but have only R)
    checkPlayableAbility("after move", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", false);
    // generate artifact tokens
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{R}: Create");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkPermanentCount("after tokens", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Wall", 7);
    checkPlayableAbility("after tokens", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", true);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ArtifactWallToken(mage.game.permanent.token.ArtifactWallToken) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Test(org.junit.Test)

Aggregations

ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)98 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)33 Ability (mage.abilities.Ability)26 Cost (mage.abilities.costs.Cost)26 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)23 UUID (java.util.UUID)16 Card (mage.cards.Card)16 ManaCosts (mage.abilities.costs.mana.ManaCosts)15 SpellAbility (mage.abilities.SpellAbility)14 FixedTarget (mage.target.targetpointer.FixedTarget)13 Test (org.junit.Test)13 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)12 ManaCost (mage.abilities.costs.mana.ManaCost)11 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)7 TargetPermanent (mage.target.TargetPermanent)7 MageObjectReference (mage.MageObjectReference)6 Effect (mage.abilities.effects.Effect)6 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)6