diff --git a/Mage.Sets/src/mage/cards/w/WarTax.java b/Mage.Sets/src/mage/cards/w/WarTax.java index d22850aff6..a82625fd18 100644 --- a/Mage.Sets/src/mage/cards/w/WarTax.java +++ b/Mage.Sets/src/mage/cards/w/WarTax.java @@ -30,10 +30,11 @@ package mage.cards.w; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.PayCostToAttackBlockEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -42,12 +43,12 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; -import mage.players.Player; +import mage.game.permanent.Permanent; /** * * - * @author HCrescent original code by LevelX2 edited from War Cadence + * @author HCrescent & L_J */ public class WarTax extends CardImpl { @@ -55,7 +56,7 @@ public class WarTax extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}"); // {X}{U}: This turn, creatures can't attack unless their controller pays {X} for each attacking creature he or she controls. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new WarTaxReplacementEffect(), new ManaCostsImpl("{X}{U}"))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new WarTaxCantAttackUnlessPaysEffect(), new ManaCostsImpl("{X}{U}"))); } public WarTax(final WarTax card) { @@ -68,49 +69,42 @@ public class WarTax extends CardImpl { } } -class WarTaxReplacementEffect extends ReplacementEffectImpl { +class WarTaxCantAttackUnlessPaysEffect extends PayCostToAttackBlockEffectImpl { DynamicValue xCosts = new ManacostVariableValue(); - WarTaxReplacementEffect() { - super(Duration.EndOfTurn, Outcome.Neutral); + WarTaxCantAttackUnlessPaysEffect() { + super(Duration.EndOfTurn, Outcome.Neutral, RestrictType.ATTACK); staticText = "This turn, creatures can't attack unless their controller pays {X} for each attacking creature he or she controls"; } - WarTaxReplacementEffect(WarTaxReplacementEffect effect) { + WarTaxCantAttackUnlessPaysEffect(WarTaxCantAttackUnlessPaysEffect effect) { super(effect); } - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player player = game.getPlayer(event.getPlayerId()); - if (player != null) { - int amount = xCosts.calculate(game, source, this); - String mana = "{" + amount + '}'; - ManaCostsImpl cost = new ManaCostsImpl(mana); - if (cost.canPay(source, source.getSourceId(), event.getPlayerId(), game) - && player.chooseUse(Outcome.Benefit, "Pay " + mana + " to declare attacker?", source, game)) { - if (cost.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) { - return false; - } - } - return true; - } - return false; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DECLARE_ATTACKER; - } - @Override public boolean applies(GameEvent event, Ability source, Game game) { return true; } @Override - public WarTaxReplacementEffect copy() { - return new WarTaxReplacementEffect(this); + public ManaCosts getManaCostToPay(GameEvent event, Ability source, Game game) { + Permanent sourceObject = game.getPermanent(source.getSourceId()); + if (sourceObject != null) { + int amount = xCosts.calculate(game, source, this); + return new ManaCostsImpl<>("{" + amount + '}'); + } + return null; } + + @Override + public boolean isCostless(GameEvent event, Ability source, Game game) { + return false; + } + + @Override + public WarTaxCantAttackUnlessPaysEffect copy() { + return new WarTaxCantAttackUnlessPaysEffect(this); + } + }