From 70069f2937097e119fa9c6fa4429ee0c64548a8f Mon Sep 17 00:00:00 2001 From: Jeff Wadsworth Date: Tue, 28 Nov 2023 17:13:15 -0600 Subject: [PATCH] Fixed #11451 --- Mage.Sets/src/mage/cards/r/ReturnToDust.java | 94 ++++++++++++------- .../common/ControllerMainPhaseCondition.java | 28 ++++++ 2 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/condition/common/ControllerMainPhaseCondition.java diff --git a/Mage.Sets/src/mage/cards/r/ReturnToDust.java b/Mage.Sets/src/mage/cards/r/ReturnToDust.java index 35e23bb97fe..eeece3b5772 100644 --- a/Mage.Sets/src/mage/cards/r/ReturnToDust.java +++ b/Mage.Sets/src/mage/cards/r/ReturnToDust.java @@ -14,6 +14,8 @@ import mage.players.Player; import mage.target.TargetPermanent; import java.util.UUID; +import mage.abilities.condition.common.ControllerMainPhaseCondition; +import mage.abilities.decorator.ConditionalOneShotEffect; /** * @author emerald000 @@ -23,9 +25,16 @@ public final class ReturnToDust extends CardImpl { public ReturnToDust(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{W}{W}"); - // Exile target artifact or enchantment. If you cast this spell during your main phase, you may exile up to one other target artifact or enchantment. - this.getSpellAbility().addEffect(new ReturnToDustEffect()); - this.getSpellAbility().addTarget(new TargetPermanent(1, 2, StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT, false)); + // Exile target artifact or enchantment + this.getSpellAbility().addEffect(new ReturnToDustExileEffect()); + // If you cast this spell during your main phase, you may exile up to one other target artifact or enchantment + ConditionalOneShotEffect returnToDustConditionalExileEffect = + new ConditionalOneShotEffect(new ReturnToDustConditionalExileEffect(), ControllerMainPhaseCondition.instance); + returnToDustConditionalExileEffect.setText("If you cast this spell during your main phase, you may exile up to one other target artifact or enchantment"); + this.getSpellAbility().addEffect(returnToDustConditionalExileEffect); + this.getSpellAbility().addTarget(new TargetPermanent(0, 2, StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT)); + + // Two effects are needed to handle cards like Ranar the Ever-Watchful. Rule 608.2e } private ReturnToDust(final ReturnToDust card) { @@ -38,49 +47,68 @@ public final class ReturnToDust extends CardImpl { } } -class ReturnToDustEffect extends OneShotEffect { +class ReturnToDustExileEffect extends OneShotEffect { - ReturnToDustEffect() { - super(Outcome.DestroyPermanent); - staticText = "Exile target artifact or enchantment. If you cast this spell during your main phase, you may exile up to one other target artifact or enchantment"; + ReturnToDustExileEffect() { + super(Outcome.Detriment); + staticText = "Exile target artifact or enchantment"; } - private ReturnToDustEffect(final ReturnToDustEffect effect) { + private ReturnToDustExileEffect(final ReturnToDustExileEffect effect) { super(effect); } @Override - public ReturnToDustEffect copy() { - return new ReturnToDustEffect(this); + public ReturnToDustExileEffect copy() { + return new ReturnToDustExileEffect(this); } @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player == null) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { return false; } - int targetsCleared = 0; - for (UUID targetId : getTargetPointer().getTargets(game, source)) { - Permanent permanent = game.getPermanent(targetId); - if (permanent == null) { - continue; - } - if (targetsCleared == 0) { - player.moveCards(permanent, Zone.EXILED, source, game); - targetsCleared++; - } else if (targetsCleared == 1) { - if (game.isActivePlayer(source.getControllerId()) && game.isMainPhase() - && player.chooseUse(outcome, "Exile another permanent?", source, game)) { - player.moveCards(permanent, Zone.EXILED, source, game); - targetsCleared++; - } else { - break; - } - } else { - break; - } + + // Exile the first target + Permanent firstTarget = game.getPermanent(source.getFirstTarget()); + if (firstTarget != null) { + controller.moveCards(firstTarget, Zone.EXILED, source, game); + return true; } - return true; + return false; + } +} + +class ReturnToDustConditionalExileEffect extends OneShotEffect { + + ReturnToDustConditionalExileEffect() { + super(Outcome.Detriment); + } + + private ReturnToDustConditionalExileEffect(final ReturnToDustConditionalExileEffect effect) { + super(effect); + } + + @Override + public ReturnToDustConditionalExileEffect copy() { + return new ReturnToDustConditionalExileEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + if (source.getTargets().get(0).getSize() > 1) { + Permanent secondTarget = game.getPermanent(source.getTargets().get(0).getTargets().get(1)); + if (secondTarget != null + && controller.chooseUse(Outcome.Detriment, "Exile the second permanent?", source, game)) { + controller.moveCards(secondTarget, Zone.EXILED, source, game); + return true; + } + } + return false; } } diff --git a/Mage/src/main/java/mage/abilities/condition/common/ControllerMainPhaseCondition.java b/Mage/src/main/java/mage/abilities/condition/common/ControllerMainPhaseCondition.java new file mode 100644 index 00000000000..1ead6d9873b --- /dev/null +++ b/Mage/src/main/java/mage/abilities/condition/common/ControllerMainPhaseCondition.java @@ -0,0 +1,28 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package mage.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; + +/** + * + * @author jeffwadsworth + */ +public enum ControllerMainPhaseCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + return game.isActivePlayer(source.getControllerId()) + && game.isMainPhase(); + } + + @Override + public String toString() { + return "If this is your main phase,"; + } +}