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;
}
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);
}
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);
}
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();
}
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();
}
Aggregations