From e0ce04c436379807fae639b16fd54b48745595ee Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 3 Apr 2019 11:18:11 -0400 Subject: [PATCH] updated damage triggers to include planeswalker damage --- .../mage/cards/v/VraskaSwarmsEminence.java | 1 + ...CombatDamageToAPlayerTriggeredAbility.java | 22 +++++++++++++------ .../DealsDamageToAPlayerTriggeredAbility.java | 21 ++++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Mage.Sets/src/mage/cards/v/VraskaSwarmsEminence.java b/Mage.Sets/src/mage/cards/v/VraskaSwarmsEminence.java index 014f79cd0a..e1a7d3f2a5 100644 --- a/Mage.Sets/src/mage/cards/v/VraskaSwarmsEminence.java +++ b/Mage.Sets/src/mage/cards/v/VraskaSwarmsEminence.java @@ -39,6 +39,7 @@ public final class VraskaSwarmsEminence extends CardImpl { this.addAbility(new PlaneswalkerEntersWithLoyaltyCountersAbility(5)); // Whenever a creature you control with deathtouch deals damage to a player or planeswalker, put a +1/+1 counter on that creature. + // TODO: make this trigger on planeswalkers this.addAbility(new DealsDamageToAPlayerAllTriggeredAbility( new AddCountersTargetEffect( CounterType.P1P1.createInstance() diff --git a/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java index 3045a8fa88..29939dc494 100644 --- a/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java @@ -5,20 +5,20 @@ import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; import mage.constants.Zone; import mage.game.Game; -import mage.game.events.DamagedPlayerEvent; +import mage.game.events.DamagedEvent; import mage.game.events.GameEvent; import mage.players.Player; import mage.target.targetpointer.FixedTarget; /** - * * @author BetaSteward_at_googlemail.com */ public class DealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbilityImpl { - protected boolean setTargetPointer; + protected final boolean setTargetPointer; protected String text; protected boolean onlyOpponents; + private boolean orPlaneswalker = false; public DealsCombatDamageToAPlayerTriggeredAbility(Effect effect, boolean optional) { this(effect, optional, false); @@ -47,6 +47,10 @@ public class DealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbility this.onlyOpponents = ability.onlyOpponents; } + public void setOrPlaneswalker(boolean orPlaneswalker) { + this.orPlaneswalker = orPlaneswalker; + } + @Override public DealsCombatDamageToAPlayerTriggeredAbility copy() { return new DealsCombatDamageToAPlayerTriggeredAbility(this); @@ -54,14 +58,15 @@ public class DealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbility @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; + return event.getType() == GameEvent.EventType.DAMAGED_PLAYER + || (orPlaneswalker && event.getType() == GameEvent.EventType.DAMAGED_PLANESWALKER); } @Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getSourceId().equals(getSourceId()) - && ((DamagedPlayerEvent) event).isCombatDamage()) { - if (onlyOpponents) { + && ((DamagedEvent) event).isCombatDamage()) { + if (onlyOpponents && event.getType() == GameEvent.EventType.DAMAGED_PLAYER) { Player controller = game.getPlayer(getControllerId()); if (controller == null || !controller.hasOpponent(event.getPlayerId(), game)) { return false; @@ -81,7 +86,10 @@ public class DealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbility @Override public String getRule() { if (text == null || text.isEmpty()) { - return "Whenever {this} deals combat damage to " + (onlyOpponents ? "an opponent, " : "a player, ") + super.getRule(); + return "Whenever {this} deals combat damage to " + + (onlyOpponents ? "an opponent" : "a player") + + (orPlaneswalker ? " or planeswalker" : "") + + ", " + super.getRule(); } return text; } diff --git a/Mage/src/main/java/mage/abilities/common/DealsDamageToAPlayerTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DealsDamageToAPlayerTriggeredAbility.java index 2c9c1fc011..289743355a 100644 --- a/Mage/src/main/java/mage/abilities/common/DealsDamageToAPlayerTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DealsDamageToAPlayerTriggeredAbility.java @@ -2,32 +2,38 @@ package mage.abilities.common; -import mage.constants.Zone; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.target.targetpointer.FixedTarget; /** - * * @author jeff */ public class DealsDamageToAPlayerTriggeredAbility extends TriggeredAbilityImpl { - private boolean setTargetPointer; + private final boolean setTargetPointer; + private final boolean orPlaneswalker; public DealsDamageToAPlayerTriggeredAbility(Effect effect, boolean optional) { this(effect, optional, false); } public DealsDamageToAPlayerTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) { + this(effect, optional, setTargetPointer, false); + } + + public DealsDamageToAPlayerTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer, boolean orPlaneswalker) { super(Zone.BATTLEFIELD, effect, optional); this.setTargetPointer = setTargetPointer; + this.orPlaneswalker = orPlaneswalker; } public DealsDamageToAPlayerTriggeredAbility(final DealsDamageToAPlayerTriggeredAbility ability) { super(ability); this.setTargetPointer = ability.setTargetPointer; + this.orPlaneswalker = ability.orPlaneswalker; } @Override @@ -37,7 +43,8 @@ public class DealsDamageToAPlayerTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; + return event.getType() == GameEvent.EventType.DAMAGED_PLAYER + || (orPlaneswalker && event.getType() == GameEvent.EventType.DAMAGED_PLANESWALKER); } @Override @@ -45,8 +52,8 @@ public class DealsDamageToAPlayerTriggeredAbility extends TriggeredAbilityImpl { if (event.getSourceId().equals(this.sourceId)) { if (setTargetPointer) { for (Effect effect : this.getEffects()) { - effect.setTargetPointer(new FixedTarget(event.getPlayerId())); - effect.setValue("damage", event.getAmount()); + effect.setTargetPointer(new FixedTarget(event.getPlayerId())); + effect.setValue("damage", event.getAmount()); } } return true; @@ -56,7 +63,7 @@ public class DealsDamageToAPlayerTriggeredAbility extends TriggeredAbilityImpl { @Override public String getRule() { - return "Whenever {this} deals damage to a player, " + super.getRule(); + return "Whenever {this} deals damage to a player" + (orPlaneswalker ? " or planeswalker" : "") + ", " + super.getRule(); } }