diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/ItThatBetrays.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/ItThatBetrays.java index 3f968a57018..9a1e3d18b4a 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/ItThatBetrays.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/ItThatBetrays.java @@ -28,16 +28,27 @@ package mage.sets.riseoftheeldrazi; import java.util.UUID; + import mage.constants.CardType; +import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.Zone; import mage.MageInt; +import mage.abilities.Ability; import mage.abilities.common.OpponentSacrificesNonTokenPermanentTriggeredAbility; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlTargetEffect; import mage.abilities.keyword.AnnihilatorAbility; +import mage.cards.Card; import mage.cards.CardImpl; import mage.filter.FilterPermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.permanent.TokenPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.targetpointer.FixedTarget; /** @@ -63,7 +74,7 @@ public class ItThatBetrays extends CardImpl { this.addAbility(new AnnihilatorAbility(2)); // Whenever an opponent sacrifices a nontoken permanent, put that card onto the battlefield under your control. - this.addAbility(new OpponentSacrificesNonTokenPermanentTriggeredAbility(new ReturnToBattlefieldUnderYourControlTargetEffect())); + this.addAbility(new OpponentSacrificesNonTokenPermanentTriggeredAbility(new ItThatBetraysReturnEffect())); } public ItThatBetrays(final ItThatBetrays card) { @@ -74,4 +85,39 @@ public class ItThatBetrays extends CardImpl { public ItThatBetrays copy() { return new ItThatBetrays(this); } + + class ItThatBetraysReturnEffect extends OneShotEffect { + + public ItThatBetraysReturnEffect() { + super(Outcome.Benefit); + } + + public ItThatBetraysReturnEffect(ItThatBetraysReturnEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + //The effect doesn't care what zone the card is currently in + Card card = game.getCard(((FixedTarget) targetPointer).getTarget()); + + if (card != null) { + Zone currentZone = game.getState().getZone(card.getId()); + controller.putOntoBattlefieldWithInfo(card, game, currentZone, source.getSourceId()); + } + + return true; + } + + return false; + } + + @Override + public Effect copy() { + return new ItThatBetraysReturnEffect(this); + } + + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/control/ItThatBetraysTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/control/ItThatBetraysTest.java index 77ac310ff5f..e48bd054ec9 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/control/ItThatBetraysTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/control/ItThatBetraysTest.java @@ -67,4 +67,25 @@ public class ItThatBetraysTest extends CardTestPlayerBase { assertGraveyardCount(playerA, "Flooded Strand", 1); } + //It That Betrays doesn't care what zone the card is when the effect resolves. It will return the card regardless. + @Test + public void testExileItThatBetraysEffect() { + addCard(Zone.BATTLEFIELD, playerA, "Flooded Strand", 1); + + addCard(Zone.BATTLEFIELD, playerA, "Rest in Peace", 1); + + addCard(Zone.BATTLEFIELD, playerB, "It That Betrays"); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Pay 1 life, Sacrifice"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 19); + assertLife(playerB, 20); + + // Player B now controls a Flooded Strand, even though it went to exile + assertPermanentCount(playerB, "Flooded Strand", 1); + } + } diff --git a/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderYourControlTargetEffect.java b/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderYourControlTargetEffect.java index b9bd9b40663..9989b06b275 100644 --- a/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderYourControlTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/ReturnToBattlefieldUnderYourControlTargetEffect.java @@ -37,6 +37,7 @@ import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.game.ExileZone; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; @@ -87,12 +88,18 @@ public class ReturnToBattlefieldUnderYourControlTargetEffect extends OneShotEffe } } } else { + UUID cardId = targetPointer.getFirst(game, source); if(targetPointer instanceof FixedTarget) { - card = game.getCard(((FixedTarget) targetPointer).getTarget()); - } else { - card = game.getCard(targetPointer.getFirst(game, source)); + UUID fixedTargetCardId = ((FixedTarget) targetPointer).getTarget(); + //Moved zones from battlefield to graveyard + if(fixedTargetCardId != null && cardId == null) { + Permanent permanent = game.getPermanentOrLKIBattlefield(fixedTargetCardId); + if(permanent != null) { + cardId = fixedTargetCardId; + } + } } - + card = game.getCard(cardId); } if (card != null) { Zone currentZone = game.getState().getZone(card.getId());