Fixed War Tax to work with Seasons of the Witch (fixes #4145)

This commit is contained in:
Zzooouhh 2017-11-03 21:19:47 +01:00 committed by GitHub
parent 4176b35f2a
commit 299e164da3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,10 +30,11 @@ package mage.cards.w;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.PayCostToAttackBlockEffectImpl;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
@ -42,12 +43,12 @@ import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; 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 { public class WarTax extends CardImpl {
@ -55,7 +56,7 @@ public class WarTax extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}"); 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. // {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) { 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(); DynamicValue xCosts = new ManacostVariableValue();
WarTaxReplacementEffect() { WarTaxCantAttackUnlessPaysEffect() {
super(Duration.EndOfTurn, Outcome.Neutral); 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"; 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); 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 @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
return true; return true;
} }
@Override @Override
public WarTaxReplacementEffect copy() { public ManaCosts getManaCostToPay(GameEvent event, Ability source, Game game) {
return new WarTaxReplacementEffect(this); 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);
}
} }