From f6ed3a4d19b16cf207b69078d99eb9f2e137b122 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 26 Sep 2018 22:13:35 -0400 Subject: [PATCH] updated target adjusters D through G --- Mage.Sets/src/mage/cards/d/DeathDenied.java | 30 +++++------ Mage.Sets/src/mage/cards/d/DeathMatch.java | 36 ++++++------- .../src/mage/cards/d/DecimatorBeetle.java | 37 +++++-------- Mage.Sets/src/mage/cards/d/Detonate.java | 33 ++++++------ .../src/mage/cards/d/DiluvianPrimordial.java | 52 ++++++++++--------- Mage.Sets/src/mage/cards/d/Disembowel.java | 36 +++++++------ .../src/mage/cards/d/DistortingWake.java | 30 +++++------ Mage.Sets/src/mage/cards/d/Dominate.java | 34 ++++++------ Mage.Sets/src/mage/cards/d/DregsOfSorrow.java | 43 ++++++++------- .../src/mage/cards/e/EliteScaleguard.java | 42 +++++---------- .../src/mage/cards/e/EntrancingMelody.java | 35 +++++++------ Mage.Sets/src/mage/cards/g/GangUp.java | 34 ++++++------ .../src/mage/cards/g/GlimpseTheSunGod.java | 32 ++++++------ Mage.Sets/src/mage/cards/g/GoblinBarrage.java | 35 +++++++++---- .../src/mage/cards/g/GoblinRacketeer.java | 30 ++++------- Mage.Sets/src/mage/cards/g/GraspOfFate.java | 44 +++++++++------- .../src/mage/cards/g/GravenAbomination.java | 35 ++++--------- Mage.Sets/src/mage/cards/g/Gridlock.java | 37 ++++++------- Mage.Sets/src/mage/cards/g/GrimReturn.java | 44 +++++++++------- .../main/java/mage/MageObjectReference.java | 9 +++- Mage/src/main/java/mage/cards/CardImpl.java | 4 +- 21 files changed, 348 insertions(+), 364 deletions(-) diff --git a/Mage.Sets/src/mage/cards/d/DeathDenied.java b/Mage.Sets/src/mage/cards/d/DeathDenied.java index 0fe70f8a59..baf509a483 100644 --- a/Mage.Sets/src/mage/cards/d/DeathDenied.java +++ b/Mage.Sets/src/mage/cards/d/DeathDenied.java @@ -2,7 +2,6 @@ package mage.cards.d; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect; import mage.cards.CardImpl; @@ -13,35 +12,24 @@ import mage.filter.common.FilterCreatureCard; import mage.game.Game; import mage.target.Target; import mage.target.common.TargetCardInYourGraveyard; +import mage.target.targetadjustment.TargetAdjuster; import java.util.UUID; /** - * * @author LevelX2 */ public final class DeathDenied extends CardImpl { public DeathDenied(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{X}{B}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{B}{B}"); this.subtype.add(SubType.ARCANE); // Return X target creature cards from your graveyard to your hand. Effect effect = new ReturnFromGraveyardToHandTargetEffect(); effect.setText("Return X target creature cards from your graveyard to your hand"); this.getSpellAbility().addEffect(effect); - this.getSpellAbility().addTarget(new TargetCardInYourGraveyard(1, new FilterCreatureCard())); - - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - Target target = new TargetCardInYourGraveyard(xValue, new FilterCreatureCard(new StringBuilder(xValue).append(xValue != 1 ? " creature cards" : "creature card").append(" from your graveyard").toString())); - ability.addTarget(target); - } + this.getSpellAbility().setTargetAdjuster(DeathDeniedAdjuster.instance); } public DeathDenied(final DeathDenied card) { @@ -53,3 +41,15 @@ public final class DeathDenied extends CardImpl { return new DeathDenied(this); } } + +enum DeathDeniedAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + Target target = new TargetCardInYourGraveyard(xValue, new FilterCreatureCard(new StringBuilder(xValue).append(xValue != 1 ? " creature cards" : "creature card").append(" from your graveyard").toString())); + ability.addTarget(target); + } +} diff --git a/Mage.Sets/src/mage/cards/d/DeathMatch.java b/Mage.Sets/src/mage/cards/d/DeathMatch.java index d5827dfbd0..389b27cd26 100644 --- a/Mage.Sets/src/mage/cards/d/DeathMatch.java +++ b/Mage.Sets/src/mage/cards/d/DeathMatch.java @@ -1,7 +1,5 @@ - package mage.cards.d; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAllTriggeredAbility; import mage.abilities.effects.OneShotEffect; @@ -13,17 +11,16 @@ import mage.filter.StaticFilters; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; import mage.target.targetpointer.FirstTargetPointer; +import java.util.UUID; + /** - * * @author LoneFox - * */ public final class DeathMatch extends CardImpl { - private final UUID originalId; - public DeathMatch(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}"); @@ -32,24 +29,12 @@ public final class DeathMatch extends CardImpl { Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new DeathMatchEffect(), StaticFilters.FILTER_PERMANENT_CREATURE, false, SetTargetPointer.PLAYER, ""); ability.addTarget(new TargetCreaturePermanent()); + ability.setTargetAdjuster(DeathMatchAdjuster.instance); this.addAbility(ability); - originalId = ability.getOriginalId(); - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability.getOriginalId().equals(originalId)) { - UUID controllerId = ability.getEffects().get(0).getTargetPointer().getFirst(game, ability); - if (controllerId != null) { - ability.getTargets().get(0).setTargetController(controllerId); - ability.getEffects().get(0).setTargetPointer(new FirstTargetPointer()); - } - } } public DeathMatch(final DeathMatch card) { super(card); - this.originalId = card.originalId; } @Override @@ -58,6 +43,19 @@ public final class DeathMatch extends CardImpl { } } +enum DeathMatchAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + UUID controllerId = ability.getEffects().get(0).getTargetPointer().getFirst(game, ability); + if (controllerId != null) { + ability.getTargets().get(0).setTargetController(controllerId); + ability.getEffects().get(0).setTargetPointer(new FirstTargetPointer()); + } + } +} + class DeathMatchEffect extends OneShotEffect { public DeathMatchEffect() { diff --git a/Mage.Sets/src/mage/cards/d/DecimatorBeetle.java b/Mage.Sets/src/mage/cards/d/DecimatorBeetle.java index 2d0c35432a..83060b5472 100644 --- a/Mage.Sets/src/mage/cards/d/DecimatorBeetle.java +++ b/Mage.Sets/src/mage/cards/d/DecimatorBeetle.java @@ -1,7 +1,6 @@ package mage.cards.d; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.AttacksTriggeredAbility; @@ -13,24 +12,29 @@ import mage.abilities.effects.common.counter.RemoveCounterTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Outcome; +import mage.constants.SubType; import mage.counters.CounterType; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.permanent.ControllerIdPredicate; +import mage.filter.predicate.permanent.DefendingPlayerControlsPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetCreaturePermanent; import mage.target.targetpointer.FixedTarget; +import java.util.UUID; + /** - * * @author spjspj */ public final class DecimatorBeetle extends CardImpl { - private final UUID originalId; + public static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls"); + + static { + filter.add(new DefendingPlayerControlsPredicate()); + } public DecimatorBeetle(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{B}{G}"); @@ -46,29 +50,14 @@ public final class DecimatorBeetle extends CardImpl { this.addAbility(ability); // Whenever Decimator Beetle attacks, remove a -1/-1 counter from target creature you control and put a -1/-1 counter on up to one target creature defending player controls. - Ability ability2 = new AttacksTriggeredAbility(new DecimatorBeetleEffect(), false); - ability2.addTarget(new TargetControlledCreaturePermanent()); - ability2.addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature defending player controls"))); - this.addAbility(ability2); - this.originalId = ability2.getOriginalId(); + ability = new AttacksTriggeredAbility(new DecimatorBeetleEffect(), false); + ability.addTarget(new TargetControlledCreaturePermanent()); + ability.addTarget(new TargetCreaturePermanent(0, 1, filter, false)); + this.addAbility(ability); } public DecimatorBeetle(final DecimatorBeetle card) { super(card); - this.originalId = card.originalId; - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability.getOriginalId().equals(originalId)) { - ability.getTargets().clear(); - ability.addTarget(new TargetControlledCreaturePermanent()); - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls"); - UUID defenderId = game.getCombat().getDefenderId(ability.getSourceId()); - filter.add(new ControllerIdPredicate(defenderId)); - TargetCreaturePermanent target = new TargetCreaturePermanent(0, 1, filter, false); - ability.addTarget(target); - } } @Override diff --git a/Mage.Sets/src/mage/cards/d/Detonate.java b/Mage.Sets/src/mage/cards/d/Detonate.java index ff84de2a35..de1a4096ed 100644 --- a/Mage.Sets/src/mage/cards/d/Detonate.java +++ b/Mage.Sets/src/mage/cards/d/Detonate.java @@ -1,9 +1,7 @@ package mage.cards.d; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.effects.Effect; import mage.abilities.effects.common.DamageTargetControllerEffect; @@ -16,15 +14,17 @@ import mage.filter.common.FilterArtifactPermanent; import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; import mage.game.Game; import mage.target.common.TargetArtifactPermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LoneFox */ public final class Detonate extends CardImpl { public Detonate(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{X}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{R}"); // Destroy target artifact with converted mana cost X. It can't be regenerated. Detonate deals X damage to that artifact's controller. this.getSpellAbility().addEffect(new DestroyTargetEffect(true)); @@ -32,17 +32,7 @@ public final class Detonate extends CardImpl { Effect effect = new DamageTargetControllerEffect(new ManacostVariableValue()); effect.setText("{this} deals X damage to that artifact's controller"); this.getSpellAbility().addEffect(effect); - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if(ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact with converted mana cost X"); - filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); - ability.addTarget(new TargetArtifactPermanent(filter)); - } + this.getSpellAbility().setTargetAdjuster(DetonateAdjuster.instance); } public Detonate(final Detonate card) { @@ -54,3 +44,16 @@ public final class Detonate extends CardImpl { return new Detonate(this); } } + +enum DetonateAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact with converted mana cost X"); + filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); + ability.addTarget(new TargetArtifactPermanent(filter)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DiluvianPrimordial.java b/Mage.Sets/src/mage/cards/d/DiluvianPrimordial.java index 69905e9470..eb8556b0bc 100644 --- a/Mage.Sets/src/mage/cards/d/DiluvianPrimordial.java +++ b/Mage.Sets/src/mage/cards/d/DiluvianPrimordial.java @@ -1,7 +1,6 @@ package mage.cards.d; -import java.util.UUID; import mage.MageInt; import mage.MageObjectReference; import mage.abilities.Ability; @@ -13,11 +12,7 @@ import mage.abilities.keyword.FlyingAbility; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.SubType; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.FilterCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; @@ -29,10 +24,12 @@ import mage.game.events.ZoneChangeEvent; import mage.players.Player; import mage.target.Target; import mage.target.common.TargetCardInOpponentsGraveyard; +import mage.target.targetadjustment.TargetAdjuster; import mage.target.targetpointer.FixedTarget; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class DiluvianPrimordial extends CardImpl { @@ -48,24 +45,9 @@ public final class DiluvianPrimordial extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // When Diluvian Primordial enters the battlefield, for each opponent, you may cast up to one target instant or sorcery card from that player's graveyard without paying its mana cost. If a card cast this way would be put into a graveyard this turn, exile it instead. - this.addAbility(new EntersBattlefieldTriggeredAbility(new DiluvianPrimordialEffect(), false)); - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof EntersBattlefieldTriggeredAbility) { - ability.getTargets().clear(); - for (UUID opponentId : game.getOpponents(ability.getControllerId())) { - Player opponent = game.getPlayer(opponentId); - if (opponent != null) { - FilterCard filter = new FilterCard("instant or sorcery card from " + opponent.getLogName() + "'s graveyard"); - filter.add(new OwnerIdPredicate(opponentId)); - filter.add(Predicates.or(new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY))); - TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(0, 1, filter); - ability.addTarget(target); - } - } - } + Ability ability = new EntersBattlefieldTriggeredAbility(new DiluvianPrimordialEffect(), false); + ability.setTargetAdjuster(DiluvianPrimordialAdjuster.instance); + this.addAbility(ability); } public DiluvianPrimordial(final DiluvianPrimordial card) { @@ -78,6 +60,26 @@ public final class DiluvianPrimordial extends CardImpl { } } +enum DiluvianPrimordialAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + for (UUID opponentId : game.getOpponents(ability.getControllerId())) { + Player opponent = game.getPlayer(opponentId); + if (opponent == null) { + continue; + } + FilterCard filter = new FilterCard("instant or sorcery card from " + opponent.getLogName() + "'s graveyard"); + filter.add(new OwnerIdPredicate(opponentId)); + filter.add(Predicates.or(new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY))); + TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(0, 1, filter); + ability.addTarget(target); + } + } +} + class DiluvianPrimordialEffect extends OneShotEffect { public DiluvianPrimordialEffect() { diff --git a/Mage.Sets/src/mage/cards/d/Disembowel.java b/Mage.Sets/src/mage/cards/d/Disembowel.java index 3e1f1d500d..6aa70be2ab 100644 --- a/Mage.Sets/src/mage/cards/d/Disembowel.java +++ b/Mage.Sets/src/mage/cards/d/Disembowel.java @@ -1,9 +1,7 @@ package mage.cards.d; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.common.DestroyTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -13,30 +11,21 @@ import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; import mage.game.Game; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LoneFox */ public final class Disembowel extends CardImpl { public Disembowel(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{X}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{B}"); // Destroy target creature with converted mana cost X. - this.getSpellAbility().addEffect(new DestroyTargetEffect()); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature with converted mana cost X"))); - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if(ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost X"); - filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); - ability.addTarget(new TargetCreaturePermanent(filter)); - } + this.getSpellAbility().addEffect(new DestroyTargetEffect("creature with converted mana cost X")); + this.getSpellAbility().setTargetAdjuster(DisembowelAdjuster.instance); } public Disembowel(final Disembowel card) { @@ -48,3 +37,16 @@ public final class Disembowel extends CardImpl { return new Disembowel(this); } } + +enum DisembowelAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost X"); + filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); + ability.addTarget(new TargetCreaturePermanent(filter)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DistortingWake.java b/Mage.Sets/src/mage/cards/d/DistortingWake.java index 6f0491c67b..e03c667af1 100644 --- a/Mage.Sets/src/mage/cards/d/DistortingWake.java +++ b/Mage.Sets/src/mage/cards/d/DistortingWake.java @@ -1,9 +1,7 @@ package mage.cards.d; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.common.ReturnToHandTargetEffect; import mage.cards.CardImpl; @@ -13,22 +11,23 @@ import mage.filter.common.FilterNonlandPermanent; import mage.game.Game; import mage.target.Target; import mage.target.common.TargetNonlandPermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class DistortingWake extends CardImpl { public DistortingWake(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{X}{U}{U}{U}"); - + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{U}{U}{U}"); // Return X target nonland permanents to their owners' hands. Effect effect = new ReturnToHandTargetEffect(); effect.setText("Return X target nonland permanents to their owners' hands"); this.getSpellAbility().addEffect(effect); - this.getSpellAbility().addTarget(new TargetNonlandPermanent()); + this.getSpellAbility().setTargetAdjuster(DistortingWakeAdjuster.instance); } public DistortingWake(final DistortingWake card) { @@ -39,16 +38,17 @@ public final class DistortingWake extends CardImpl { public DistortingWake copy() { return new DistortingWake(this); } +} + +enum DistortingWakeAdjuster implements TargetAdjuster { + instance; @Override public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - int xValue = ability.getManaCostsToPay().getX(); - Target target = new TargetNonlandPermanent(xValue, xValue, - new FilterNonlandPermanent(xValue + " target nonland permanent(s)"), false); - ability.getTargets().clear(); - ability.getTargets().add(target); - } + int xValue = ability.getManaCostsToPay().getX(); + Target target = new TargetNonlandPermanent(xValue, xValue, + new FilterNonlandPermanent(xValue + " target nonland permanent(s)"), false); + ability.getTargets().clear(); + ability.getTargets().add(target); } - -} +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/Dominate.java b/Mage.Sets/src/mage/cards/d/Dominate.java index 7ad2e93a8c..d9c74afb3c 100644 --- a/Mage.Sets/src/mage/cards/d/Dominate.java +++ b/Mage.Sets/src/mage/cards/d/Dominate.java @@ -1,9 +1,6 @@ - package mage.cards.d; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -15,38 +12,43 @@ import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; import mage.game.Game; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author fireshoes */ public final class Dominate extends CardImpl { public Dominate(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{X}{1}{U}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{1}{U}{U}"); // Gain control of target creature with converted mana cost X or less. this.getSpellAbility().addEffect(new GainControlTargetEffect(Duration.Custom, true)); this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature with converted mana cost X or less"))); + this.getSpellAbility().setTargetAdjuster(DominateAdjuster.instance); } public Dominate(final Dominate card) { super(card); } - - @Override - public void adjustTargets(Ability ability, Game game) { - if(ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost X or less"); - filter.add(Predicates.not(new ConvertedManaCostPredicate(ComparisonType.MORE_THAN, xValue))); - ability.addTarget(new TargetCreaturePermanent(filter)); - } - } @Override public Dominate copy() { return new Dominate(this); } } + +enum DominateAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost X or less"); + filter.add(Predicates.not(new ConvertedManaCostPredicate(ComparisonType.MORE_THAN, xValue))); + ability.addTarget(new TargetCreaturePermanent(filter)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DregsOfSorrow.java b/Mage.Sets/src/mage/cards/d/DregsOfSorrow.java index a819a8abf7..082731e051 100644 --- a/Mage.Sets/src/mage/cards/d/DregsOfSorrow.java +++ b/Mage.Sets/src/mage/cards/d/DregsOfSorrow.java @@ -1,10 +1,7 @@ - package mage.cards.d; -import java.util.UUID; import mage.ObjectColor; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; @@ -16,39 +13,25 @@ import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class DregsOfSorrow extends CardImpl { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("nonblack creatures"); - - static { - filter.add(Predicates.not(new ColorPredicate(ObjectColor.BLACK))); - } - public DregsOfSorrow(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{X}{4}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{4}{B}"); // Destroy X target nonblack creatures. Draw X cards. this.getSpellAbility().addEffect(new DestroyTargetEffect("Destroy X target nonblack creatures")); this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect(new ManacostVariableValue())); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter)); + this.getSpellAbility().setTargetAdjuster(DregsOfSorrowAdjuster.instance); } - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - ability.addTarget(new TargetCreaturePermanent(xValue, xValue, filter, false)); - } - } - - public DregsOfSorrow(final DregsOfSorrow card) { super(card); } @@ -58,3 +41,19 @@ public final class DregsOfSorrow extends CardImpl { return new DregsOfSorrow(this); } } + +enum DregsOfSorrowAdjuster implements TargetAdjuster { + instance; + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("nonblack creatures"); + + static { + filter.add(Predicates.not(new ColorPredicate(ObjectColor.BLACK))); + } + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + ability.addTarget(new TargetCreaturePermanent(xValue, xValue, filter, false)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/e/EliteScaleguard.java b/Mage.Sets/src/mage/cards/e/EliteScaleguard.java index 332e040f55..1e52cb5160 100644 --- a/Mage.Sets/src/mage/cards/e/EliteScaleguard.java +++ b/Mage.Sets/src/mage/cards/e/EliteScaleguard.java @@ -1,12 +1,10 @@ package mage.cards.e; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.AttacksCreatureYouControlTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.TapTargetEffect; import mage.abilities.effects.keyword.BolsterEffect; import mage.cards.CardImpl; @@ -16,25 +14,29 @@ import mage.constants.SubType; import mage.counters.CounterType; import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.filter.predicate.permanent.CounterPredicate; +import mage.filter.predicate.permanent.DefendingPlayerControlsPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** - * * @author emerald000 */ public final class EliteScaleguard extends CardImpl { - + private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature you control with a +1/+1 counter on it"); + private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature defending player controls"); + static { filter.add(new CounterPredicate(CounterType.P1P1)); + filter2.add(new DefendingPlayerControlsPredicate()); } public EliteScaleguard(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{4}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{W}"); this.subtype.add(SubType.HUMAN); this.subtype.add(SubType.SOLDIER); this.power = new MageInt(2); @@ -42,32 +44,16 @@ public final class EliteScaleguard extends CardImpl { // When Elite Scaleguard enters the battlefield, bolster 2. this.addAbility(new EntersBattlefieldTriggeredAbility(new BolsterEffect(2))); - + // Whenever a creature you control with a +1/+1 counter on it attacks, tap target creature defending player controls. Ability ability = new AttacksCreatureYouControlTriggeredAbility(new EliteScaleguardTapEffect(), false, filter, true); - ability.addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature defending player controls"))); + ability.addTarget(new TargetCreaturePermanent(filter2)); this.addAbility(ability); } public EliteScaleguard(final EliteScaleguard card) { super(card); } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof AttacksCreatureYouControlTriggeredAbility) { - FilterCreaturePermanent filterDefender = new FilterCreaturePermanent("creature defending player controls"); - for (Effect effect : ability.getEffects()) { - if (effect instanceof EliteScaleguardTapEffect) { - filterDefender.add(new ControllerIdPredicate(game.getCombat().getDefendingPlayerId(effect.getTargetPointer().getFirst(game, ability), game))); - break; - } - } - ability.getTargets().clear(); - TargetCreaturePermanent target = new TargetCreaturePermanent(filterDefender); - ability.addTarget(target); - } - } @Override public EliteScaleguard copy() { @@ -76,20 +62,20 @@ public final class EliteScaleguard extends CardImpl { } class EliteScaleguardTapEffect extends TapTargetEffect { - + EliteScaleguardTapEffect() { super(); } - + EliteScaleguardTapEffect(final EliteScaleguardTapEffect effect) { super(effect); } - + @Override public EliteScaleguardTapEffect copy() { return new EliteScaleguardTapEffect(this); } - + @Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getFirstTarget()); diff --git a/Mage.Sets/src/mage/cards/e/EntrancingMelody.java b/Mage.Sets/src/mage/cards/e/EntrancingMelody.java index 4c14d0ee0c..5fb6288498 100644 --- a/Mage.Sets/src/mage/cards/e/EntrancingMelody.java +++ b/Mage.Sets/src/mage/cards/e/EntrancingMelody.java @@ -1,9 +1,7 @@ package mage.cards.e; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -14,38 +12,45 @@ import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; import mage.game.Game; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author TheElk801 */ public final class EntrancingMelody extends CardImpl { + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost X"); + public EntrancingMelody(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{U}{U}"); // Gain control of target creature with converted mana cost X. this.getSpellAbility().addEffect(new GainControlTargetEffect(Duration.Custom, true)); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature with converted mana cost X"))); + this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter)); + this.getSpellAbility().setTargetAdjuster(EntrancingMelodyAdjuster.instance); } public EntrancingMelody(final EntrancingMelody card) { super(card); } - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost X"); - filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); - ability.addTarget(new TargetCreaturePermanent(filter)); - } - } - @Override public EntrancingMelody copy() { return new EntrancingMelody(this); } } + +enum EntrancingMelodyAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with converted mana cost " + xValue); + filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); + ability.addTarget(new TargetCreaturePermanent(filter)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/g/GangUp.java b/Mage.Sets/src/mage/cards/g/GangUp.java index 5106c8e463..a49f70ff1d 100644 --- a/Mage.Sets/src/mage/cards/g/GangUp.java +++ b/Mage.Sets/src/mage/cards/g/GangUp.java @@ -1,9 +1,7 @@ package mage.cards.g; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.keyword.AssistAbility; import mage.cards.CardImpl; @@ -14,9 +12,11 @@ import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.PowerPredicate; import mage.game.Game; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author TheElk801 */ public final class GangUp extends CardImpl { @@ -28,27 +28,29 @@ public final class GangUp extends CardImpl { this.addAbility(new AssistAbility()); // Destroy target creature with power X or less. - this.getSpellAbility().addEffect(new DestroyTargetEffect()); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature with power X or less"))); + this.getSpellAbility().addEffect(new DestroyTargetEffect("destroy target creature with power X or less")); + this.getSpellAbility().setTargetAdjuster(GangUpAdjuster.instance); } public GangUp(final GangUp card) { super(card); } - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - int xValue = ability.getManaCostsToPay().getX(); - ability.getTargets().clear(); - FilterCreaturePermanent filter = new FilterCreaturePermanent(new StringBuilder("creature with power ").append(xValue).append(" or less").toString()); - filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); - ability.addTarget(new TargetCreaturePermanent(filter)); - } - } - @Override public GangUp copy() { return new GangUp(this); } } + +enum GangUpAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int xValue = ability.getManaCostsToPay().getX(); + ability.getTargets().clear(); + FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with power " + xValue + " or less"); + filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); + ability.addTarget(new TargetCreaturePermanent(filter)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/g/GlimpseTheSunGod.java b/Mage.Sets/src/mage/cards/g/GlimpseTheSunGod.java index 4ab2832a67..f0c457aa4f 100644 --- a/Mage.Sets/src/mage/cards/g/GlimpseTheSunGod.java +++ b/Mage.Sets/src/mage/cards/g/GlimpseTheSunGod.java @@ -1,20 +1,21 @@ package mage.cards.g; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.common.TapTargetEffect; import mage.abilities.effects.keyword.ScryEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import static mage.filter.StaticFilters.FILTER_PERMANENT_CREATURES; import mage.game.Game; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; + +import static mage.filter.StaticFilters.FILTER_PERMANENT_CREATURES; /** - * * @author LevelX2 */ public final class GlimpseTheSunGod extends CardImpl { @@ -24,26 +25,27 @@ public final class GlimpseTheSunGod extends CardImpl { // Tap X target creatures. Scry 1. this.getSpellAbility().addEffect(new TapTargetEffect("X target creatures")); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(0, 1, FILTER_PERMANENT_CREATURES, false)); this.getSpellAbility().addEffect(new ScryEffect(1)); + this.getSpellAbility().setTargetAdjuster(GlimpseTheSunGodAdjuster.instance); } public GlimpseTheSunGod(final GlimpseTheSunGod card) { super(card); } - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - int numberToTap = ability.getManaCostsToPay().getX(); - numberToTap = Math.min(game.getBattlefield().count(FILTER_PERMANENT_CREATURES, ability.getSourceId(), ability.getControllerId(), game), numberToTap); - ability.addTarget(new TargetCreaturePermanent(numberToTap, numberToTap, FILTER_PERMANENT_CREATURES, false)); - } - } - @Override public GlimpseTheSunGod copy() { return new GlimpseTheSunGod(this); } } + +enum GlimpseTheSunGodAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int numberToTap = ability.getManaCostsToPay().getX(); + ability.addTarget(new TargetCreaturePermanent(numberToTap, numberToTap, FILTER_PERMANENT_CREATURES, false)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/g/GoblinBarrage.java b/Mage.Sets/src/mage/cards/g/GoblinBarrage.java index cfc82c9248..57f2fef6e7 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinBarrage.java +++ b/Mage.Sets/src/mage/cards/g/GoblinBarrage.java @@ -1,7 +1,6 @@ package mage.cards.g; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.condition.common.KickedCondition; import mage.abilities.costs.common.SacrificeTargetCost; @@ -19,19 +18,28 @@ import mage.game.Game; import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetPlayerOrPlaneswalker; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class GoblinBarrage extends CardImpl { + private static final FilterControlledPermanent filter = new FilterControlledPermanent("an artifact or Goblin"); + + static { + filter.add(Predicates.or( + new CardTypePredicate(CardType.ARTIFACT), + new SubtypePredicate(SubType.GOBLIN) + )); + } + public GoblinBarrage(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{R}"); // Kicker—Sacrifice an artifact or Goblin. - FilterControlledPermanent filter = new FilterControlledPermanent("an artifact or Goblin"); - filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), new SubtypePredicate(SubType.GOBLIN))); this.addAbility(new KickerAbility(new SacrificeTargetCost(new TargetControlledPermanent(filter)))); // Goblin Barrage deals 4 damage to target creature. If this spell was kicked, it also deals 4 damage to target player or planeswalker. @@ -40,13 +48,7 @@ public final class GoblinBarrage extends CardImpl { + "it also deals 4 damage to target player or planeswalker") ); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (KickedCondition.instance.apply(game, ability)) { - ability.addTarget(new TargetPlayerOrPlaneswalker()); - } + this.getSpellAbility().setTargetAdjuster(GoblinBarrageAdjuster.instance); } public GoblinBarrage(final GoblinBarrage card) { @@ -58,3 +60,14 @@ public final class GoblinBarrage extends CardImpl { return new GoblinBarrage(this); } } + +enum GoblinBarrageAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + if (KickedCondition.instance.apply(game, ability)) { + ability.addTarget(new TargetPlayerOrPlaneswalker()); + } + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/g/GoblinRacketeer.java b/Mage.Sets/src/mage/cards/g/GoblinRacketeer.java index a4c3c44b11..80e0d2b5b3 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinRacketeer.java +++ b/Mage.Sets/src/mage/cards/g/GoblinRacketeer.java @@ -1,8 +1,6 @@ package mage.cards.g; -import java.util.UUID; - import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.AttacksTriggeredAbility; @@ -12,16 +10,21 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.permanent.ControllerIdPredicate; -import mage.game.Game; +import mage.filter.predicate.permanent.DefendingPlayerControlsPredicate; import mage.target.common.TargetCreaturePermanent; +import java.util.UUID; + /** * @author TheElk801 */ public final class GoblinRacketeer extends CardImpl { - private final UUID originalId; + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls"); + + static { + filter.add(new DefendingPlayerControlsPredicate()); + } public GoblinRacketeer(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}"); @@ -33,27 +36,12 @@ public final class GoblinRacketeer extends CardImpl { // Whenever Goblin Racketeer attacks, you may goad target creature defending player controls. Ability ability = new AttacksTriggeredAbility(new GoadTargetEffect(), true, "Whenever {this} attacks, you may goad target creature defending player controls"); - ability.addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature defending player controls"))); - originalId = ability.getOriginalId(); + ability.addTarget(new TargetCreaturePermanent(filter)); this.addAbility(ability); } public GoblinRacketeer(final GoblinRacketeer card) { super(card); - this.originalId = card.originalId; - - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability.getOriginalId().equals(originalId)) { - ability.getTargets().clear(); - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls"); - UUID defenderId = game.getCombat().getDefenderId(ability.getSourceId()); - filter.add(new ControllerIdPredicate(defenderId)); - TargetCreaturePermanent target = new TargetCreaturePermanent(filter); - ability.addTarget(target); - } } @Override diff --git a/Mage.Sets/src/mage/cards/g/GraspOfFate.java b/Mage.Sets/src/mage/cards/g/GraspOfFate.java index 271b67e730..3fbb816904 100644 --- a/Mage.Sets/src/mage/cards/g/GraspOfFate.java +++ b/Mage.Sets/src/mage/cards/g/GraspOfFate.java @@ -1,7 +1,6 @@ package mage.cards.g; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; @@ -23,10 +22,12 @@ 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 java.util.UUID; + /** - * * @author fireshoes */ public final class GraspOfFate extends CardImpl { @@ -36,8 +37,8 @@ public final class GraspOfFate extends CardImpl { // 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.addTarget(new TargetPermanent()); ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility())); + ability.setTargetAdjuster(GraspOfFateAdjuster.instance); this.addAbility(ability); } @@ -45,29 +46,32 @@ public final class GraspOfFate extends CardImpl { super(card); } - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof EntersBattlefieldTriggeredAbility) { - ability.getTargets().clear(); - for (UUID opponentId : game.getOpponents(ability.getControllerId())) { - Player opponent = game.getPlayer(opponentId); - if (opponent != null) { - FilterPermanent filter = new FilterPermanent("nonland permanent from opponent " + opponent.getLogName()); - filter.add(new ControllerIdPredicate(opponentId)); - filter.add(Predicates.not(new CardTypePredicate(CardType.LAND))); - TargetPermanent target = new TargetPermanent(0, 1, filter, false); - ability.addTarget(target); - } - } - } - } - @Override public GraspOfFate copy() { return new GraspOfFate(this); } } +enum GraspOfFateAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + for (UUID opponentId : game.getOpponents(ability.getControllerId())) { + Player opponent = game.getPlayer(opponentId); + if (opponent == null) { + continue; + } + FilterPermanent filter = new FilterPermanent("nonland permanent from opponent " + opponent.getLogName()); + filter.add(new ControllerIdPredicate(opponentId)); + filter.add(Predicates.not(new CardTypePredicate(CardType.LAND))); + TargetPermanent target = new TargetPermanent(0, 1, filter, false); + ability.addTarget(target); + } + } +} + class GraspOfFateExileEffect extends OneShotEffect { public GraspOfFateExileEffect() { diff --git a/Mage.Sets/src/mage/cards/g/GravenAbomination.java b/Mage.Sets/src/mage/cards/g/GravenAbomination.java index c48c21d123..18f6730471 100644 --- a/Mage.Sets/src/mage/cards/g/GravenAbomination.java +++ b/Mage.Sets/src/mage/cards/g/GravenAbomination.java @@ -1,7 +1,6 @@ package mage.cards.g; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.AttacksTriggeredAbility; @@ -11,20 +10,22 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.filter.FilterCard; -import mage.filter.predicate.other.OwnerIdPredicate; -import mage.game.Game; -import mage.players.Player; +import mage.filter.predicate.permanent.DefendingPlayerOwnsCardPredicate; import mage.target.common.TargetCardInGraveyard; +import java.util.UUID; + /** - * * @author jeffwadsworth */ public final class GravenAbomination extends CardImpl { - private final UUID originalId; + private static final String rule = "Whenever {this} attacks, exile target card from defending player's graveyard."; + private static final FilterCard filter = new FilterCard("card from defending player's graveyard"); - private final static String rule = "Whenever {this} attacks, exile target card from defending player's graveyard."; + static { + filter.add(new DefendingPlayerOwnsCardPredicate()); + } public GravenAbomination(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); @@ -35,30 +36,12 @@ public final class GravenAbomination extends CardImpl { // Whenever Graven Abomination attacks, exile target card from defending player's graveyard. Ability ability = new AttacksTriggeredAbility(new ExileTargetEffect(), false, rule); - ability.addTarget(new TargetCardInGraveyard()); + ability.addTarget(new TargetCardInGraveyard(filter)); this.addAbility(ability); - originalId = ability.getOriginalId(); - - } - - @Override - public void adjustTargets(Ability ability, Game game) { - UUID gravenAbominationId = ability.getSourceId(); - FilterCard filter = new FilterCard("target card from defending player's graveyard"); - if (ability.getOriginalId().equals(originalId)) { - UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(gravenAbominationId, game); - Player defendingPlayer = game.getPlayer(defendingPlayerId); - if (defendingPlayer != null) { - filter.add(new OwnerIdPredicate(defendingPlayerId)); - ability.getTargets().clear(); - ability.getTargets().add(new TargetCardInGraveyard(filter)); - } - } } public GravenAbomination(final GravenAbomination card) { super(card); - this.originalId = card.originalId; } @Override diff --git a/Mage.Sets/src/mage/cards/g/Gridlock.java b/Mage.Sets/src/mage/cards/g/Gridlock.java index a94c6e7848..23c6be94f6 100644 --- a/Mage.Sets/src/mage/cards/g/Gridlock.java +++ b/Mage.Sets/src/mage/cards/g/Gridlock.java @@ -1,9 +1,7 @@ package mage.cards.g; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.effects.common.TapTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -11,41 +9,40 @@ import mage.constants.CardType; import mage.filter.common.FilterNonlandPermanent; import mage.game.Game; import mage.target.TargetPermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class Gridlock extends CardImpl { - private static final FilterNonlandPermanent filter = new FilterNonlandPermanent("nonland permanents"); public Gridlock(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{X}{U}"); - + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{U}"); // Tap X target nonland permanents. - this.getSpellAbility().addEffect(new TapTargetEffect()); - // Correct number of targets will be set in adjustTargets - this.getSpellAbility().addTarget(new TargetPermanent(0, 1,filter, false)); - + this.getSpellAbility().addEffect(new TapTargetEffect("X target nonland permanents")); + this.getSpellAbility().setTargetAdjuster(GridlockAdjuster.instance); } public Gridlock(final Gridlock card) { super(card); } - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - int numberToTap = ability.getManaCostsToPay().getX(); - numberToTap = Math.min(game.getBattlefield().count(filter, ability.getSourceId(), ability.getControllerId(), game), numberToTap); - ability.addTarget(new TargetPermanent(numberToTap, filter)); - } - } - @Override public Gridlock copy() { return new Gridlock(this); } } + +enum GridlockAdjuster implements TargetAdjuster { + instance; + private static final FilterNonlandPermanent filter = new FilterNonlandPermanent("nonland permanents"); + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + ability.addTarget(new TargetPermanent(ability.getManaCostsToPay().getX(), filter)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/g/GrimReturn.java b/Mage.Sets/src/mage/cards/g/GrimReturn.java index 19e46ebcaa..70ef959076 100644 --- a/Mage.Sets/src/mage/cards/g/GrimReturn.java +++ b/Mage.Sets/src/mage/cards/g/GrimReturn.java @@ -1,9 +1,6 @@ package mage.cards.g; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.Effect; @@ -17,10 +14,14 @@ import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardIdPredicate; import mage.game.Game; import mage.target.common.TargetCardInGraveyard; +import mage.target.targetadjustment.TargetAdjuster; import mage.watchers.common.CardsPutIntoGraveyardWatcher; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class GrimReturn extends CardImpl { @@ -28,13 +29,13 @@ public final class GrimReturn extends CardImpl { private static final String textFilter = "creature card in a graveyard that was put there from the battlefield this turn"; public GrimReturn(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{B}"); // Choose target creature card in a graveyard that was put there from the battlefield this turn. Put that card onto the battlefield under your control. Effect effect = new ReturnFromGraveyardToBattlefieldTargetEffect(); effect.setText("Choose target creature card in a graveyard that was put there from the battlefield this turn. Put that card onto the battlefield under your control"); this.getSpellAbility().addEffect(new ReturnFromGraveyardToBattlefieldTargetEffect()); - this.getSpellAbility().addTarget(new TargetCardInGraveyard(new FilterCreatureCard(textFilter))); + this.getSpellAbility().setTargetAdjuster(GrimReturnAdjuster.instance); this.getSpellAbility().addWatcher(new CardsPutIntoGraveyardWatcher()); } @@ -46,22 +47,27 @@ public final class GrimReturn extends CardImpl { public GrimReturn copy() { return new GrimReturn(this); } +} + +enum GrimReturnAdjuster implements TargetAdjuster { + instance; + private static final String textFilter = "creature card in a graveyard that was put there from the battlefield this turn"; @Override public void adjustTargets(Ability ability, Game game) { CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName()); - if (watcher != null) { - FilterCard filter = new FilterCreatureCard(textFilter); - List uuidPredicates = new ArrayList<>(); - for (MageObjectReference mor : watcher.getCardsPutToGraveyardFromBattlefield()) { - if (game.getState().getZoneChangeCounter(mor.getSourceId()) == mor.getZoneChangeCounter()) { - uuidPredicates.add(new CardIdPredicate(mor.getSourceId())); - } - } - filter.add(Predicates.or(uuidPredicates)); - ability.getTargets().clear(); - ability.addTarget(new TargetCardInGraveyard(filter)); + if (watcher == null) { + return; } - + FilterCard filter = new FilterCreatureCard(textFilter); + List uuidPredicates = new ArrayList<>(); + for (MageObjectReference mor : watcher.getCardsPutToGraveyardFromBattlefield()) { + if (mor.zoneCounterIsCurrent(game)) { + uuidPredicates.add(new CardIdPredicate(mor.getSourceId())); + } + } + filter.add(Predicates.or(uuidPredicates)); + ability.getTargets().clear(); + ability.addTarget(new TargetCardInGraveyard(filter)); } -} +} \ No newline at end of file diff --git a/Mage/src/main/java/mage/MageObjectReference.java b/Mage/src/main/java/mage/MageObjectReference.java index ff72668e40..44f63bebc6 100644 --- a/Mage/src/main/java/mage/MageObjectReference.java +++ b/Mage/src/main/java/mage/MageObjectReference.java @@ -1,7 +1,5 @@ package mage; -import java.io.Serializable; -import java.util.UUID; import mage.cards.Card; import mage.constants.Zone; import mage.game.Game; @@ -10,6 +8,9 @@ import mage.game.stack.Spell; import mage.game.stack.StackObject; import org.apache.log4j.Logger; +import java.io.Serializable; +import java.util.UUID; + /** * A object reference that takes zone changes into account. * @@ -145,4 +146,8 @@ public class MageObjectReference implements Comparable, Ser } return null; } + + public boolean zoneCounterIsCurrent(Game game) { + return game.getState().getZoneChangeCounter(sourceId) == zoneChangeCounter; + } } diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index 8b19cf5d3f..a8390ccfe7 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -360,9 +360,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card { public List getMana() { List mana = new ArrayList<>(); for (ActivatedManaAbilityImpl ability : this.abilities.getActivatedManaAbilities(Zone.BATTLEFIELD)) { - for (Mana netMana : ability.getNetMana(null)) { - mana.add(netMana); - } + mana.addAll(ability.getNetMana(null)); } return mana; }