From f60eb218eab8fe5c4d2a2f1b548534f2e337029b Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 08:13:27 +0000 Subject: [PATCH] - +1/+1 and -1/-1 Counters will now remove each other when added to a card that already has the other type of Counter. --- src/forge/Card.java | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/forge/Card.java b/src/forge/Card.java index edeea9ef9f4..188b5a3f7ed 100644 --- a/src/forge/Card.java +++ b/src/forge/Card.java @@ -345,13 +345,40 @@ public class Card extends MyObservable { int multiplier = 1; int doublingSeasons = CardFactoryUtil.getCards("Doubling Season", this.getController()).size(); if(doublingSeasons > 0) multiplier = (int) Math.pow(2, doublingSeasons); - + if(counters.containsKey(counterName)) { Integer aux = counters.get(counterName) + (multiplier * n); counters.put(counterName, aux); } else { counters.put(counterName, Integer.valueOf(multiplier * n)); } + + if (counterName.equals(Counters.P1P1) || counterName.equals(Counters.M1M1)){ + // +1/+1 counters should erase -1/-1 counters + int plusOneCounters = 0; + int minusOneCounters = 0; + + Counters p1Counter = Counters.P1P1; + Counters m1Counter = Counters.M1M1; + if (counters.containsKey(p1Counter)) + plusOneCounters = counters.get(p1Counter); + if (counters.containsKey(m1Counter)) + minusOneCounters = counters.get(m1Counter); + + if (plusOneCounters == minusOneCounters){ + counters.remove(m1Counter); + counters.remove(p1Counter); + } + if (plusOneCounters > minusOneCounters){ + counters.remove(m1Counter); + counters.put(p1Counter, (Integer)(plusOneCounters - minusOneCounters)); + } + else{ + counters.put(m1Counter, (Integer)(minusOneCounters - plusOneCounters)); + counters.remove(p1Counter); + } + } + this.updateObservers(); }