diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 6d80ffdf790..da155315244 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -1382,6 +1382,21 @@ public class Card extends GameEntity implements Comparable { public final boolean hasSecondStrike() { return this.hasDoubleStrike() || !this.hasFirstStrike(); } + + public final boolean canHaveCountersPlacedOnIt(final Counters counterName) { + if (this.hasKeyword("CARDNAME can't have counters placed on it.")) { + return false; + } + if (counterName.equals(Counters.M1M1)) { + for (Card c: AllZoneUtil.getCreaturesInPlay(this.getController())) {//look for Melira, Sylvok Outcast + if (c.hasKeyword("Creatures you control can't have -1/-1 counters placed on them.")) { + return false; + } + } + + } + return true; + } // for costs (like Planeswalker abilities) Doubling Season gets ignored. /** @@ -1395,17 +1410,9 @@ public class Card extends GameEntity implements Comparable { * a int. */ public final void addCounterFromNonEffect(final Counters counterName, final int n) { - if (this.hasKeyword("CARDNAME can't have counters placed on it.")) { + if (!canHaveCountersPlacedOnIt(counterName)) { return; } - if (counterName.equals(Counters.M1M1)) { - for (Card c: AllZoneUtil.getCreaturesInPlay(this.getController())) {//look for Melira, Sylvok Outcast - if (c.hasKeyword("Creatures you control can't have -1/-1 counters placed on them.")) { - return; - } - } - - } if (this.counters.containsKey(counterName)) { final Integer aux = this.counters.get(counterName) + n; this.counters.put(counterName, aux); @@ -1440,18 +1447,6 @@ public class Card extends GameEntity implements Comparable { } } - // /////////////// - // - // Not sure if we want to fire triggers on addCounterFromNonEffect - // I don't think so since reverting cost payments uses this. - - /* - * //Run triggers HashMap runParams = new - * HashMap(); runParams.put("Card", this); - * runParams.put("CounterType", counterName); - * AllZone.getTriggerHandler().runTrigger("CounterAdded", runParams); - */ - this.updateObservers(); } @@ -1466,17 +1461,9 @@ public class Card extends GameEntity implements Comparable { * a int. */ public final void addCounter(final Counters counterName, final int n) { - if (this.hasKeyword("CARDNAME can't have counters placed on it.")) { + if (!canHaveCountersPlacedOnIt(counterName)) { return; } - if (counterName.equals(Counters.M1M1)) { - for (Card c: AllZoneUtil.getCreaturesInPlay(this.getController())) {//look for Melira, Sylvok Outcast - if (c.hasKeyword("Creatures you control can't have -1/-1 counters placed on them.")) { - return; - } - } - - } final int multiplier = AllZoneUtil.getDoublingSeasonMagnitude(this.getController()); if (this.counters.containsKey(counterName)) { final Integer aux = this.counters.get(counterName) + (multiplier * n); @@ -1635,17 +1622,9 @@ public class Card extends GameEntity implements Comparable { * a boolean. */ public final void setCounter(final Counters counterName, final int n, final boolean bSetValue) { - if (this.hasKeyword("CARDNAME can't have counters placed on it.")) { + if (!canHaveCountersPlacedOnIt(counterName)) { return; } - if (counterName.equals(Counters.M1M1)) { - for (Card c: AllZoneUtil.getCreaturesInPlay(this.getController())) {//look for Melira, Sylvok Outcast - if (c.hasKeyword("Creatures you control can't have -1/-1 counters placed on them.")) { - return; - } - } - - } // sometimes you just need to set the value without being affected by // DoublingSeason if (bSetValue) { diff --git a/src/main/java/forge/CombatUtil.java b/src/main/java/forge/CombatUtil.java index 6ede1f54b38..d5df2e1bc28 100644 --- a/src/main/java/forge/CombatUtil.java +++ b/src/main/java/forge/CombatUtil.java @@ -1724,8 +1724,9 @@ public class CombatUtil { } } // flanking - if ((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) - && !(defender.hasKeyword("Wither") || defender.hasKeyword("Infect"))) { + if (((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) + && !(defender.hasKeyword("Wither") || defender.hasKeyword("Infect"))) + || (attacker.hasKeyword("Persist") && !attacker.canHaveCountersPlacedOnIt(Counters.M1M1))) { return false; } @@ -1854,8 +1855,9 @@ public class CombatUtil { } } // flanking - if ((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) - && !(attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect"))) { + if (((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) + && !(attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect"))) + || (defender.hasKeyword("Persist") && !defender.canHaveCountersPlacedOnIt(Counters.M1M1))){ return false; }