diff --git a/Mage.Sets/src/mage/sets/mirrodin/FieryGambit.java b/Mage.Sets/src/mage/sets/mirrodin/FieryGambit.java index c95dbad0ffe..8f291f43f75 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/FieryGambit.java +++ b/Mage.Sets/src/mage/sets/mirrodin/FieryGambit.java @@ -28,15 +28,15 @@ package mage.sets.mirrodin; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DamagePlayersEffect; import mage.abilities.effects.common.UntapAllLandsControllerEffect; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; import mage.constants.TargetController; import mage.game.Game; import mage.game.permanent.Permanent; @@ -53,7 +53,6 @@ public class FieryGambit extends CardImpl { super(ownerId, 90, "Fiery Gambit", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{2}{R}"); this.expansionSetCode = "MRD"; - // Flip a coin until you lose a flip or choose to stop flipping. If you lose a flip, Fiery Gambit has no effect. If you win one or more flips, Fiery Gambit deals 3 damage to target creature. If you win two or more flips, Fiery Gambit deals 6 damage to each opponent. If you win three or more flips, draw nine cards and untap all lands you control. this.getSpellAbility().addEffect(new FieryGambitEffect()); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); @@ -69,7 +68,6 @@ public class FieryGambit extends CardImpl { } } - class FieryGambitEffect extends OneShotEffect { public FieryGambitEffect() { @@ -89,12 +87,13 @@ class FieryGambitEffect extends OneShotEffect { @java.lang.Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { + MageObject sourceObject = source.getSourceObject(game); + if (controller != null && sourceObject != null) { int flipsWon = 0; boolean controllerStopped = false; while (controller.flipCoin(game)) { ++flipsWon; - if (!controller.chooseUse(outcome, new StringBuilder("You won ").append(flipsWon).append(flipsWon == 1?" flip.":" flips.") + if (!controller.chooseUse(outcome, new StringBuilder("You won ").append(flipsWon).append(flipsWon == 1 ? " flip." : " flips.") .append(" Flip another coin?").toString(), source, game)) { controllerStopped = true; break; @@ -113,7 +112,7 @@ class FieryGambitEffect extends OneShotEffect { new UntapAllLandsControllerEffect().apply(game, source); } } else { - game.informPlayers("Fiery Gambit had no effect"); + game.informPlayers(sourceObject.getIdName() + " had no effect"); } return true; } diff --git a/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java b/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java index 0cdacc0dde0..a48bc1732a1 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java +++ b/Mage.Sets/src/mage/sets/mirrodin/KrarksThumb.java @@ -29,15 +29,15 @@ package mage.sets.mirrodin; import java.util.Random; import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.abilities.Ability; -import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; -import mage.cards.CardImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; @@ -68,6 +68,7 @@ public class KrarksThumb extends CardImpl { } class KrarksThumbEffect extends ReplacementEffectImpl { + KrarksThumbEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit); staticText = "If you would flip a coin, instead flip two coins and ignore one"; @@ -88,9 +89,9 @@ class KrarksThumbEffect extends ReplacementEffectImpl { } if (player.chooseUse(outcome, "Ignore the first coin flip?", source, game)) { event.setFlag(secondCoinFlip); - game.informPlayers(new StringBuilder(player.getLogName()).append(" ignores the first coin flip.").toString()); + game.informPlayers(player.getLogName() + " ignores the first coin flip."); } else { - game.informPlayers(new StringBuilder(player.getLogName()).append(" ignores the second coin flip.").toString()); + game.informPlayers(player.getLogName() + " ignores the second coin flip."); } } return false; diff --git a/Mage.Sets/src/mage/sets/theros/GiftOfImmortality.java b/Mage.Sets/src/mage/sets/theros/GiftOfImmortality.java index e2652db7329..beb90cc4c31 100644 --- a/Mage.Sets/src/mage/sets/theros/GiftOfImmortality.java +++ b/Mage.Sets/src/mage/sets/theros/GiftOfImmortality.java @@ -59,7 +59,6 @@ public class GiftOfImmortality extends CardImpl { this.expansionSetCode = "THS"; this.subtype.add("Aura"); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); @@ -67,9 +66,9 @@ public class GiftOfImmortality extends CardImpl { Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); - // When enchanted creature dies, return that card to the battlefield under its owner's control. + // When enchanted creature dies, return that card to the battlefield under its owner's control. // Return Gift of Immortality to the battlefield attached to that creature at the beginning of the next end step. - this.addAbility(new DiesAttachedTriggeredAbility(new GiftOfImmortalityEffect(),"enchanted creature", false)); + this.addAbility(new DiesAttachedTriggeredAbility(new GiftOfImmortalityEffect(), "enchanted creature", false)); } public GiftOfImmortality(final GiftOfImmortality card) { @@ -106,21 +105,22 @@ class GiftOfImmortalityEffect extends OneShotEffect { if (card != null) { Zone currentZone = game.getState().getZone(card.getId()); if (card.putOntoBattlefield(game, currentZone, source.getSourceId(), card.getOwnerId())) { - //create delayed triggered ability - Effect effect = new GiftOfImmortalityReturnEnchantmentEffect(); - effect.setTargetPointer(new FixedTarget(card.getId())); - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - game.addDelayedTriggeredAbility(delayedAbility); + Permanent permanent = game.getPermanent(card.getId()); + if (permanent != null) { + //create delayed triggered ability + Effect effect = new GiftOfImmortalityReturnEnchantmentEffect(); + effect.setTargetPointer(new FixedTarget(permanent, game)); + AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect); + delayedAbility.setSourceId(source.getSourceId()); + delayedAbility.setControllerId(source.getControllerId()); + delayedAbility.setSourceObject(source.getSourceObject(game), game); + game.addDelayedTriggeredAbility(delayedAbility); + } } return true; } } - - return false; } } @@ -128,7 +128,7 @@ class GiftOfImmortalityEffect extends OneShotEffect { class GiftOfImmortalityReturnEnchantmentEffect extends OneShotEffect { public GiftOfImmortalityReturnEnchantmentEffect() { - super(Outcome.BoostCreature); + super(Outcome.PutCardInPlay); staticText = "Return {this} to the battlefield attached to that creature at the beginning of the next end step"; } @@ -140,11 +140,11 @@ class GiftOfImmortalityReturnEnchantmentEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Card aura = game.getCard(source.getSourceId()); if (aura != null && game.getState().getZone(aura.getId()).equals(Zone.GRAVEYARD)) { - Player you = game.getPlayer(source.getControllerId()); + Player controller = game.getPlayer(source.getControllerId()); Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source)); - if (you != null && creature != null) { + if (controller != null && creature != null) { game.getState().setValue("attachTo:" + aura.getId(), creature); - aura.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), you.getId()); + aura.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), controller.getId()); return creature.addAttachment(aura.getId(), game); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CommanderReplaceEffectTest.java b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CommanderReplaceEffectTest.java index e20431c07e6..50de4a66e0d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CommanderReplaceEffectTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CommanderReplaceEffectTest.java @@ -74,4 +74,37 @@ public class CommanderReplaceEffectTest extends CardTestCommanderDuelBase { assertPermanentCount(playerB, "Horror", 1); assertPowerToughness(playerB, "Horror", 1, 1); } + + @Test + public void saveCommanderWithGiftOfImmortality() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + addCard(Zone.BATTLEFIELD, playerA, "Island", 1); + + // Enchant creature + // When enchanted creature dies, return that card to the battlefield under its owner's control. + // Return Gift of Immortality to the battlefield attached to that creature at the beginning of the next end step. + addCard(Zone.HAND, playerA, "Gift of Immortality", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Plains", 6); + addCard(Zone.HAND, playerB, "Phyrexian Rebirth", 1); + + // Daxos of Meletis can't be blocked by creatures with power 3 or greater. + // Whenever Daxos of Meletis deals combat damage to a player, exile the top card of that player's library. You gain life equal to that card's converted mana cost. Until end of turn, you may cast that card and you may spend mana as though it were mana of any color to cast it. + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Daxos of Meletis"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gift of Immortality", "Daxos of Meletis"); + + // Destroy all creatures, then put an X/X colorless Horror artifact creature token onto the battlefield, where X is the number of creatures destroyed this way. + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Phyrexian Rebirth"); + setChoice(playerA, "No"); // Let the commander go to graveyard because of Gift of Immortality + + setStopAt(3, PhaseStep.UPKEEP); + execute(); + + assertPermanentCount(playerB, "Horror", 1); + assertPowerToughness(playerB, "Horror", 1, 1); + + assertPermanentCount(playerA, "Daxos of Meletis", 1); + assertPermanentCount(playerA, "Gift of Immortality", 1); + + } }