From b833fc7f7782bcdbf8459505e0f4804933e8f074 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 17 Sep 2018 14:13:52 -0400 Subject: [PATCH] replaced various single-use adjusters --- .../mage/cards/a/AryelKnightOfWindgrace.java | 27 ++++- .../src/mage/cards/d/DeclarationOfNaught.java | 22 +++- .../src/mage/cards/g/GethLordOfTheVault.java | 4 +- .../mage/cards/l/LazavTheMultifarious.java | 8 +- .../src/mage/cards/l/LeagueGuildmage.java | 19 ++++ Mage.Sets/src/mage/cards/l/LegacysAllure.java | 25 +++- .../src/mage/cards/m/MinamoSightbender.java | 22 +++- .../src/mage/cards/p/PentarchPaladin.java | 30 ++++- .../src/mage/cards/s/SimicManipulator.java | 31 ++--- Mage/src/main/java/mage/cards/CardImpl.java | 107 ------------------ .../XCMCGraveyardAdjuster.java | 27 +++++ 11 files changed, 178 insertions(+), 144 deletions(-) create mode 100644 Mage/src/main/java/mage/target/targetadjustment/XCMCGraveyardAdjuster.java diff --git a/Mage.Sets/src/mage/cards/a/AryelKnightOfWindgrace.java b/Mage.Sets/src/mage/cards/a/AryelKnightOfWindgrace.java index 4e8c867ee3..86ad83f7f4 100644 --- a/Mage.Sets/src/mage/cards/a/AryelKnightOfWindgrace.java +++ b/Mage.Sets/src/mage/cards/a/AryelKnightOfWindgrace.java @@ -1,4 +1,3 @@ - package mage.cards.a; import java.util.UUID; @@ -6,6 +5,7 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.Cost; +import mage.abilities.costs.VariableCost; import mage.abilities.costs.VariableCostImpl; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapTargetCost; @@ -16,17 +16,21 @@ import mage.abilities.keyword.VigilanceAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.ComparisonType; import mage.constants.SubType; import mage.constants.SuperType; -import mage.constants.TargetAdjustment; import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.PowerPredicate; import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.permanent.TappedPredicate; import mage.game.Game; import mage.game.permanent.token.KnightToken; import mage.target.common.TargetControlledPermanent; +import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; /** * @@ -57,9 +61,8 @@ public final class AryelKnightOfWindgrace extends CardImpl { .setText("Destroy target creature with power X or less"), new ManaCostsImpl("{B}")); ability.addCost(new TapSourceCost()); ability.addCost(new AryelTapXTargetCost()); - ability.setTargetAdjustment(TargetAdjustment.CREATURE_POWER_X_OR_LESS); + ability.setTargetAdjuster(AryelKnightOfWindgraceAdjuster.instance); this.addAbility(ability); - ability.getOriginalId(); } public AryelKnightOfWindgrace(final AryelKnightOfWindgrace card) { @@ -106,3 +109,19 @@ class AryelTapXTargetCost extends VariableCostImpl { return new TapTargetCost(target); } } + +enum AryelKnightOfWindgraceAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int value = 0; + for (VariableCost cost : ability.getCosts().getVariableCosts()) { + value = cost.getAmount(); + } + FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("creature with power " + value + " or less"); + filterCreaturePermanent.add(new PowerPredicate(ComparisonType.FEWER_THAN, value + 1)); + ability.getTargets().clear(); + ability.addTarget(new TargetCreaturePermanent(filterCreaturePermanent)); + } +} diff --git a/Mage.Sets/src/mage/cards/d/DeclarationOfNaught.java b/Mage.Sets/src/mage/cards/d/DeclarationOfNaught.java index 7fef07ec16..8e761b1c30 100644 --- a/Mage.Sets/src/mage/cards/d/DeclarationOfNaught.java +++ b/Mage.Sets/src/mage/cards/d/DeclarationOfNaught.java @@ -1,7 +1,7 @@ - package mage.cards.d; import java.util.UUID; +import mage.abilities.Ability; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; @@ -10,10 +10,12 @@ import mage.abilities.effects.common.ChooseACardNameEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.TargetAdjustment; import mage.constants.Zone; import mage.filter.FilterSpell; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.game.Game; import mage.target.TargetSpell; +import mage.target.targetadjustment.TargetAdjuster; /** * @@ -31,7 +33,7 @@ public final class DeclarationOfNaught extends CardImpl { // {U}: Counter target spell with the chosen name. SimpleActivatedAbility ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CounterTargetEffect(), new ManaCostsImpl("{U}")); - ability.setTargetAdjustment(TargetAdjustment.CHOSEN_NAME); + ability.setTargetAdjuster(DeclarationOfNaughtAdjuster.instance); ability.addTarget(new TargetSpell(filter)); this.addAbility(ability); } @@ -45,3 +47,17 @@ public final class DeclarationOfNaught extends CardImpl { return new DeclarationOfNaught(this); } } + +enum DeclarationOfNaughtAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + String chosenName = (String) game.getState().getValue(ability.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); + FilterSpell filterSpell = new FilterSpell("spell named " + chosenName); + filterSpell.add(new NamePredicate(chosenName)); + TargetSpell target = new TargetSpell(1, filterSpell); + ability.addTarget(target); + } +} diff --git a/Mage.Sets/src/mage/cards/g/GethLordOfTheVault.java b/Mage.Sets/src/mage/cards/g/GethLordOfTheVault.java index 58c1bc3553..ce931358a9 100644 --- a/Mage.Sets/src/mage/cards/g/GethLordOfTheVault.java +++ b/Mage.Sets/src/mage/cards/g/GethLordOfTheVault.java @@ -14,7 +14,6 @@ import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Outcome; import mage.constants.SuperType; -import mage.constants.TargetAdjustment; import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.FilterCard; @@ -24,6 +23,7 @@ import mage.filter.predicate.other.OwnerPredicate; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInGraveyard; +import mage.target.targetadjustment.XCMCGraveyardAdjuster; /** * @author nantuko @@ -52,7 +52,7 @@ public final class GethLordOfTheVault extends CardImpl { // {X}{B}: Put target artifact or creature card with converted mana cost X from an opponent's graveyard onto the battlefield under your control tapped. // Then that player puts the top X cards of their library into their graveyard. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GethLordOfTheVaultEffect(), new ManaCostsImpl("{X}{B}")); - ability.setTargetAdjustment(TargetAdjustment.X_CMC_EQUAL_GY_CARD); + ability.setTargetAdjuster(XCMCGraveyardAdjuster.instance); ability.addTarget(new TargetCardInGraveyard(filter)); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/l/LazavTheMultifarious.java b/Mage.Sets/src/mage/cards/l/LazavTheMultifarious.java index 835106f467..446426e94e 100644 --- a/Mage.Sets/src/mage/cards/l/LazavTheMultifarious.java +++ b/Mage.Sets/src/mage/cards/l/LazavTheMultifarious.java @@ -18,7 +18,6 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; -import mage.constants.TargetAdjustment; import mage.constants.TargetController; import mage.filter.FilterCard; import mage.filter.common.FilterCreatureCard; @@ -28,6 +27,7 @@ import mage.game.permanent.Permanent; import mage.game.permanent.PermanentCard; import mage.players.Player; import mage.target.common.TargetCardInGraveyard; +import mage.target.targetadjustment.XCMCGraveyardAdjuster; import mage.target.targetpointer.FixedTarget; import mage.util.functions.ApplyToPermanent; @@ -62,7 +62,7 @@ public final class LazavTheMultifarious extends CardImpl { new ManaCostsImpl("{X}") ); ability.addTarget(new TargetCardInGraveyard(filter)); - ability.setTargetAdjustment(TargetAdjustment.X_CMC_EQUAL_GY_CARD); + ability.setTargetAdjuster(XCMCGraveyardAdjuster.instance); this.addAbility(ability); } @@ -137,7 +137,7 @@ class LazavTheMultifariousApplier extends ApplyToPermanent { new ManaCostsImpl("{X}") ); ability.addTarget(new TargetCardInGraveyard(filter)); - ability.setTargetAdjustment(TargetAdjustment.X_CMC_EQUAL_GY_CARD); + ability.setTargetAdjuster(XCMCGraveyardAdjuster.instance); permanent.getAbilities().add(ability); permanent.setName("Lazav, the Multifarious"); permanent.addSuperType(SuperType.LEGENDARY); @@ -151,7 +151,7 @@ class LazavTheMultifariousApplier extends ApplyToPermanent { new ManaCostsImpl("{X}") ); ability.addTarget(new TargetCardInGraveyard(filter)); - ability.setTargetAdjustment(TargetAdjustment.X_CMC_EQUAL_GY_CARD); + ability.setTargetAdjuster(XCMCGraveyardAdjuster.instance); mageObject.getAbilities().add(ability); mageObject.setName("Lazav, the Multifarious"); mageObject.addSuperType(SuperType.LEGENDARY); diff --git a/Mage.Sets/src/mage/cards/l/LeagueGuildmage.java b/Mage.Sets/src/mage/cards/l/LeagueGuildmage.java index 3ff66776aa..885e0d9327 100644 --- a/Mage.Sets/src/mage/cards/l/LeagueGuildmage.java +++ b/Mage.Sets/src/mage/cards/l/LeagueGuildmage.java @@ -12,11 +12,15 @@ import mage.constants.SubType; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.ComparisonType; import mage.constants.TargetController; import mage.filter.FilterSpell; import mage.filter.common.FilterInstantOrSorcerySpell; +import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; import mage.target.TargetSpell; +import mage.target.targetadjustment.TargetAdjuster; /** * @@ -53,6 +57,7 @@ public final class LeagueGuildmage extends CardImpl { ); ability.addCost(new TapSourceCost()); ability.addTarget(new TargetSpell(filter)); + ability.setTargetAdjuster(LeagueGuildmageAdjuster.instance); this.addAbility(ability); } @@ -65,3 +70,17 @@ public final class LeagueGuildmage extends CardImpl { return new LeagueGuildmage(this); } } + +enum LeagueGuildmageAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int xValue = ability.getManaCostsToPay().getX(); + FilterSpell spellFilter = new FilterInstantOrSorcerySpell("instant or sorcery you control with converted mana cost " + xValue); + spellFilter.add(new ControllerPredicate(TargetController.YOU)); + spellFilter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); + ability.getTargets().clear(); + ability.addTarget(new TargetSpell(spellFilter)); + } +} diff --git a/Mage.Sets/src/mage/cards/l/LegacysAllure.java b/Mage.Sets/src/mage/cards/l/LegacysAllure.java index 162c2fc5f3..acf4bbe6ec 100644 --- a/Mage.Sets/src/mage/cards/l/LegacysAllure.java +++ b/Mage.Sets/src/mage/cards/l/LegacysAllure.java @@ -1,4 +1,3 @@ - package mage.cards.l; import java.util.UUID; @@ -11,13 +10,17 @@ import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.ComparisonType; import mage.constants.Duration; -import mage.constants.TargetAdjustment; import mage.constants.TargetController; import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.mageobject.PowerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; /** * @author LevelX2 @@ -36,7 +39,7 @@ public final class LegacysAllure extends CardImpl { // Sacrifice Legacy's Allure: Gain control of target creature with power less than or equal to the number of treasure counters on Legacy's Allure. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainControlTargetEffect(Duration.EndOfGame, true), new SacrificeSourceCost()); ability.addTarget(new TargetCreaturePermanent(0, 0, filter, false)); - ability.setTargetAdjustment(TargetAdjustment.TREASURE_COUNTER_POWER); + ability.setTargetAdjuster(LegacysAllureAdjuster.instance); this.addAbility(ability); } @@ -49,3 +52,19 @@ public final class LegacysAllure extends CardImpl { return new LegacysAllure(this); } } + +enum LegacysAllureAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId()); + if (sourcePermanent != null) { + int xValue = sourcePermanent.getCounters(game).getCount(CounterType.TREASURE); + FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature with power less than or equal to " + xValue); + filter2.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); + ability.getTargets().clear(); + ability.getTargets().add(new TargetCreaturePermanent(filter2)); + } + } +} diff --git a/Mage.Sets/src/mage/cards/m/MinamoSightbender.java b/Mage.Sets/src/mage/cards/m/MinamoSightbender.java index b20ca6ff0d..dc001957da 100644 --- a/Mage.Sets/src/mage/cards/m/MinamoSightbender.java +++ b/Mage.Sets/src/mage/cards/m/MinamoSightbender.java @@ -1,4 +1,3 @@ - package mage.cards.m; import java.util.UUID; @@ -11,13 +10,17 @@ import mage.abilities.effects.common.combat.CantBeBlockedTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.ComparisonType; import mage.constants.SubType; -import mage.constants.TargetAdjustment; import mage.constants.Zone; import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.filter.predicate.mageobject.PowerPredicate; +import mage.game.Game; import mage.target.Target; import mage.target.TargetPermanent; +import mage.target.targetadjustment.TargetAdjuster; /** * @@ -42,7 +45,7 @@ public final class MinamoSightbender extends CardImpl { // {X}, {T}: Target creature with power X or less can't be blocked this turn. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CantBeBlockedTargetEffect(), new ManaCostsImpl("{X}")); Target target = new TargetPermanent(filter); - ability.setTargetAdjustment(TargetAdjustment.X_POWER_LEQ); + ability.setTargetAdjuster(MinamoSightbenderAdjuster.instance); ability.addTarget(target); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -58,3 +61,16 @@ public final class MinamoSightbender extends CardImpl { return new MinamoSightbender(this); } } + +enum MinamoSightbenderAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int xValue = ability.getManaCostsToPay().getX(); + FilterPermanent permanentFilter = new FilterCreaturePermanent("creature with power " + xValue + " or less"); + permanentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); + ability.getTargets().clear(); + ability.getTargets().add(new TargetPermanent(permanentFilter)); + } +} diff --git a/Mage.Sets/src/mage/cards/p/PentarchPaladin.java b/Mage.Sets/src/mage/cards/p/PentarchPaladin.java index dffc4b86d0..4e27796c3e 100644 --- a/Mage.Sets/src/mage/cards/p/PentarchPaladin.java +++ b/Mage.Sets/src/mage/cards/p/PentarchPaladin.java @@ -1,8 +1,8 @@ - package mage.cards.p; import java.util.UUID; import mage.MageInt; +import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleActivatedAbility; @@ -19,7 +19,11 @@ import mage.constants.Zone; import mage.filter.FilterPermanent; import mage.target.TargetPermanent; import mage.abilities.effects.common.DestroyTargetEffect; -import mage.constants.TargetAdjustment; +import mage.constants.ComparisonType; +import mage.filter.predicate.mageobject.ColorPredicate; +import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; +import mage.game.Game; +import mage.target.targetadjustment.TargetAdjuster; /** * @@ -27,7 +31,7 @@ import mage.constants.TargetAdjustment; */ public final class PentarchPaladin extends CardImpl { - FilterPermanent filter = new FilterPermanent("permanent of the chosen color."); + private static final FilterPermanent filter = new FilterPermanent("permanent of the chosen color."); public PentarchPaladin(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}{W}{W}"); @@ -47,7 +51,7 @@ public final class PentarchPaladin extends CardImpl { Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), new ManaCostsImpl("{W}{W}")); ability.addCost(new TapSourceCost()); ability.addTarget(new TargetPermanent(filter)); - ability.setTargetAdjustment(TargetAdjustment.CHOSEN_COLOR); + ability.setTargetAdjuster(PentarchPaladinAdjuster.instance); this.addAbility(ability); } @@ -60,3 +64,21 @@ public final class PentarchPaladin extends CardImpl { return new PentarchPaladin(this); } } + +enum PentarchPaladinAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ObjectColor chosenColor = (ObjectColor) game.getState().getValue(ability.getSourceId() + "_color"); + ability.getTargets().clear(); + FilterPermanent filter = new FilterPermanent("permanent of the chosen color."); + if (chosenColor != null) { + filter.add(new ColorPredicate(chosenColor)); + } else { + filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, -5));// Pretty sure this is always false + } + TargetPermanent oldTargetPermanent = new TargetPermanent(filter); + ability.addTarget(oldTargetPermanent); + } +} diff --git a/Mage.Sets/src/mage/cards/s/SimicManipulator.java b/Mage.Sets/src/mage/cards/s/SimicManipulator.java index f4c12960b6..5e74a62d85 100644 --- a/Mage.Sets/src/mage/cards/s/SimicManipulator.java +++ b/Mage.Sets/src/mage/cards/s/SimicManipulator.java @@ -1,4 +1,3 @@ - package mage.cards.s; import java.util.UUID; @@ -7,6 +6,7 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.Cost; import mage.abilities.costs.common.RemoveVariableCountersSourceCost; +import mage.abilities.costs.common.RemoveVariableCountersTargetCost; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.abilities.keyword.EvolveAbility; @@ -21,7 +21,9 @@ import mage.counters.CounterType; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.PowerPredicate; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; /** * Gatecrash FAQ (01.2013) @@ -37,7 +39,6 @@ import mage.target.common.TargetCreaturePermanent; */ public final class SimicManipulator extends CardImpl { - private final UUID originalId; private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("with power less than or equal to the number of +1/+1 counters removed this way"); public SimicManipulator(UUID ownerId, CardSetInfo setInfo) { @@ -55,36 +56,38 @@ public final class SimicManipulator extends CardImpl { Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainControlTargetEffect(Duration.Custom, true), new TapSourceCost()); ability.addTarget(new TargetCreaturePermanent(filter)); ability.addCost(new RemoveVariableCountersSourceCost(CounterType.P1P1.createInstance(), 1, "Remove one or more +1/+1 counters from {this}")); + ability.setTargetAdjuster(SimicManipulatorAdjuster.instance); this.addAbility(ability); - this.originalId = ability.getOriginalId(); - } public SimicManipulator(final SimicManipulator card) { super(card); - this.originalId = card.originalId; } @Override public SimicManipulator copy() { return new SimicManipulator(this); } +} + +enum SimicManipulatorAdjuster implements TargetAdjuster { + instance; @Override public void adjustTargets(Ability ability, Game game) { - if (ability.getOriginalId().equals(originalId)) { - ability.getTargets().clear(); - int maxPower = 0; - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with power less than or equal to the number of +1/+1 counters removed this way"); + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId()); + if (sourcePermanent != null) { + int xValue = 0; for (Cost cost : ability.getCosts()) { - if (cost instanceof RemoveVariableCountersSourceCost) { - maxPower = ((RemoveVariableCountersSourceCost) cost).getAmount(); + if (cost instanceof RemoveVariableCountersTargetCost) { + xValue = ((RemoveVariableCountersTargetCost) cost).getAmount(); break; } } - filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, maxPower + 1)); - TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, false); - ability.addTarget(target); + ability.getTargets().clear(); + FilterCreaturePermanent newFilter = new FilterCreaturePermanent("creature with power " + xValue + " or less"); + newFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); + ability.addTarget(new TargetCreaturePermanent(newFilter)); } } } diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index be374afd61..8b19cf5d3f 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -5,27 +5,12 @@ import mage.MageObjectImpl; import mage.Mana; import mage.ObjectColor; import mage.abilities.*; -import mage.abilities.costs.Cost; -import mage.abilities.costs.VariableCost; -import mage.abilities.costs.common.RemoveVariableCountersTargetCost; -import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.repository.PluginClassloaderRegistery; import mage.constants.*; import mage.counters.Counter; -import mage.counters.CounterType; import mage.counters.Counters; -import mage.filter.FilterCard; import mage.filter.FilterMana; -import mage.filter.FilterPermanent; -import mage.filter.FilterSpell; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.common.FilterInstantOrSorcerySpell; -import mage.filter.predicate.permanent.ControllerPredicate; -import mage.filter.predicate.mageobject.ColorPredicate; -import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; -import mage.filter.predicate.mageobject.NamePredicate; -import mage.filter.predicate.mageobject.PowerPredicate; import mage.game.*; import mage.game.command.CommandObject; import mage.game.events.GameEvent; @@ -33,10 +18,6 @@ import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.game.stack.StackObject; -import mage.target.TargetCard; -import mage.target.TargetPermanent; -import mage.target.TargetSpell; -import mage.target.common.TargetCreaturePermanent; import mage.util.GameLog; import mage.util.SubTypeList; import mage.watchers.Watcher; @@ -48,7 +29,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; -import mage.target.common.TargetCardInGraveyard; public abstract class CardImpl extends MageObjectImpl implements Card { @@ -353,93 +333,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { @Override public void adjustTargets(Ability ability, Game game) { ability.adjustTargets(game); - int xValue; - TargetPermanent oldTargetPermanent; - FilterPermanent permanentFilter; - int minTargets; - int maxTargets; - switch (ability.getTargetAdjustment()) { - case NONE: - break; - case X_POWER_LEQ:// Minamo Sightbender only - xValue = ability.getManaCostsToPay().getX(); - oldTargetPermanent = (TargetPermanent) ability.getTargets().get(0); - minTargets = oldTargetPermanent.getMinNumberOfTargets(); - maxTargets = oldTargetPermanent.getMaxNumberOfTargets(); - permanentFilter = oldTargetPermanent.getFilter().copy(); - permanentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); - ability.getTargets().clear(); - ability.getTargets().add(new TargetPermanent(minTargets, maxTargets, permanentFilter, false)); - break; - case X_CMC_EQUAL_GY_CARD: - xValue = ability.getManaCostsToPay().getX(); - FilterCard filterCard = ((TargetCard) ability.getTargets().get(0)).getFilter().copy(); - filterCard.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); - filterCard.setMessage(filterCard.getMessage().replace('X', (char) xValue)); - ability.getTargets().clear(); - ability.getTargets().add(new TargetCardInGraveyard(filterCard)); - break; - case CHOSEN_NAME: //Declaration of Naught only - ability.getTargets().clear(); - FilterSpell filterSpell = new FilterSpell("spell with the chosen name"); - filterSpell.add(new NamePredicate((String) game.getState().getValue(ability.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY))); - TargetSpell target = new TargetSpell(1, filterSpell); - ability.addTarget(target); - break; - case CHOSEN_COLOR: //Pentarch Paladin only - ObjectColor chosenColor = (ObjectColor) game.getState().getValue(ability.getSourceId() + "_color"); - ability.getTargets().clear(); - FilterPermanent filter = new FilterPermanent("permanent of the chosen color."); - if (chosenColor != null) { - filter.add(new ColorPredicate(chosenColor)); - } else { - filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, -5));// Pretty sure this is always false - } - oldTargetPermanent = new TargetPermanent(filter); - ability.addTarget(oldTargetPermanent); - break; - case TREASURE_COUNTER_POWER: //Legacy's Allure only - Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId()); - if (sourcePermanent != null) { - xValue = sourcePermanent.getCounters(game).getCount(CounterType.TREASURE); - FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature with power less than or equal to the number of treasure counters on {this}"); - filter2.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); - ability.getTargets().clear(); - ability.getTargets().add(new TargetCreaturePermanent(filter2)); - } - break; - case SIMIC_MANIPULATOR: //Simic Manipulator only - xValue = 0; - for (Cost cost : ability.getCosts()) { - if (cost instanceof RemoveVariableCountersTargetCost) { - xValue = ((RemoveVariableCountersTargetCost) cost).getAmount(); - break; - } - } - ability.getTargets().clear(); - FilterCreaturePermanent newFilter = new FilterCreaturePermanent("creature with power less than or equal to " + xValue); - newFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1)); - ability.addTarget(new TargetCreaturePermanent(newFilter)); - break; - case CREATURE_POWER_X_OR_LESS: // Aryel, Knight of Windgrace - int value = 0; - for (VariableCost cost : ability.getCosts().getVariableCosts()) { - value = cost.getAmount(); - } - FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("creature with power " + value + " or less"); - filterCreaturePermanent.add(new PowerPredicate(ComparisonType.FEWER_THAN, value + 1)); - ability.getTargets().clear(); - ability.addTarget(new TargetCreaturePermanent(filterCreaturePermanent)); - break; - case X_CMC_EQUAL_SPELL_CONTROLLED: // League Guildmage - xValue = ability.getManaCostsToPay().getX(); - FilterSpell spellFilter = new FilterInstantOrSorcerySpell("instant or sorcery you control with converted mana cost " + xValue); - spellFilter.add(new ControllerPredicate(TargetController.YOU)); - spellFilter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); - ability.getTargets().clear(); - ability.addTarget(new TargetSpell(spellFilter)); - break; - } } @Override diff --git a/Mage/src/main/java/mage/target/targetadjustment/XCMCGraveyardAdjuster.java b/Mage/src/main/java/mage/target/targetadjustment/XCMCGraveyardAdjuster.java new file mode 100644 index 0000000000..617da884a1 --- /dev/null +++ b/Mage/src/main/java/mage/target/targetadjustment/XCMCGraveyardAdjuster.java @@ -0,0 +1,27 @@ +package mage.target.targetadjustment; + +import mage.abilities.Ability; +import mage.constants.ComparisonType; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; +import mage.game.Game; +import mage.target.TargetCard; +import mage.target.common.TargetCardInGraveyard; + +/** + * + * @author TheElk801 + */ +public enum XCMCGraveyardAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int xValue = ability.getManaCostsToPay().getX(); + FilterCard filterCard = ((TargetCard) ability.getTargets().get(0)).getFilter().copy(); + filterCard.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue)); + filterCard.setMessage(filterCard.getMessage().replace('X', (char) xValue)); + ability.getTargets().clear(); + ability.getTargets().add(new TargetCardInGraveyard(filterCard)); + } +}