diff --git a/Mage.Sets/src/mage/cards/d/DisorderInTheCourt.java b/Mage.Sets/src/mage/cards/d/DisorderInTheCourt.java index 80c749e4ac8..985054731fe 100644 --- a/Mage.Sets/src/mage/cards/d/DisorderInTheCourt.java +++ b/Mage.Sets/src/mage/cards/d/DisorderInTheCourt.java @@ -1,18 +1,30 @@ package mage.cards.d; import mage.abilities.Ability; +import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.dynamicvalue.common.ManacostVariableValue; -import mage.abilities.effects.common.ExileTargetForSourceEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect; import mage.abilities.effects.keyword.InvestigateEffect; +import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.cards.CardsImpl; import mage.constants.CardType; +import mage.constants.Outcome; import mage.game.Game; +import mage.players.Player; import mage.target.common.TargetCreaturePermanent; import mage.target.targetadjustment.TargetAdjuster; +import mage.target.targetpointer.FixedTargets; +import mage.util.CardUtil; +import java.util.LinkedHashSet; +import java.util.Objects; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; /** * @author TheElk801 @@ -23,12 +35,7 @@ public final class DisorderInTheCourt extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{W}{U}"); // Exile X target creatures, then investigate X times. Return the exiled cards to the battlefield tapped under their owners' control at the beginning of the next end step. - this.getSpellAbility().addEffect(new ExileTargetForSourceEffect() - .setText("exile X target creatures")); - this.getSpellAbility().addEffect(new InvestigateEffect(ManacostVariableValue.REGULAR) - .setText(", then investigate X times")); - this.getSpellAbility().addEffect(new ReturnToBattlefieldUnderOwnerControlTargetEffect(true, true) - .setText("Return the exiled cards to the battlefield tapped under their owners' control at the beginning of the next end step")); + this.getSpellAbility().addEffect(new DisorderInTheCourtEffect()); this.getSpellAbility().setTargetAdjuster(DisorderInTheCourtAdjuster.instance); } @@ -51,3 +58,44 @@ enum DisorderInTheCourtAdjuster implements TargetAdjuster { ability.addTarget(new TargetCreaturePermanent(ability.getManaCostsToPay().getX())); } } + +class DisorderInTheCourtEffect extends OneShotEffect { + + DisorderInTheCourtEffect() { + super(Outcome.Benefit); + staticText = "Exile X target creatures, then investigate X times. Return the exiled cards to the battlefield tapped under their owners' control at the beginning of the next end step"; + } + + private DisorderInTheCourtEffect(final DisorderInTheCourtEffect effect) { + super(effect); + } + + @Override + public DisorderInTheCourtEffect copy() { + return new DisorderInTheCourtEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + Set toExile = getTargetPointer().getTargets(game, source) + .stream() + .map(game::getPermanent) + .filter(Objects::nonNull) + .collect(Collectors.toCollection(LinkedHashSet::new)); + if (toExile.isEmpty()) { + return false; + } + controller.moveCardsToExile(toExile, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source)); + game.getState().processAction(game); + new InvestigateEffect(ManacostVariableValue.REGULAR).apply(game, source); + Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(true, true); + effect.setTargetPointer(new FixedTargets(new CardsImpl(toExile), game)); + game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source); + return true; + } + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/DisorderInTheCourtTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/DisorderInTheCourtTest.java new file mode 100644 index 00000000000..0519016b77b --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/DisorderInTheCourtTest.java @@ -0,0 +1,44 @@ +package org.mage.test.cards.single.clb; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +public class DisorderInTheCourtTest extends CardTestPlayerBase { + + // {X}{W}{U} Instant + // Exile X target creatures, then investigate X times. + // Return the exiled cards to the battlefield tapped under their owners’ control at the beginning of the next end step. + private static final String disorder = "Disorder in the Court"; + private static final String leonin = "Leonin Elder"; // Whenever an artifact enters the battlefield, you may gain 1 life. + private static final String lizard = "Lagac Lizard"; + + + @Test + public void testDisorder() { + addCard(Zone.BATTLEFIELD, playerA, "Tundra", 4); + addCard(Zone.BATTLEFIELD, playerA, leonin); + addCard(Zone.BATTLEFIELD, playerB, lizard); + addCard(Zone.HAND, playerA, disorder); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, disorder); + setChoice(playerA, "X=2"); + addTarget(playerA, leonin); + addTarget(playerA, lizard); + + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, leonin, 1); + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, lizard, 1); + checkPermanentCount("Clue tokens", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Clue Token", 2); + + setStrictChooseMode(true); + setStopAt(2, PhaseStep.UPKEEP); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + assertTapped(leonin, true); + assertPermanentCount(playerB, lizard, 1); + } + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/LaezelsAcrobaticsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/LaezelsAcrobaticsTest.java index 62ee8b77469..3e3053a7fd2 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/LaezelsAcrobaticsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/clb/LaezelsAcrobaticsTest.java @@ -35,6 +35,11 @@ public class LaezelsAcrobaticsTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, knight); setDieRollResult(playerA, 9); castSpell(1, PhaseStep.BEGIN_COMBAT, playerA, acrobatics); + + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, knight, 1); + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, auramancer, 1); + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, dwarf, 1); + setChoice(playerA, "When {this} enters the battlefield, create"); // order triggers setChoice(playerA, true); // Auramancer: yes to return addTarget(playerA, wings); // enchantment to return @@ -65,6 +70,11 @@ public class LaezelsAcrobaticsTest extends CardTestPlayerBase { setChoice(playerA, "When {this} enters the battlefield, create"); // order triggers setChoice(playerA, true); // Auramancer: yes to return addTarget(playerA, wings); // enchantment to return + + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, knight, 1); + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, auramancer, 1); + checkExileCount("Exiled", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, dwarf, 1); + setChoice(playerA, "When {this} enters the battlefield, create"); // order triggers setChoice(playerA, true); // Auramancer: yes to return addTarget(playerA, wings); // enchantment to return