Moved methods and attributes concerning counters from Permanent to Card (to support e.g. suspend in the future).

This commit is contained in:
LevelX2 2013-01-04 15:04:31 +01:00
parent 658cbff736
commit 452794bf1e
4 changed files with 73 additions and 37 deletions

View file

@ -37,6 +37,8 @@ import mage.MageObject;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.game.Game; import mage.game.Game;
import mage.watchers.Watcher; import mage.watchers.Watcher;
@ -113,6 +115,15 @@ public interface Card extends MageObject {
* @return true if there exists various art images for this card * @return true if there exists various art images for this card
*/ */
boolean getUsesVariousArt(); boolean getUsesVariousArt();
Counters getCounters();
void addCounters(String name, int amount, Game game);
void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects);
void addCounters(Counter counter, Game game);
void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects);
void removeCounters(String name, int amount, Game game);
void removeCounters(Counter counter, Game game);
@Override @Override
Card copy(); Card copy();

View file

@ -39,7 +39,10 @@ import mage.abilities.Ability;
import mage.abilities.PlayLandAbility; import mage.abilities.PlayLandAbility;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.mana.ManaAbility; import mage.abilities.mana.ManaAbility;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentCard;
import mage.game.stack.Spell; import mage.game.stack.Spell;
@ -66,6 +69,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
protected int zoneChangeCounter = 1; protected int zoneChangeCounter = 1;
protected Map<String, String> info; protected Map<String, String> info;
protected boolean usesVariousArt = false; protected boolean usesVariousArt = false;
protected Counters counters;
public CardImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) { public CardImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) {
this(ownerId, name); this(ownerId, name);
@ -80,17 +84,20 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
addAbility(new SpellAbility(manaCost, name)); addAbility(new SpellAbility(manaCost, name));
} }
this.usesVariousArt = Character.isDigit(this.getClass().getName().charAt(this.getClass().getName().length()-1)); this.usesVariousArt = Character.isDigit(this.getClass().getName().charAt(this.getClass().getName().length()-1));
this.counters = new Counters();
} }
protected CardImpl(UUID ownerId, String name) { protected CardImpl(UUID ownerId, String name) {
this.ownerId = ownerId; this.ownerId = ownerId;
this.name = name; this.name = name;
this.counters = new Counters();
} }
protected CardImpl(UUID id, UUID ownerId, String name) { protected CardImpl(UUID id, UUID ownerId, String name) {
super(id); super(id);
this.ownerId = ownerId; this.ownerId = ownerId;
this.name = name; this.name = name;
this.counters = new Counters();
} }
public CardImpl(final CardImpl card) { public CardImpl(final CardImpl card) {
@ -115,6 +122,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
info.putAll(card.info); info.putAll(card.info);
} }
usesVariousArt = card.usesVariousArt; usesVariousArt = card.usesVariousArt;
this.counters = card.counters.copy();
} }
@Override @Override
@ -511,4 +519,54 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
public boolean getUsesVariousArt() { public boolean getUsesVariousArt() {
return usesVariousArt; 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<UUID> 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<UUID> 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);
}
} }

View file

@ -102,15 +102,7 @@ public interface Permanent extends Card, Controllable {
int applyDamage(Game game); int applyDamage(Game game);
void removeAllDamage(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<UUID> appliedEffects);
void addCounters(Counter counter, Game game);
void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects);
void removeCounters(String name, int amount, Game game);
void removeCounters(Counter counter, Game game);
void reset(Game game); void reset(Game game);
boolean destroy(UUID sourceId, Game game, boolean noRegen); boolean destroy(UUID sourceId, Game game, boolean noRegen);
boolean sacrifice(UUID sourceId, Game game); boolean sacrifice(UUID sourceId, Game game);

View file

@ -90,7 +90,6 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
protected int minBlockedBy = 1; protected int minBlockedBy = 1;
protected boolean loyaltyUsed; protected boolean loyaltyUsed;
protected boolean deathtouched; protected boolean deathtouched;
protected Counters counters;
protected List<UUID> attachments = new ArrayList<UUID>(); protected List<UUID> attachments = new ArrayList<UUID>();
protected Map<String, List<UUID>> connectedCards = new HashMap<String, List<UUID>>(); protected Map<String, List<UUID>> connectedCards = new HashMap<String, List<UUID>>();
protected List<UUID> dealtDamageByThisTurn; protected List<UUID> dealtDamageByThisTurn;
@ -104,14 +103,12 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
super(ownerId, name); super(ownerId, name);
this.originalControllerId = controllerId; this.originalControllerId = controllerId;
this.controllerId = controllerId; this.controllerId = controllerId;
this.counters = new Counters();
} }
public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) { public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) {
super(id, ownerId, name); super(id, ownerId, name);
this.originalControllerId = controllerId; this.originalControllerId = controllerId;
this.controllerId = controllerId; this.controllerId = controllerId;
this.counters = new Counters();
} }
public PermanentImpl(final PermanentImpl<T> permanent) { public PermanentImpl(final PermanentImpl<T> permanent) {
@ -130,7 +127,6 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
this.maxBlocks = permanent.maxBlocks; this.maxBlocks = permanent.maxBlocks;
this.loyaltyUsed = permanent.loyaltyUsed; this.loyaltyUsed = permanent.loyaltyUsed;
this.deathtouched = permanent.deathtouched; this.deathtouched = permanent.deathtouched;
this.counters = permanent.counters.copy();
this.attachments.addAll(permanent.attachments); this.attachments.addAll(permanent.attachments);
for (Map.Entry<String, List<UUID>> entry: permanent.connectedCards.entrySet()) { for (Map.Entry<String, List<UUID>> entry: permanent.connectedCards.entrySet()) {
this.connectedCards.put(entry.getKey(), entry.getValue()); this.connectedCards.put(entry.getKey(), entry.getValue());
@ -182,7 +178,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
sb.append(controllerId).append(name).append(tapped).append(damage); sb.append(controllerId).append(name).append(tapped).append(damage);
sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue()); sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue());
sb.append(abilities.getValue()); sb.append(abilities.getValue());
for (Counter counter : counters.values()) { for (Counter counter : getCounters().values()) {
sb.append(counter.getName()).append(counter.getCount()); sb.append(counter.getName()).append(counter.getCount());
} }
return sb.toString(); return sb.toString();
@ -223,56 +219,35 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
game.resetForSourceId(this.getId()); 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 @Override
public void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) { public void addCounters(String name, int amount, Game game, ArrayList<UUID> appliedEffects) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, name, amount); GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, name, amount);
event.setAppliedEffects(appliedEffects); event.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) { if (!game.replaceEvent(event)) {
counters.addCounter(name, amount); 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 @Override
public void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) { public void addCounters(Counter counter, Game game, ArrayList<UUID> appliedEffects) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, counter.getName(), counter.getCount()); GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, counter.getName(), counter.getCount());
event.setAppliedEffects(appliedEffects); event.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) { if (!game.replaceEvent(event)) {
counters.addCounter(counter); 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 @Override
public void removeCounters(String name, int amount, Game game) { public void removeCounters(String name, int amount, Game game) {
counters.removeCounter(name, amount); 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); event.setData(name);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
game.fireEvent(event); game.fireEvent(event);
} }
} }
@Override
public void removeCounters(Counter counter, Game game) {
removeCounters(counter.getName(), counter.getCount(), game);
}
@Override @Override
public int getTurnsOnBattlefield() { public int getTurnsOnBattlefield() {
return turnsOnBattlefield; return turnsOnBattlefield;