This commit is contained in:
Jeff Wadsworth 2023-11-28 17:13:15 -06:00
parent b695f8906c
commit 70069f2937
2 changed files with 89 additions and 33 deletions

View file

@ -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;
}
}

View file

@ -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,";
}
}