From 18064114e01677f95b3ab96272a3681ee11d0d29 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Fri, 12 Aug 2011 10:09:41 -0400 Subject: [PATCH] added events for adding counters --- .../src/mage/sets/magic2010/ProteanHydra.java | 5 ++--- .../mage/sets/magic2011/PhylacteryLich.java | 3 +-- .../mirrodinbesieged/BlackSunsZenith.java | 2 +- .../mage/sets/newphyrexia/GlisteningOil.java | 2 +- .../sets/scarsofmirrodin/CarnifexDemon.java | 2 +- .../sets/scarsofmirrodin/ChimericMass.java | 2 +- .../sets/scarsofmirrodin/ContagionEngine.java | 2 +- .../shardsofalara/SigilOfDistinction.java | 2 +- .../sets/zendikar/OranRiefTheVastwood.java | 3 ++- .../common/counter/AddCountersAllEffect.java | 2 +- .../counter/AddCountersSourceEffect.java | 2 +- .../counter/AddCountersTargetEffect.java | 2 +- .../AddPlusOneCountersAttachedEffect.java | 2 +- .../common/counter/ProliferateEffect.java | 4 ++-- .../abilities/keyword/BloodthirstAbility.java | 2 +- Mage/src/mage/game/events/GameEvent.java | 1 + Mage/src/mage/game/permanent/Permanent.java | 5 +++-- .../mage/game/permanent/PermanentImpl.java | 21 ++++++++++++++----- 18 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java b/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java index a028239832..4f7b98ef44 100644 --- a/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java +++ b/Mage.Sets/src/mage/sets/magic2010/ProteanHydra.java @@ -46,7 +46,6 @@ import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.cards.CardImpl; import mage.counters.CounterType; -import mage.counters.common.PlusOneCounter; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; @@ -96,7 +95,7 @@ public class ProteanHydra extends CardImpl { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null && source.getManaCostsToPay().getVariableCosts().size() > 0) { int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); - permanent.addCounters(new PlusOneCounter(amount)); + permanent.addCounters(CounterType.P1P1.createInstance(amount), game); } return true; } @@ -141,7 +140,7 @@ public class ProteanHydra extends CardImpl { } Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { - permanent.removeCounters("+1/+1", damage, game); + permanent.removeCounters(CounterType.P1P1.createInstance(damage), game); } return retValue; } diff --git a/Mage.Sets/src/mage/sets/magic2011/PhylacteryLich.java b/Mage.Sets/src/mage/sets/magic2011/PhylacteryLich.java index c2f4293cfd..6e7473505d 100644 --- a/Mage.Sets/src/mage/sets/magic2011/PhylacteryLich.java +++ b/Mage.Sets/src/mage/sets/magic2011/PhylacteryLich.java @@ -48,7 +48,6 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.target.TargetPermanent; import mage.target.common.TargetControlledPermanent; /** @@ -140,7 +139,7 @@ class PhylacteryLichEffect extends OneShotEffect { if (player.choose(Outcome.Neutral, target, game)) { Permanent permanent = game.getPermanent(target.getFirstTarget()); if (permanent != null) { - permanent.addCounters(new Counter("phylactery")); + permanent.addCounters(new Counter("phylactery"), game); } } } diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java index 67792708f2..21f1f91694 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/BlackSunsZenith.java @@ -81,7 +81,7 @@ class BlackSunsZenithEffect extends OneShotEffect { int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { - permanent.addCounters(CounterType.M1M1.createInstance(amount)); + permanent.addCounters(CounterType.M1M1.createInstance(amount), game); } } return true; diff --git a/Mage.Sets/src/mage/sets/newphyrexia/GlisteningOil.java b/Mage.Sets/src/mage/sets/newphyrexia/GlisteningOil.java index be304a59f5..333c4f40ff 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/GlisteningOil.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/GlisteningOil.java @@ -96,7 +96,7 @@ class GlisteningOilEffect extends OneShotEffect { if (enchantment != null && enchantment.getAttachedTo() != null) { Permanent creature = game.getPermanent(enchantment.getAttachedTo()); if (creature != null) { - creature.addCounters(CounterType.M1M1.createInstance()); + creature.addCounters(CounterType.M1M1.createInstance(), game); } } return true; diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/CarnifexDemon.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/CarnifexDemon.java index d796a04911..4200bf407f 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/CarnifexDemon.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/CarnifexDemon.java @@ -94,7 +94,7 @@ class CarnifexDemonEffect extends OneShotEffect { if (p != null) { for (Permanent t : game.getBattlefield().getAllActivePermanents()) { if (t.getCardType().contains(CardType.CREATURE) && !t.getId().equals(source.getSourceId())) - t.addCounters(CounterType.M1M1.createInstance()); + t.addCounters(CounterType.M1M1.createInstance(), game); } } return false; diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/ChimericMass.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/ChimericMass.java index 010afe155a..aec0306010 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/ChimericMass.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/ChimericMass.java @@ -94,7 +94,7 @@ class ChimericMassEffect extends OneShotEffect { int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { - p.addCounters(CounterType.CHARGE.createInstance(amount)); + p.addCounters(CounterType.CHARGE.createInstance(amount), game); return true; } return true; diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/ContagionEngine.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/ContagionEngine.java index 76254d4a84..a65ce3156c 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/ContagionEngine.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/ContagionEngine.java @@ -92,7 +92,7 @@ class ContagionEngineEffect extends OneShotEffect { Player target = game.getPlayer(source.getFirstTarget()); if (target != null) { for (Permanent p : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), target.getId())) { - p.getCounters().addCounter(CounterType.M1M1.createInstance()); + p.addCounters(CounterType.M1M1.createInstance(), game); } return true; } diff --git a/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java b/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java index 4b71321c7f..a256f68adc 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/SigilOfDistinction.java @@ -87,7 +87,7 @@ class SigilOfDistinctionEffect extends OneShotEffect { int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { - p.addCounters(CounterType.CHARGE.createInstance(amount)); + p.addCounters(CounterType.CHARGE.createInstance(amount), game); return true; } return true; diff --git a/Mage.Sets/src/mage/sets/zendikar/OranRiefTheVastwood.java b/Mage.Sets/src/mage/sets/zendikar/OranRiefTheVastwood.java index 89315170b9..7cf8dbb4bc 100644 --- a/Mage.Sets/src/mage/sets/zendikar/OranRiefTheVastwood.java +++ b/Mage.Sets/src/mage/sets/zendikar/OranRiefTheVastwood.java @@ -40,6 +40,7 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.OneShotEffect; import mage.abilities.mana.GreenManaAbility; import mage.cards.CardImpl; +import mage.counters.CounterType; import mage.counters.common.PlusOneCounter; import mage.filter.Filter; import mage.filter.FilterPermanent; @@ -96,7 +97,7 @@ class OranRiefTheVastwoodEffect extends OneShotEffect filter.setUseColor(true); for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { if (permanent.getTurnsOnBattlefield() == 0) { - permanent.addCounters(new PlusOneCounter()); + permanent.addCounters(CounterType.P1P1.createInstance(), game); } } return true; diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java index 26fd94dec7..53c2a627c4 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersAllEffect.java @@ -67,7 +67,7 @@ public class AddCountersAllEffect extends OneShotEffect { List permanents = game.getBattlefield().getAllActivePermanents(); for (Permanent permanent : permanents) { if (filter.match(permanent, source.getSourceId(), controllerId, game)) { - permanent.addCounters(counter.copy()); + permanent.addCounters(counter.copy(), game); applied = true; } } diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java index 6dd88a4a84..cc6b3a96c9 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java @@ -59,7 +59,7 @@ public class AddCountersSourceEffect extends OneShotEffect { if (permanent.getCounters().size() > 0) { if (permanent.getCounters().size() == 1) { for (Counter counter : permanent.getCounters().values()) { - permanent.getCounters().addCounter(counter.getName(), 1); + permanent.addCounters(counter.getName(), 1, game); } } else { Choice choice = new ChoiceImpl(true); @@ -93,7 +93,7 @@ public class ProliferateEffect extends OneShotEffect { controller.choose(Outcome.Benefit, choice, game); for (Counter counter : permanent.getCounters().values()) { if (counter.getName().equals(choice.getChoice())) { - permanent.getCounters().addCounter(counter.getName(), 1); + permanent.addCounters(counter.getName(), 1, game); break; } } diff --git a/Mage/src/mage/abilities/keyword/BloodthirstAbility.java b/Mage/src/mage/abilities/keyword/BloodthirstAbility.java index b60e7f4266..153cc1047c 100644 --- a/Mage/src/mage/abilities/keyword/BloodthirstAbility.java +++ b/Mage/src/mage/abilities/keyword/BloodthirstAbility.java @@ -56,7 +56,7 @@ class BloodthirstEffect extends OneShotEffect { if (watcher.conditionMet()) { Permanent p = game.getPermanent(source.getSourceId()); if (p != null) { - p.addCounters(CounterType.P1P1.createInstance(amount)); + p.addCounters(CounterType.P1P1.createInstance(amount), game); } } return false; diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index f5439c8492..5f7555b7f7 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -110,6 +110,7 @@ public class GameEvent { SACRIFICE_PERMANENT, SACRIFICED_PERMANENT, ATTACH, ATTACHED, UNATTACH, UNATTACHED, + ADD_COUNTER, COUNTER_ADDED, COUNTER_REMOVED, LOSE_CONTROL, LOST_CONTROL, GAIN_CONTROL, GAINED_CONTROL, diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 3884da8906..d984297a85 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -77,9 +77,10 @@ public interface Permanent extends Card { public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat); public void removeAllDamage(Game game); public Counters getCounters(); - public void addCounters(String name, int amount); - public void addCounters(Counter counter); + public void addCounters(String name, int amount, Game game); + public void addCounters(Counter counter, Game game); public void removeCounters(String name, int amount, Game game); + public void removeCounters(Counter counter, Game game); public void reset(Game game); public boolean destroy(UUID sourceId, Game game, boolean noRegen); public boolean sacrifice(UUID sourceId, Game game); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index 77a7182965..0a16d0a2df 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -157,13 +157,19 @@ public abstract class PermanentImpl> extends CardImpl } @Override - public void addCounters(String name, int amount) { - counters.addCounter(name, amount); + public void addCounters(String name, int amount, Game game) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId))) { + counters.addCounter(name, amount); + game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId)); + } } @Override - public void addCounters(Counter counter) { - counters.addCounter(counter); + public void addCounters(Counter counter, Game game) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId))) { + counters.addCounter(counter); + game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId)); + } } @Override @@ -175,6 +181,11 @@ public abstract class PermanentImpl> extends CardImpl game.fireEvent(event); } + @Override + public void removeCounters(Counter counter, Game game) { + removeCounters(counter.getName(), counter.getCount(), game); + } + @Override public int getTurnsOnBattlefield() { return turnsOnBattlefield; @@ -533,7 +544,7 @@ public abstract class PermanentImpl> extends CardImpl Permanent source = game.getPermanent(sourceId); if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId()) || source.getAbilities().containsKey(WitherAbility.getInstance().getId()))) { - addCounters(CounterType.M1M1.createInstance(actualDamage)); + addCounters(CounterType.M1M1.createInstance(actualDamage), game); } else { this.damage += actualDamage; }