From e1aa40cbf71cd72220269194282367dbb7200835 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 29 May 2018 12:31:11 -0400 Subject: [PATCH] Fixed counter replacement effects with Doubling Season and Pir, Imaginative Rascal --- Mage.Sets/src/mage/cards/d/DoublingSeason.java | 3 +++ .../src/mage/cards/p/PirImaginativeRascal.java | 6 ++---- .../abilities/costs/common/PayLoyaltyCost.java | 14 ++++++++------ .../costs/common/PutCountersSourceCost.java | 2 +- Mage/src/main/java/mage/cards/Card.java | 4 ++++ Mage/src/main/java/mage/cards/CardImpl.java | 13 ++++++++++++- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Mage.Sets/src/mage/cards/d/DoublingSeason.java b/Mage.Sets/src/mage/cards/d/DoublingSeason.java index 41b0edb0831..db9bab2ee9b 100644 --- a/Mage.Sets/src/mage/cards/d/DoublingSeason.java +++ b/Mage.Sets/src/mage/cards/d/DoublingSeason.java @@ -96,6 +96,9 @@ class DoublingSeasonCounterEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { Permanent permanent = game.getPermanent(event.getTargetId()); + if (!event.getFlag()) { + return false; + } if (permanent == null) { permanent = game.getPermanentEntering(event.getTargetId()); landPlayed = (permanent != null diff --git a/Mage.Sets/src/mage/cards/p/PirImaginativeRascal.java b/Mage.Sets/src/mage/cards/p/PirImaginativeRascal.java index d73a79cb378..a1ad3ba6cf2 100644 --- a/Mage.Sets/src/mage/cards/p/PirImaginativeRascal.java +++ b/Mage.Sets/src/mage/cards/p/PirImaginativeRascal.java @@ -110,10 +110,8 @@ class PirImaginativeRascalEffect extends ReplacementEffectImpl { if (permanent == null) { permanent = game.getPermanentEntering(event.getTargetId()); } - if (permanent != null && player != null && !player.hasOpponent(permanent.getControllerId(), game)) { - return true; - } - return false; + return permanent != null && player != null + && !player.hasOpponent(permanent.getControllerId(), game); } @Override diff --git a/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java b/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java index 20b7f4d2124..4450a58a7fa 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java @@ -64,17 +64,19 @@ public class PayLoyaltyCost extends CostImpl { } /** - * Gatherer Ruling: - * 10/1/2005: Planeswalkers will enter the battlefield with double the normal amount of loyalty counters. However, - * if you activate an ability whose cost has you put loyalty counters on a planeswalker, the number you put on isn’t doubled. - * This is because those counters are put on as a cost, not as an effect. - **/ + * Gatherer Ruling: 10/1/2005: Planeswalkers will enter the battlefield with + * double the normal amount of loyalty counters. However, if you activate an + * ability whose cost has you put loyalty counters on a planeswalker, the + * number you put on isn’t doubled. This is because those counters are put + * on as a cost, not as an effect. + * + */ @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { Permanent planeswalker = game.getPermanent(sourceId); if (planeswalker != null && planeswalker.getCounters(game).getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) { if (amount > 0) { - planeswalker.getCounters(game).addCounter(CounterType.LOYALTY.createInstance(amount)); + planeswalker.addCounters(CounterType.LOYALTY.createInstance(amount), ability, game, false); } else if (amount < 0) { planeswalker.removeCounters(CounterType.LOYALTY.getName(), Math.abs(amount), game); } diff --git a/Mage/src/main/java/mage/abilities/costs/common/PutCountersSourceCost.java b/Mage/src/main/java/mage/abilities/costs/common/PutCountersSourceCost.java index a4bc5d6cb49..1508253a4ab 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/PutCountersSourceCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/PutCountersSourceCost.java @@ -72,7 +72,7 @@ public class PutCountersSourceCost extends CostImpl { public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { Permanent permanent = game.getPermanent(sourceId); if (permanent != null) { - this.paid = permanent.addCounters(counter, ability, game); + this.paid = permanent.addCounters(counter, ability, game, false); } return paid; } diff --git a/Mage/src/main/java/mage/cards/Card.java b/Mage/src/main/java/mage/cards/Card.java index 4398096c06a..470915a13ae 100644 --- a/Mage/src/main/java/mage/cards/Card.java +++ b/Mage/src/main/java/mage/cards/Card.java @@ -161,8 +161,12 @@ public interface Card extends MageObject { boolean addCounters(Counter counter, Ability source, Game game); + boolean addCounters(Counter counter, Ability source, Game game, boolean isEffect); + boolean addCounters(Counter counter, Ability source, Game game, List appliedEffects); + boolean addCounters(Counter counter, Ability source, Game game, List appliedEffects, boolean isEffect); + void removeCounters(String name, int amount, Game game); void removeCounters(Counter counter, Game game); diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index 57c4c9427d6..ae0919fb90a 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -789,15 +789,26 @@ public abstract class CardImpl extends MageObjectImpl implements Card { @Override public boolean addCounters(Counter counter, Ability source, Game game) { - return addCounters(counter, source, game, null); + return addCounters(counter, source, game, null, true); + } + + @Override + public boolean addCounters(Counter counter, Ability source, Game game, boolean isEffect) { + return addCounters(counter, source, game, null, isEffect); } @Override public boolean addCounters(Counter counter, Ability source, Game game, List appliedEffects) { + return addCounters(counter, source, game, appliedEffects, true); + } + + @Override + public boolean addCounters(Counter counter, Ability source, Game game, List appliedEffects, boolean isEffect) { boolean returnCode = true; UUID sourceId = (source == null ? getId() : source.getSourceId()); GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, sourceId, getControllerOrOwner(), counter.getName(), counter.getCount()); countersEvent.setAppliedEffects(appliedEffects); + countersEvent.setFlag(isEffect); if (!game.replaceEvent(countersEvent)) { int amount = countersEvent.getAmount(); int finalAmount = amount;