From c9ca0e8916be315718c92e524b6faa23c79df543 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 30 Sep 2018 20:28:40 -0400 Subject: [PATCH] finished the last few target adjusters --- .../src/mage/cards/n/NecropolisFiend.java | 97 +++++++++++-------- .../src/mage/cards/p/PhyrexianPurge.java | 51 ++++++---- Mage.Sets/src/mage/cards/s/ScorchedEarth.java | 62 +++++------- 3 files changed, 110 insertions(+), 100 deletions(-) diff --git a/Mage.Sets/src/mage/cards/n/NecropolisFiend.java b/Mage.Sets/src/mage/cards/n/NecropolisFiend.java index a4219545b3..db6e9c26c8 100644 --- a/Mage.Sets/src/mage/cards/n/NecropolisFiend.java +++ b/Mage.Sets/src/mage/cards/n/NecropolisFiend.java @@ -1,11 +1,11 @@ package mage.cards.n; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.Cost; +import mage.abilities.costs.CostAdjuster; import mage.abilities.costs.VariableCost; import mage.abilities.costs.common.ExileFromGraveCost; import mage.abilities.costs.common.TapSourceCost; @@ -21,8 +21,8 @@ import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.filter.FilterCard; import mage.game.Game; @@ -30,15 +30,17 @@ import mage.players.Player; import mage.target.Target; import mage.target.common.TargetCardInYourGraveyard; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class NecropolisFiend extends CardImpl { public NecropolisFiend(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{7}{B}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{7}{B}{B}"); this.subtype.add(SubType.DEMON); this.power = new MageInt(4); @@ -46,54 +48,29 @@ public final class NecropolisFiend extends CardImpl { // Delve this.addAbility(new DelveAbility()); + // Flying this.addAbility(FlyingAbility.getInstance()); - //TODO: Make ability properly copiable + // {X}, {T}, Exile X cards from your graveyard: Target creature gets -X/-X until end of turn. DynamicValue xValue = new SignInversionDynamicValue(new ManacostVariableValue()); - Effect effect = new BoostTargetEffect(xValue,xValue,Duration.EndOfTurn); + Effect effect = new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn); effect.setText("Target creature gets -X/-X until end of turn"); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{X}")); + Ability ability = new SimpleActivatedAbility( + Zone.BATTLEFIELD, effect, + new ManaCostsImpl("{X}") + ); ability.addCost(new TapSourceCost()); ability.addTarget(new TargetCreaturePermanent()); - ability.addCost(new ExileFromGraveCost(new TargetCardInYourGraveyard(1,1,new FilterCard("cards from your graveyard")), "Exile X cards from your graveyard")); + ability.addCost(new ExileFromGraveCost(new TargetCardInYourGraveyard( + 1, 1, new FilterCard("cards from your graveyard") + ), "Exile X cards from your graveyard")); + ability.setTargetAdjuster(NecropolisFiendTargetAdjuster.instance); + ability.setCostAdjuster(NecropolisFiendCostAdjuster.instance); this.addAbility(ability); } - @Override - public void adjustCosts(Ability ability, Game game) { - if (ability instanceof SimpleActivatedAbility) { - Player controller = game.getPlayer(ability.getControllerId()); - if (controller != null) { - for (VariableCost variableCost: ability.getManaCostsToPay().getVariableCosts()) { - if (variableCost instanceof VariableManaCost) { - ((VariableManaCost)variableCost).setMaxX(controller.getGraveyard().size()); - } - } - } - } - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SimpleActivatedAbility) { - int xValue = ability.getManaCostsToPay().getX(); - for(Cost cost: ability.getCosts()) { - if (cost instanceof ExileFromGraveCost) { - ExileFromGraveCost exileCost = (ExileFromGraveCost) cost; - for(Target target: exileCost.getTargets()) { - if (target instanceof TargetCardInYourGraveyard) { - target.setMaxNumberOfTargets(xValue); - target.setMinNumberOfTargets(xValue); - } - } - - } - } - } - } - public NecropolisFiend(final NecropolisFiend card) { super(card); } @@ -103,3 +80,41 @@ public final class NecropolisFiend extends CardImpl { return new NecropolisFiend(this); } } + +enum NecropolisFiendCostAdjuster implements CostAdjuster { + instance; + + @Override + public void adjustCosts(Ability ability, Game game) { + Player controller = game.getPlayer(ability.getControllerId()); + if (controller == null) { + return; + } + for (VariableCost variableCost : ability.getManaCostsToPay().getVariableCosts()) { + if (variableCost instanceof VariableManaCost) { + ((VariableManaCost) variableCost).setMaxX(controller.getGraveyard().size()); + } + } + } +} + +enum NecropolisFiendTargetAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int xValue = ability.getManaCostsToPay().getX(); + for (Cost cost : ability.getCosts()) { + if (!(cost instanceof ExileFromGraveCost)) { + continue; + } + ExileFromGraveCost exileCost = (ExileFromGraveCost) cost; + for (Target target : exileCost.getTargets()) { + if (target instanceof TargetCardInYourGraveyard) { + target.setMaxNumberOfTargets(xValue); + target.setMinNumberOfTargets(xValue); + } + } + } + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/p/PhyrexianPurge.java b/Mage.Sets/src/mage/cards/p/PhyrexianPurge.java index f6860e52d4..526c986b5b 100644 --- a/Mage.Sets/src/mage/cards/p/PhyrexianPurge.java +++ b/Mage.Sets/src/mage/cards/p/PhyrexianPurge.java @@ -1,9 +1,8 @@ package mage.cards.p; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; +import mage.abilities.costs.CostAdjuster; import mage.abilities.costs.common.PayLifeCost; import mage.abilities.effects.common.DestroyMultiTargetEffect; import mage.abilities.effects.common.InfoEffect; @@ -13,9 +12,11 @@ import mage.constants.CardType; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author escplan9 - Derek Monturo */ public final class PhyrexianPurge extends CardImpl { @@ -28,24 +29,8 @@ public final class PhyrexianPurge extends CardImpl { this.getSpellAbility().addTarget(new TargetCreaturePermanent(0, Integer.MAX_VALUE)); this.getSpellAbility().addEffect(new DestroyMultiTargetEffect()); this.getSpellAbility().addEffect(new InfoEffect("

{this} costs 3 life more to cast for each target")); - } - - @Override - public void adjustCosts(Ability ability, Game game) { - int numTargets = ability.getTargets().get(0).getTargets().size(); - if (numTargets > 0) { - ability.getCosts().add(new PayLifeCost(numTargets * 3)); - } - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - Player you = game.getPlayer(ownerId); - int maxTargets = you.getLife() / 3; - ability.addTarget(new TargetCreaturePermanent(0, maxTargets)); - } + this.getSpellAbility().setTargetAdjuster(PhyrexianPurgeTargetAdjuster.instance); + this.getSpellAbility().setCostAdjuster(PhyrexianPurgeCostAdjuster.instance); } public PhyrexianPurge(final PhyrexianPurge card) { @@ -57,3 +42,27 @@ public final class PhyrexianPurge extends CardImpl { return new PhyrexianPurge(this); } } + +enum PhyrexianPurgeCostAdjuster implements CostAdjuster { + instance; + + @Override + public void adjustCosts(Ability ability, Game game) { + int numTargets = ability.getTargets().get(0).getTargets().size(); + if (numTargets > 0) { + ability.getCosts().add(new PayLifeCost(numTargets * 3)); + } + } +} + +enum PhyrexianPurgeTargetAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + Player you = game.getPlayer(ability.getControllerId()); + int maxTargets = you.getLife() / 3; + ability.addTarget(new TargetCreaturePermanent(0, maxTargets)); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/s/ScorchedEarth.java b/Mage.Sets/src/mage/cards/s/ScorchedEarth.java index bc2c406e14..0c578f5129 100644 --- a/Mage.Sets/src/mage/cards/s/ScorchedEarth.java +++ b/Mage.Sets/src/mage/cards/s/ScorchedEarth.java @@ -1,36 +1,36 @@ package mage.cards.s; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.CostAdjuster; import mage.abilities.costs.common.DiscardTargetCost; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DestroyTargetEffect; +import mage.abilities.effects.common.InfoEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.common.FilterLandCard; import mage.filter.common.FilterLandPermanent; import mage.game.Game; import mage.target.common.TargetCardInHand; import mage.target.common.TargetLandPermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; /** - * * @author fireshoes */ public final class ScorchedEarth extends CardImpl { public ScorchedEarth(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{X}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{R}"); // As an additional cost to cast Scorched Earth, discard X land cards. - Ability ability = new SimpleStaticAbility(Zone.ALL, new ScorchedEarthRuleEffect()); + Ability ability = new SimpleStaticAbility(Zone.ALL, new InfoEffect("as an additional cost to cast this spell, discard X land cards")); ability.setRuleAtTheTop(true); this.addAbility(ability); @@ -39,53 +39,39 @@ public final class ScorchedEarth extends CardImpl { effect.setText("Destroy X target lands"); this.getSpellAbility().addTarget(new TargetLandPermanent()); this.getSpellAbility().addEffect(effect); - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - ability.getTargets().clear(); - int xValue = ability.getManaCostsToPay().getX(); - ability.addTarget(new TargetLandPermanent(xValue, xValue, new FilterLandPermanent(), false)); - } + this.getSpellAbility().setTargetAdjuster(ScorchedEarthTargetAdjuster.instance); + this.getSpellAbility().setCostAdjuster(ScorchedEarthCostAdjuster.instance); } public ScorchedEarth(final ScorchedEarth card) { super(card); } - @Override - public void adjustCosts(Ability ability, Game game) { - int xValue = ability.getManaCostsToPay().getX(); - if (xValue > 0) { - ability.addCost(new DiscardTargetCost(new TargetCardInHand(xValue, xValue, new FilterLandCard("land cards")))); - } - } - @Override public ScorchedEarth copy() { return new ScorchedEarth(this); } } -class ScorchedEarthRuleEffect extends OneShotEffect { - - public ScorchedEarthRuleEffect() { - super(Outcome.Benefit); - this.staticText = "as an additional cost to cast this spell, discard X land cards"; - } - - public ScorchedEarthRuleEffect(final ScorchedEarthRuleEffect effect) { - super(effect); - } +enum ScorchedEarthTargetAdjuster implements TargetAdjuster { + instance; @Override - public ScorchedEarthRuleEffect copy() { - return new ScorchedEarthRuleEffect(this); + public void adjustTargets(Ability ability, Game game) { + ability.getTargets().clear(); + int xValue = ability.getManaCostsToPay().getX(); + ability.addTarget(new TargetLandPermanent(xValue, xValue, new FilterLandPermanent(), false)); } +} + +enum ScorchedEarthCostAdjuster implements CostAdjuster { + instance; @Override - public boolean apply(Game game, Ability source) { - return true; + public void adjustCosts(Ability ability, Game game) { + int xValue = ability.getManaCostsToPay().getX(); + if (xValue > 0) { + ability.addCost(new DiscardTargetCost(new TargetCardInHand(xValue, xValue, new FilterLandCard("land cards")))); + } } } \ No newline at end of file