diff --git a/Mage.Sets/src/mage/cards/h/Hypnox.java b/Mage.Sets/src/mage/cards/h/Hypnox.java index 62c1d3c64c8..a8bc90b813b 100644 --- a/Mage.Sets/src/mage/cards/h/Hypnox.java +++ b/Mage.Sets/src/mage/cards/h/Hypnox.java @@ -7,6 +7,7 @@ import mage.abilities.common.LeavesBattlefieldTriggeredAbility; import mage.abilities.condition.common.CastFromHandSourcePermanentCondition; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.ReturnFromExileForSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -14,7 +15,6 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.Zone; -import mage.game.ExileZone; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetOpponent; @@ -48,7 +48,8 @@ public final class Hypnox extends CardImpl { this.addAbility(ability, new CastFromHandWatcher()); // When Hypnox leaves the battlefield, return the exiled cards to their owner's hand. - this.addAbility(new LeavesBattlefieldTriggeredAbility(new HypnoxReturnEffect(), false)); + this.addAbility(new LeavesBattlefieldTriggeredAbility(new ReturnFromExileForSourceEffect(Zone.HAND) + .withText(true, false, false), false)); } private Hypnox(final Hypnox card) { @@ -90,27 +91,3 @@ class HypnoxExileEffect extends OneShotEffect { return new HypnoxExileEffect(this); } } - -class HypnoxReturnEffect extends OneShotEffect { - - HypnoxReturnEffect() { - super(Outcome.ReturnToHand); - this.staticText = "return the exiled cards to their owner's hand"; - } - - private HypnoxReturnEffect(final HypnoxReturnEffect effect) { - super(effect); - } - - @Override - public HypnoxReturnEffect copy() { - return new HypnoxReturnEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - ExileZone exZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)); - return controller != null && exZone != null && controller.moveCards(exZone, Zone.HAND, source, game); - } -} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/tor/HypnoxTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/tor/HypnoxTest.java new file mode 100644 index 00000000000..86a881f8af9 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/tor/HypnoxTest.java @@ -0,0 +1,47 @@ +package org.mage.test.cards.single.tor; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author xenohedron + */ +public class HypnoxTest extends CardTestPlayerBase { + + private static final String hypnox = "Hypnox"; + /** Hypnox {8}{B}{B}{B} + * Flying + * When Hypnox enters the battlefield, if you cast it from your hand, exile all cards from target opponent’s hand. + * When Hypnox leaves the battlefield, return the exiled cards to their owner’s hand. + */ + + @Test + public void testExileAndReturn() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 11); + addCard(Zone.HAND, playerA, hypnox); + addCard(Zone.HAND, playerB, "Shock"); + addCard(Zone.HAND, playerB, "Watchwolf"); + addCard(Zone.BATTLEFIELD, playerA, "Bloodthrone Vampire"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, hypnox); + addTarget(playerA, playerB); + + checkPT("Hypnox", 1, PhaseStep.BEGIN_COMBAT, playerA, hypnox, 8, 8); + checkExileCount("exiled from hand", 1, PhaseStep.BEGIN_COMBAT, playerB, "Shock", 1); + checkExileCount("exiled from hand", 1, PhaseStep.BEGIN_COMBAT, playerB, "Watchwolf", 1); + + activateAbility(1, PhaseStep.END_COMBAT, playerA, "Sacrifice"); + setChoice(playerA, hypnox); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerA, hypnox, 1); + assertHandCount(playerB, "Shock", 1); + assertHandCount(playerB, "Watchwolf", 1); + } + +}