Remove custom multitarget handling from ExileTargetEffect (use EachTargetPointer instead)

This commit is contained in:
Alex W. Jackson 2022-09-03 22:59:19 -04:00
parent fbccdd3088
commit c6e1ce6697
5 changed files with 40 additions and 116 deletions

View file

@ -1,33 +1,26 @@
package mage.cards.g;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility;
import mage.abilities.condition.common.SourceOnBattlefieldCondition;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.ExileTargetEffect;
import mage.abilities.effects.common.ExileUntilSourceLeavesEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.targetadjustment.TargetAdjuster;
import mage.util.CardUtil;
import mage.target.targetpointer.EachTargetPointer;
import java.util.UUID;
/**
* @author fireshoes
* @author awjackson
*/
public final class GraspOfFate extends CardImpl {
@ -35,7 +28,10 @@ public final class GraspOfFate extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}{W}");
// When Grasp of Fate enters the battlefield, for each opponent, exile up to one target nonland permanent that player controls until Grasp of Fate leaves the battlefield.
Ability ability = new EntersBattlefieldTriggeredAbility(new GraspOfFateExileEffect());
Ability ability = new EntersBattlefieldTriggeredAbility(new ExileUntilSourceLeavesEffect("")
.setTargetPointer(new EachTargetPointer())
.setText("for each opponent, exile up to one target nonland permanent that player controls until {this} leaves the battlefield")
);
ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()));
ability.setTargetAdjuster(GraspOfFateAdjuster.instance);
this.addAbility(ability);
@ -70,29 +66,3 @@ enum GraspOfFateAdjuster implements TargetAdjuster {
}
}
}
class GraspOfFateExileEffect extends OneShotEffect {
public GraspOfFateExileEffect() {
super(Outcome.Benefit);
this.staticText = "for each opponent, exile up to one target nonland permanent that player controls until {this} leaves the battlefield";
}
public GraspOfFateExileEffect(final GraspOfFateExileEffect effect) {
super(effect);
}
@Override
public GraspOfFateExileEffect copy() {
return new GraspOfFateExileEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) { // 11/4/2015: If Grasp of Fate leaves the battlefield before its triggered ability resolves, no nonland permanents will be exiled.
return new ConditionalOneShotEffect(new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName(), Zone.BATTLEFIELD, true), SourceOnBattlefieldCondition.instance).apply(game, source);
}
return false;
}
}

View file

@ -22,7 +22,7 @@ import java.util.UUID;
*/
public final class MindbreakTrap extends CardImpl {
private static final FilterSpell filter = new FilterSpell("spell to exile");
private static final FilterSpell filter = new FilterSpell("spells");
public MindbreakTrap(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{U}{U}");
@ -33,7 +33,7 @@ public final class MindbreakTrap extends CardImpl {
// Exile any number of target spells.
this.getSpellAbility().addTarget(new TargetSpell(0, Integer.MAX_VALUE, filter));
this.getSpellAbility().addEffect(new ExileTargetEffect("Exile any number of target spells", true));
this.getSpellAbility().addEffect(new ExileTargetEffect("Exile any number of target spells"));
}
private MindbreakTrap(final MindbreakTrap card) {

View file

@ -21,9 +21,7 @@ public final class RatsFeast extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{B}");
// Exile X target cards from a single graveyard.
this.getSpellAbility().addEffect(new ExileTargetEffect(
"Exile X target cards from a single graveyard", true
));
this.getSpellAbility().addEffect(new ExileTargetEffect("Exile X target cards from a single graveyard"));
this.getSpellAbility().setTargetAdjuster(RatsFeastAdjuster.instance);
}
@ -46,4 +44,4 @@ enum RatsFeastAdjuster implements TargetAdjuster {
ability.getTargets().clear();
ability.addTarget(new TargetCardInASingleGraveyard(xValue, xValue, StaticFilters.FILTER_CARD_CARDS));
}
}
}

View file

