From 452794bf1e0bd460a4c5f02e6590f10f98087572 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 4 Jan 2013 15:04:31 +0100 Subject: [PATCH] Moved methods and attributes concerning counters from Permanent to Card (to support e.g. suspend in the future). --- Mage/src/mage/cards/Card.java | 11 ++++ Mage/src/mage/cards/CardImpl.java | 58 +++++++++++++++++++ Mage/src/mage/game/permanent/Permanent.java | 8 --- .../mage/game/permanent/PermanentImpl.java | 33 ++--------- 4 files changed, 73 insertions(+), 37 deletions(-) diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java index 4a89c5cfc2..9c63810719 100644 --- a/Mage/src/mage/cards/Card.java +++ b/Mage/src/mage/cards/Card.java @@ -37,6 +37,8 @@ import mage.MageObject; import mage.Mana; import mage.abilities.Ability; import mage.abilities.SpellAbility; +import mage.counters.Counter; +import mage.counters.Counters; import mage.game.Game; import mage.watchers.Watcher; @@ -113,6 +115,15 @@ public interface Card extends MageObject { * @return true if there exists various art images for this card */ boolean getUsesVariousArt(); + Counters getCounters(); + + void addCounters(String name, int amount, Game game); + void addCounters(String name, int amount, Game game, ArrayList appliedEffects); + void addCounters(Counter counter, Game game); + void addCounters(Counter counter, Game game, ArrayList appliedEffects); + + void removeCounters(String name, int amount, Game game); + void removeCounters(Counter counter, Game game); @Override Card copy(); diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index f1b2f7c8b7..e4dd11122d 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -39,7 +39,10 @@ import mage.abilities.Ability; import mage.abilities.PlayLandAbility; import mage.abilities.SpellAbility; import mage.abilities.mana.ManaAbility; +import mage.counters.Counter; +import mage.counters.Counters; import mage.game.Game; +import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.PermanentCard; import mage.game.stack.Spell; @@ -66,6 +69,7 @@ public abstract class CardImpl> extends MageObjectImpl protected int zoneChangeCounter = 1; protected Map info; protected boolean usesVariousArt = false; + protected Counters counters; public CardImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) { this(ownerId, name); @@ -80,17 +84,20 @@ public abstract class CardImpl> extends MageObjectImpl addAbility(new SpellAbility(manaCost, name)); } this.usesVariousArt = Character.isDigit(this.getClass().getName().charAt(this.getClass().getName().length()-1)); + this.counters = new Counters(); } protected CardImpl(UUID ownerId, String name) { this.ownerId = ownerId; this.name = name; + this.counters = new Counters(); } protected CardImpl(UUID id, UUID ownerId, String name) { super(id); this.ownerId = ownerId; this.name = name; + this.counters = new Counters(); } public CardImpl(final CardImpl card) { @@ -115,6 +122,7 @@ public abstract class CardImpl> extends MageObjectImpl info.putAll(card.info); } usesVariousArt = card.usesVariousArt; + this.counters = card.counters.copy(); } @Override @@ -511,4 +519,54 @@ public abstract class CardImpl> extends MageObjectImpl public boolean getUsesVariousArt() { return usesVariousArt; } + + @Override + public Counters getCounters() { + return counters; + } + + @Override + public void addCounters(String name, int amount, Game game) { + addCounters(name, amount, game, null); + } + + @Override + public void addCounters(String name, int amount, Game game, ArrayList appliedEffects) { + GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, ownerId, name, amount); + event.setAppliedEffects(appliedEffects); + if (!game.replaceEvent(event)) { + counters.addCounter(name, amount); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, ownerId, name, amount)); + } + } + + @Override + public void addCounters(Counter counter, Game game) { + addCounters(counter, game, null); + } + + @Override + public void addCounters(Counter counter, Game game, ArrayList appliedEffects) { + GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, ownerId, counter.getName(), counter.getCount()); + event.setAppliedEffects(appliedEffects); + if (!game.replaceEvent(event)) { + counters.addCounter(counter); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, ownerId, counter.getName(), counter.getCount())); + } + } + + @Override + public void removeCounters(String name, int amount, Game game) { + counters.removeCounter(name, amount); + GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTER_REMOVED, objectId, ownerId); + event.setData(name); + for (int i = 0; i < amount; i++) { + game.fireEvent(event); + } + } + + @Override + public void removeCounters(Counter counter, Game game) { + removeCounters(counter.getName(), counter.getCount(), game); + } } diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 65563463fc..e45350ffa6 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -102,15 +102,7 @@ public interface Permanent extends Card, Controllable { int applyDamage(Game game); void removeAllDamage(Game game); - Counters getCounters(); - void addCounters(String name, int amount, Game game); - void addCounters(String name, int amount, Game game, ArrayList appliedEffects); - void addCounters(Counter counter, Game game); - void addCounters(Counter counter, Game game, ArrayList appliedEffects); - - void removeCounters(String name, int amount, Game game); - void removeCounters(Counter counter, Game game); void reset(Game game); boolean destroy(UUID sourceId, Game game, boolean noRegen); 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 c2f244e9b0..2c9a8e4b8e 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -90,7 +90,6 @@ public abstract class PermanentImpl> extends CardImpl protected int minBlockedBy = 1; protected boolean loyaltyUsed; protected boolean deathtouched; - protected Counters counters; protected List attachments = new ArrayList(); protected Map> connectedCards = new HashMap>(); protected List dealtDamageByThisTurn; @@ -104,14 +103,12 @@ public abstract class PermanentImpl> extends CardImpl super(ownerId, name); this.originalControllerId = controllerId; this.controllerId = controllerId; - this.counters = new Counters(); } public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) { super(id, ownerId, name); this.originalControllerId = controllerId; this.controllerId = controllerId; - this.counters = new Counters(); } public PermanentImpl(final PermanentImpl permanent) { @@ -130,7 +127,6 @@ public abstract class PermanentImpl> extends CardImpl this.maxBlocks = permanent.maxBlocks; this.loyaltyUsed = permanent.loyaltyUsed; this.deathtouched = permanent.deathtouched; - this.counters = permanent.counters.copy(); this.attachments.addAll(permanent.attachments); for (Map.Entry> entry: permanent.connectedCards.entrySet()) { this.connectedCards.put(entry.getKey(), entry.getValue()); @@ -182,7 +178,7 @@ public abstract class PermanentImpl> extends CardImpl sb.append(controllerId).append(name).append(tapped).append(damage); sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue()); sb.append(abilities.getValue()); - for (Counter counter : counters.values()) { + for (Counter counter : getCounters().values()) { sb.append(counter.getName()).append(counter.getCount()); } return sb.toString(); @@ -223,56 +219,35 @@ public abstract class PermanentImpl> extends CardImpl game.resetForSourceId(this.getId()); } - @Override - public Counters getCounters() { - return counters; - } - - @Override - public void addCounters(String name, int amount, Game game) { - addCounters(name, amount, game, null); - } - @Override public void addCounters(String name, int amount, Game game, ArrayList appliedEffects) { GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, name, amount); event.setAppliedEffects(appliedEffects); if (!game.replaceEvent(event)) { counters.addCounter(name, amount); - game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId, name, amount)); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, controllerId, name, amount)); } } - @Override - public void addCounters(Counter counter, Game game) { - addCounters(counter, game, null); - } - @Override public void addCounters(Counter counter, Game game, ArrayList appliedEffects) { GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, counter.getName(), counter.getCount()); event.setAppliedEffects(appliedEffects); if (!game.replaceEvent(event)) { counters.addCounter(counter); - game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId, counter.getName(), counter.getCount())); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, controllerId, counter.getName(), counter.getCount())); } } @Override public void removeCounters(String name, int amount, Game game) { counters.removeCounter(name, amount); - GameEvent event = GameEvent.getEvent(EventType.COUNTER_REMOVED, objectId, controllerId); + GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTER_REMOVED, objectId, controllerId); event.setData(name); for (int i = 0; i < amount; i++) { game.fireEvent(event); } } - - @Override - public void removeCounters(Counter counter, Game game) { - removeCounters(counter.getName(), counter.getCount(), game); - } - @Override public int getTurnsOnBattlefield() { return turnsOnBattlefield;