Implemented Rule 704.5r - If a permanent has both a +1/+1 counter and a -1/-1 counter on it, N +1/+1 and N -1/-1 counters are removed from it, where N is the smaller of the number of +1/+1 and -1/-1 counters on it.

This commit is contained in:
magenoxx 2011-05-15 15:35:36 +04:00
parent 7c608b8b91
commit 13497ec651
2 changed files with 20 additions and 0 deletions

View file

@ -75,6 +75,12 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
this.get(name).remove();
}
public void removeCounter(CounterType counterType, int amount) {
if (this.containsKey(counterType.getName())) {
get(counterType.getName()).remove(amount);
}
}
public void removeCounter(String name, int amount) {
if (this.containsKey(name))
this.get(name).remove(amount);
@ -86,6 +92,10 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
return 0;
}
public boolean containsKey(CounterType counterType) {
return getCount(counterType) > 0;
}
public int getCount(CounterType type) {
if (this.containsKey(type.getName()))
return this.get(type.getName()).getCount();

View file

@ -725,6 +725,16 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
}
}
}
//20110501 - 704.5r
for (Permanent perm: getBattlefield().getAllActivePermanents()) {
if (perm.getCounters().containsKey(CounterType.P1P1) && perm.getCounters().containsKey(CounterType.M1M1)) {
int p1p1 = perm.getCounters().getCount(CounterType.P1P1);
int m1m1 = perm.getCounters().getCount(CounterType.M1M1);
int min = Math.min(p1p1, m1m1);
perm.getCounters().removeCounter(CounterType.P1P1, min);
perm.getCounters().removeCounter(CounterType.M1M1, min);
}
}
//TODO: implement the rest