@ -6,9 +6,11 @@ import mage.abilities.hint.common.OpenSideboardHint;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.filter.StaticFilters;
import mage.filter.FilterCard;
import mage.filter.common.FilterInstantOrSorceryCard;
import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.SecondTargetPointer;
import java.util.UUID;
@ -17,16 +19,18 @@ import java.util.UUID;
*/
public final class RiseOfExtus extends CardImpl {
private static final FilterCard filter = new FilterInstantOrSorceryCard("instant or sorcery card from a graveyard");
public RiseOfExtus(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{W/B}{W/B}");
// Exile target creature. Exile up to one target instant or sorcery card from a graveyard.
this.getSpellAbility().addEffect(new ExileTargetEffect("Exile target creature. " +
"Exile up to one target instant or sorcery card from a graveyard.", true));
// Exile target creature.
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addTarget(new TargetCardInGraveyard(
0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY
));
this.getSpellAbility().addEffect(new ExileTargetEffect());
// Exile up to one target instant or sorcery card from a graveyard.
this.getSpellAbility().addTarget(new TargetCardInGraveyard(0, 1, filter));
this.getSpellAbility().addEffect(new ExileTargetEffect().setTargetPointer(new SecondTargetPointer()));
// Learn.
this.getSpellAbility().addEffect(new LearnEffect().concatBy("<br>"));

View file

@ -29,18 +29,12 @@ public class ExileTargetEffect extends OneShotEffect {
private final Zone onlyFromZone;
private String exileZone = null;
private UUID exileId = null;
protected boolean multitargetHandling;
private boolean toSourceExileZone = false; // exile the targets to a source object specific exile zone (takes care of zone change counter)
private boolean withName = true;
public ExileTargetEffect(String effectText) {
this(effectText, false);
}
public ExileTargetEffect(String effectText, boolean multitargetHandling) {
this();
this.staticText = effectText;
this.multitargetHandling = multitargetHandling;
}
/**
@ -56,15 +50,10 @@ public class ExileTargetEffect extends OneShotEffect {
}
public ExileTargetEffect(UUID exileId, String exileZone, Zone onlyFromZone) {
this(exileId, exileZone, onlyFromZone, false);
}
public ExileTargetEffect(UUID exileId, String exileZone, Zone onlyFromZone, boolean multitargetHandling) {
super(Outcome.Exile);
this.exileZone = exileZone;
this.exileId = exileId;
this.onlyFromZone = onlyFromZone;
this.multitargetHandling = multitargetHandling;
}
public ExileTargetEffect(final ExileTargetEffect effect) {
@ -72,7 +61,6 @@ public class ExileTargetEffect extends OneShotEffect {
this.exileZone = effect.exileZone;
this.exileId = effect.exileId;
this.onlyFromZone = effect.onlyFromZone;
this.multitargetHandling = effect.multitargetHandling;
this.toSourceExileZone = effect.toSourceExileZone;
this.withName = effect.withName;
}
@ -96,65 +84,29 @@ public class ExileTargetEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> toExile = new LinkedHashSet<>();
if (multitargetHandling
&& targetPointer instanceof FirstTargetPointer
&& (source.getTargets().size() > 1
|| (source.getTargets().size() > 0
&& source.getTargets().get(0).getTargets().size() > 1))) {
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null
&& permanent.isPhasedIn()) {
Zone currentZone = game.getState().getZone(permanent.getId());
if (currentZone != Zone.EXILED
&& (onlyFromZone == null
|| onlyFromZone == Zone.BATTLEFIELD)) {
toExile.add(permanent);
}
} else {
Card card = game.getCard(targetId);
if (card != null) {
Zone currentZone = game.getState().getZone(card.getId());
if (currentZone != Zone.EXILED
&& (onlyFromZone == null
|| onlyFromZone == currentZone)) {
toExile.add(card);
}
} else {
StackObject stackObject = game.getStack().getStackObject(targetId);
if (stackObject instanceof Spell) {
toExile.add((Spell) stackObject);
}
}
}
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null
&& permanent.isPhasedIn()) {
Zone currentZone = game.getState().getZone(permanent.getId());
if (currentZone != Zone.EXILED
&& (onlyFromZone == null
|| onlyFromZone == Zone.BATTLEFIELD)) {
toExile.add(permanent);
}
}
} else {
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null
&& permanent.isPhasedIn()) {
Zone currentZone = game.getState().getZone(permanent.getId());
} else {
Card card = game.getCard(targetId);
if (card != null) {
Zone currentZone = game.getState().getZone(card.getId());
if (currentZone != Zone.EXILED
&& (onlyFromZone == null
|| onlyFromZone == Zone.BATTLEFIELD)) {
toExile.add(permanent);
|| onlyFromZone == currentZone)) {
toExile.add(card);
}
} else {
Card card = game.getCard(targetId);
if (card != null) {
Zone currentZone = game.getState().getZone(card.getId());
if (currentZone != Zone.EXILED
&& (onlyFromZone == null
|| onlyFromZone == currentZone)) {
toExile.add(card);
}
} else {
StackObject stackObject = game.getStack().getStackObject(targetId);
if (stackObject instanceof Spell) {
toExile.add((Spell) stackObject);
}
StackObject stackObject = game.getStack().getStackObject(targetId);
if (stackObject instanceof Spell) {
toExile.add((Spell) stackObject);
}
}
}