From 913d5dfee8e63dcb5084e2a9f3d100d026a7d44a Mon Sep 17 00:00:00 2001 From: xenohedron Date: Fri, 2 Jun 2023 11:29:51 +0300 Subject: [PATCH] Cleanup: PreventDamageAndRemoveCountersEffect (#10321) * Add tests (two passing, one failing due to incorrect implementation) * Cleanup PreventDamageAndRemoveCountersEffect; fix Protean Hydra --- Mage.Sets/src/mage/cards/m/MagmaPummeler.java | 31 ++------ .../src/mage/cards/o/OathswornKnight.java | 2 +- .../src/mage/cards/p/PolukranosUnchained.java | 2 +- Mage.Sets/src/mage/cards/p/ProteanHydra.java | 8 +- .../src/mage/cards/u/UginsConjurant.java | 2 +- .../src/mage/cards/u/UnbreathingHorde.java | 69 +++------------- .../src/mage/cards/u/UndergrowthChampion.java | 79 +------------------ .../PreventDamageRemoveCountersTest.java | 77 ++++++++++++++++++ .../PreventDamageAndRemoveCountersEffect.java | 16 ++-- 9 files changed, 111 insertions(+), 175 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventDamageRemoveCountersTest.java diff --git a/Mage.Sets/src/mage/cards/m/MagmaPummeler.java b/Mage.Sets/src/mage/cards/m/MagmaPummeler.java index 0c53646f66..d685327fa7 100644 --- a/Mage.Sets/src/mage/cards/m/MagmaPummeler.java +++ b/Mage.Sets/src/mage/cards/m/MagmaPummeler.java @@ -5,13 +5,12 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.delayed.ReflexiveTriggeredAbility; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.PreventDamageAndRemoveCountersEffect; import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.EntersBattlefieldWithXCountersEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Duration; import mage.constants.SubType; import mage.counters.CounterType; import mage.game.Game; @@ -36,7 +35,8 @@ public final class MagmaPummeler extends CardImpl { // Magma Pummeler enters the battlefield with X +1/+1 counters on it. this.addAbility(new EntersBattlefieldAbility(new EntersBattlefieldWithXCountersEffect(CounterType.P1P1.createInstance()))); - // If damage would be dealt to Magma Pummeler while it has a +1/+1 counter on it, prevent that damage and remove that many +1/+1 counters from it. When one or more counters are removed from Magma Pummeler this way, it deals that much damage to any target. + // If damage would be dealt to Magma Pummeler while it has a +1/+1 counter on it, prevent that damage and remove that many +1/+1 counters from it. + // When one or more counters are removed from Magma Pummeler this way, it deals that much damage to any target. this.addAbility(new SimpleStaticAbility(new MagmaPummelerEffect())); } @@ -50,13 +50,11 @@ public final class MagmaPummeler extends CardImpl { } } -class MagmaPummelerEffect extends PreventionEffectImpl { +class MagmaPummelerEffect extends PreventDamageAndRemoveCountersEffect { public MagmaPummelerEffect() { - super(Duration.WhileOnBattlefield, Integer.MAX_VALUE, false, false); - staticText = "If damage would be dealt to {this} while it has a +1/+1 counter on it, " + - "prevent that damage and remove that many +1/+1 counters from it. " + - "When one or more counters are removed from {this} this way, it deals that much damage to any target."; + super(true, true, true); + staticText += ". When one or more counters are removed from {this} this way, it deals that much damage to any target"; } private MagmaPummelerEffect(final MagmaPummelerEffect effect) { @@ -68,21 +66,14 @@ class MagmaPummelerEffect extends PreventionEffectImpl { return new MagmaPummelerEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - return true; - } - @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - int damage = event.getAmount(); - preventDamageAction(event, source, game); Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent == null) { return false; } int beforeCounters = permanent.getCounters(game).getCount(CounterType.P1P1); - permanent.removeCounters(CounterType.P1P1.createInstance(damage), source, game); + super.replaceEvent(event, source, game); int countersRemoved = beforeCounters - permanent.getCounters(game).getCount(CounterType.P1P1); if (countersRemoved > 0) { ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility( @@ -95,12 +86,4 @@ class MagmaPummelerEffect extends PreventionEffectImpl { return false; } - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - Permanent permanent = game.getPermanent(event.getTargetId()); - return super.applies(event, source, game) - && permanent != null - && event.getTargetId().equals(source.getSourceId()) - && permanent.getCounters(game).containsKey(CounterType.P1P1); - } } diff --git a/Mage.Sets/src/mage/cards/o/OathswornKnight.java b/Mage.Sets/src/mage/cards/o/OathswornKnight.java index 70e3164371..bd0b07f927 100644 --- a/Mage.Sets/src/mage/cards/o/OathswornKnight.java +++ b/Mage.Sets/src/mage/cards/o/OathswornKnight.java @@ -36,7 +36,7 @@ public final class OathswornKnight extends CardImpl { this.addAbility(new AttacksEachCombatStaticAbility()); // If damage would be dealt to Oathsworn Knight while it has a +1/+1 counter on it, prevent that damage and remove a +1/+1 counter from it. - this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(false))); + this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(false, true, true))); } private OathswornKnight(final OathswornKnight card) { diff --git a/Mage.Sets/src/mage/cards/p/PolukranosUnchained.java b/Mage.Sets/src/mage/cards/p/PolukranosUnchained.java index 1cb8643156..73555a7833 100644 --- a/Mage.Sets/src/mage/cards/p/PolukranosUnchained.java +++ b/Mage.Sets/src/mage/cards/p/PolukranosUnchained.java @@ -51,7 +51,7 @@ public final class PolukranosUnchained extends CardImpl { this.addAbility(new EntersBattlefieldAbility(new PolukranosUnchainedEffect())); // If damage would be dealt to Polukranos while it has a +1/+1 counter on it, prevent that damage and remove that many +1/+1 counters from it. - this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(true))); + this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(true, true, true))); // {1}{B}{G}: Polukranos fights another target creature. Ability ability = new SimpleActivatedAbility(new FightTargetSourceEffect(), new ManaCostsImpl<>("{1}{B}{G}")); diff --git a/Mage.Sets/src/mage/cards/p/ProteanHydra.java b/Mage.Sets/src/mage/cards/p/ProteanHydra.java index 65ef2165ac..f0583051b8 100644 --- a/Mage.Sets/src/mage/cards/p/ProteanHydra.java +++ b/Mage.Sets/src/mage/cards/p/ProteanHydra.java @@ -19,7 +19,6 @@ import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; /** * @@ -38,7 +37,7 @@ public final class ProteanHydra extends CardImpl { this.addAbility(new EntersBattlefieldAbility(new EntersBattlefieldWithXCountersEffect(CounterType.P1P1.createInstance()))); // If damage would be dealt to Protean Hydra, prevent that damage and remove that many +1/+1 counters from it. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageAndRemoveCountersEffect(true))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageAndRemoveCountersEffect(true, false, true))); // Whenever a +1/+1 counter is removed from Protean Hydra, put two +1/+1 counters on it at the beginning of the next end step. this.addAbility(new ProteanHydraAbility()); @@ -76,10 +75,7 @@ public final class ProteanHydra extends CardImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - if (event.getData().equals("+1/+1") && event.getTargetId().equals(this.getSourceId())) { - return true; - } - return false; + return event.getData().equals("+1/+1") && event.getTargetId().equals(this.getSourceId()); } @Override diff --git a/Mage.Sets/src/mage/cards/u/UginsConjurant.java b/Mage.Sets/src/mage/cards/u/UginsConjurant.java index cf2582e131..1c6f87732b 100644 --- a/Mage.Sets/src/mage/cards/u/UginsConjurant.java +++ b/Mage.Sets/src/mage/cards/u/UginsConjurant.java @@ -31,7 +31,7 @@ public final class UginsConjurant extends CardImpl { // Ugin’s Conjurant enters the battlefield with X +1/+1 counters on it. this.addAbility(new EntersBattlefieldAbility(new EntersBattlefieldWithXCountersEffect(CounterType.P1P1.createInstance()))); // If damage would be dealt to Ugin’s Conjurant while it has a +1/+1 counter on it, prevent that damage and remove that many +1/+1 counters from Ugin’s Conjurant. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageAndRemoveCountersEffect(true))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageAndRemoveCountersEffect(true, true, false))); } private UginsConjurant(final UginsConjurant card) { diff --git a/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java b/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java index 6e361dab8b..41b5d56b22 100644 --- a/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java +++ b/Mage.Sets/src/mage/cards/u/UnbreathingHorde.java @@ -5,7 +5,7 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.PreventDamageAndRemoveCountersEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; @@ -13,10 +13,6 @@ import mage.counters.CounterType; import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; -import mage.game.events.DamageEvent; -import mage.game.events.GameEvent; -import mage.game.events.PreventDamageEvent; -import mage.game.events.PreventedDamageEvent; import mage.game.permanent.Permanent; import mage.players.Player; @@ -35,10 +31,11 @@ public final class UnbreathingHorde extends CardImpl { this.toughness = new MageInt(0); // Unbreathing Horde enters the battlefield with a +1/+1 counter on it for each other Zombie you control and each Zombie card in your graveyard. - this.addAbility(new EntersBattlefieldAbility(new UnbreathingHordeEffect1(), "with a +1/+1 counter on it for each other Zombie you control and each Zombie card in your graveyard")); + this.addAbility(new EntersBattlefieldAbility(new UnbreathingHordeEntersEffect(), "with a +1/+1 counter on it for each other Zombie you control and each Zombie card in your graveyard")); // If Unbreathing Horde would be dealt damage, prevent that damage and remove a +1/+1 counter from it. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new UnbreathingHordeEffect2())); + this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(false, false, true) + .setText("if {this} would be dealt damage, prevent that damage and remove a +1/+1 counter from it"))); } private UnbreathingHorde(final UnbreathingHorde card) { @@ -51,7 +48,7 @@ public final class UnbreathingHorde extends CardImpl { } } -class UnbreathingHordeEffect1 extends OneShotEffect { +class UnbreathingHordeEntersEffect extends OneShotEffect { private static final FilterCreaturePermanent filter1 = new FilterCreaturePermanent(); private static final FilterCreatureCard filter2 = new FilterCreatureCard(); @@ -61,12 +58,12 @@ class UnbreathingHordeEffect1 extends OneShotEffect { filter2.add(SubType.ZOMBIE.getPredicate()); } - public UnbreathingHordeEffect1() { + public UnbreathingHordeEntersEffect() { super(Outcome.BoostCreature); staticText = "{this} enters the battlefield with a +1/+1 counter on it for each other Zombie you control and each Zombie card in your graveyard"; } - public UnbreathingHordeEffect1(final UnbreathingHordeEffect1 effect) { + public UnbreathingHordeEntersEffect(final UnbreathingHordeEntersEffect effect) { super(effect); } @@ -86,56 +83,8 @@ class UnbreathingHordeEffect1 extends OneShotEffect { } @Override - public UnbreathingHordeEffect1 copy() { - return new UnbreathingHordeEffect1(this); - } - -} - -class UnbreathingHordeEffect2 extends PreventionEffectImpl { - - public UnbreathingHordeEffect2() { - super(Duration.WhileOnBattlefield); - staticText = "If damage would be dealt to {this}, prevent that damage and remove a +1/+1 counter from it"; - } - - public UnbreathingHordeEffect2(final UnbreathingHordeEffect2 effect) { - super(effect); - } - - @Override - public UnbreathingHordeEffect2 copy() { - return new UnbreathingHordeEffect2(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - boolean retValue = false; - GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()); - int damage = event.getAmount(); - if (!game.replaceEvent(preventEvent)) { - event.setAmount(0); - game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage)); - retValue = true; - } - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - permanent.removeCounters(CounterType.P1P1.createInstance(), source, game); - } - return retValue; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (super.applies(event, source, game)) { - return event.getTargetId().equals(source.getSourceId()); - } - return false; + public UnbreathingHordeEntersEffect copy() { + return new UnbreathingHordeEntersEffect(this); } } diff --git a/Mage.Sets/src/mage/cards/u/UndergrowthChampion.java b/Mage.Sets/src/mage/cards/u/UndergrowthChampion.java index 3d9dbba752..5016251c3f 100644 --- a/Mage.Sets/src/mage/cards/u/UndergrowthChampion.java +++ b/Mage.Sets/src/mage/cards/u/UndergrowthChampion.java @@ -3,23 +3,15 @@ package mage.cards.u; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.LandfallAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.PreventDamageAndRemoveCountersEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.PhaseStep; -import mage.constants.Zone; import mage.counters.CounterType; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; -import mage.game.turn.Step; /** * @@ -34,7 +26,7 @@ public final class UndergrowthChampion extends CardImpl { this.toughness = new MageInt(2); // If damage would be dealt to Undergrowth Champion while it has a +1/+1 counter on it, prevent that damage and remove a +1/+1 counter from Undergrowth Champion. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new UndergrowthChampionPreventionEffect())); + this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(false, true, false))); // Landfall-Whenever a land enters the battlefield under your control, put a +1/+1 counter on Undergrowth Champion. this.addAbility(new LandfallAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false)); @@ -49,70 +41,3 @@ public final class UndergrowthChampion extends CardImpl { return new UndergrowthChampion(this); } } - -class UndergrowthChampionPreventionEffect extends PreventionEffectImpl { - - // remember turn and phase step to check if counter in this step was already removed - private int turn = 0; - private Step combatPhaseStep = null; - - public UndergrowthChampionPreventionEffect() { - super(Duration.WhileOnBattlefield); - staticText = "If damage would be dealt to {this} while it has a +1/+1 counter on it, prevent that damage and remove a +1/+1 counter from {this}"; - } - - public UndergrowthChampionPreventionEffect(final UndergrowthChampionPreventionEffect effect) { - super(effect); - this.turn = effect.turn; - this.combatPhaseStep = effect.combatPhaseStep; - } - - @Override - public UndergrowthChampionPreventionEffect copy() { - return new UndergrowthChampionPreventionEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - boolean removeCounter = true; - // check if in the same combat damage step already a counter was removed - if (game.getTurn().getPhase().getStep().getType() == PhaseStep.COMBAT_DAMAGE) { - if (game.getTurnNum() == turn - && game.getTurn().getStep().equals(combatPhaseStep)) { - removeCounter = false; - } else { - turn = game.getTurnNum(); - combatPhaseStep = game.getTurn().getStep(); - } - } - - if(removeCounter && permanent.getCounters(game).containsKey(CounterType.P1P1)) { - preventDamageAction(event, source, game); - StringBuilder sb = new StringBuilder(permanent.getName()).append(": "); - permanent.removeCounters(CounterType.P1P1.createInstance(), source, game); - sb.append("Removed a +1/+1 counter "); - game.informPlayers(sb.toString()); - } - } - - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getSourceId())) { - return true; - } - } - return false; - } - -} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventDamageRemoveCountersTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventDamageRemoveCountersTest.java new file mode 100644 index 0000000000..4ea3ac7d89 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/prevention/PreventDamageRemoveCountersTest.java @@ -0,0 +1,77 @@ +package org.mage.test.cards.prevention; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Ignore; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +public class PreventDamageRemoveCountersTest extends CardTestPlayerBase { + + @Test + public void testCounterRemoval() { + setStrictChooseMode(true); + + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + addCard(Zone.HAND, playerA, "Flame Slash", 1); + addCard(Zone.HAND, playerA, "Shock", 1); + addCard(Zone.BATTLEFIELD, playerA, "Oathsworn Knight", 1); + addCard(Zone.BATTLEFIELD, playerA, "Polukranos, Unchained", 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Slash", "Oathsworn Knight"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shock", "Polukranos, Unchained"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Oathsworn Knight", 1); + assertPermanentCount(playerA, "Polukranos, Unchained", 1); + assertPowerToughness(playerA, "Oathsworn Knight", 3, 3); // 1 counter removed + assertPowerToughness(playerA, "Polukranos, Unchained", 4, 4); // 2 counters removed + + } + + @Test + public void testMagmaPummeler() { + setStrictChooseMode(true); + + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 8); + addCard(Zone.HAND, playerA, "Magma Pummeler", 1); + addCard(Zone.HAND, playerA, "Shock", 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Magma Pummeler"); + setChoice(playerA, "X=5"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shock", "Magma Pummeler"); + addTarget(playerA, playerB); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Magma Pummeler", 1); + assertPowerToughness(playerA, "Magma Pummeler", 3, 3); // 2 counters removed + assertLife(playerB, 18); // 2 damage dealt + + } + + @Test + public void testProteanHydraBoosted() { + setStrictChooseMode(true); + + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Zone.BATTLEFIELD, playerA, "Glorious Anthem", 1); + addCard(Zone.HAND, playerA, "Protean Hydra", 1); + addCard(Zone.HAND, playerA, "Hornet Sting", 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Protean Hydra"); + setChoice(playerA, "X=0"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Hornet Sting", "Protean Hydra"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Protean Hydra", 1); + assertPowerToughness(playerA, "Protean Hydra", 1, 1); + + } + +} diff --git a/Mage/src/main/java/mage/abilities/effects/PreventDamageAndRemoveCountersEffect.java b/Mage/src/main/java/mage/abilities/effects/PreventDamageAndRemoveCountersEffect.java index 14410862e8..2a08854556 100644 --- a/Mage/src/main/java/mage/abilities/effects/PreventDamageAndRemoveCountersEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/PreventDamageAndRemoveCountersEffect.java @@ -12,17 +12,23 @@ import mage.game.permanent.Permanent; */ public class PreventDamageAndRemoveCountersEffect extends PreventionEffectImpl { private final boolean thatMany; + private final boolean whileHasCounter; - public PreventDamageAndRemoveCountersEffect(boolean thatMany) { + public PreventDamageAndRemoveCountersEffect(boolean thatMany, boolean whileHasCounter, boolean textFromIt) { super(Duration.WhileOnBattlefield, Integer.MAX_VALUE, false, false); this.thatMany = thatMany; - staticText = "If damage would be dealt to {this} while it has a +1/+1 counter on it, " + - "prevent that damage and remove " + (thatMany ? "that many +1/+1 counters" : "a +1/+1 counter") + " from it"; + this.whileHasCounter = whileHasCounter; + staticText = "If damage would be dealt to {this}" + + (whileHasCounter ? " while it has a +1/+1 counter on it" : "") + + ", prevent that damage and remove " + + (thatMany ? "that many +1/+1 counters" : "a +1/+1 counter") + + " from " + (textFromIt ? "it" : "{this}"); } - private PreventDamageAndRemoveCountersEffect(final PreventDamageAndRemoveCountersEffect effect) { + protected PreventDamageAndRemoveCountersEffect(final PreventDamageAndRemoveCountersEffect effect) { super(effect); this.thatMany = effect.thatMany; + this.whileHasCounter = effect.whileHasCounter; } @Override @@ -56,6 +62,6 @@ public class PreventDamageAndRemoveCountersEffect extends PreventionEffectImpl { return super.applies(event, source, game) && permanent != null && event.getTargetId().equals(source.getSourceId()) - && permanent.getCounters(game).containsKey(CounterType.P1P1); + && (!whileHasCounter || permanent.getCounters(game).containsKey(CounterType.P1P1)); } }