Fix counter placement sound playing repeatedly.

This commit is contained in:
elcnesh
2014-09-29 09:08:45 +00:00
parent 97a46fae15
commit 9ce50662fe
2 changed files with 23 additions and 13 deletions

View File

@@ -758,7 +758,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
pumped.addChangedCardKeywords(kws, new ArrayList<String>(), false, timestamp);
Set<CounterType> types = c.getCounters().keySet();
for(CounterType ct : types) {
pumped.addCounter(ct, c.getCounters(ct), true);
pumped.addCounterFireNoEvents(ct, c.getCounters(ct), true);
}
//Copies tap-state and extra keywords (auras, equipment, etc.)
if (c.isTapped()) {

View File

@@ -1194,6 +1194,13 @@ public class Card extends GameEntity implements Comparable<Card>, IIdentifiable
}
public final void addCounter(final CounterType counterType, final int n, final boolean applyMultiplier) {
this.addCounter(counterType, n, applyMultiplier, true);
}
public final void addCounterFireNoEvents(final CounterType counterType, final int n, final boolean applyMultiplier) {
this.addCounter(counterType, n, applyMultiplier, false);
}
private void addCounter(final CounterType counterType, final int n, final boolean applyMultiplier, final boolean fireEvents) {
int addAmount = n;
final HashMap<String, Object> repParams = new HashMap<String, Object>();
repParams.put("Event", "AddCounter");
@@ -1218,22 +1225,25 @@ public class Card extends GameEntity implements Comparable<Card>, IIdentifiable
}
this.setTotalCountersToAdd(addAmount);
int powerBonusBefore = this.getPowerBonusFromCounters();
int toughnessBonusBefore = this.getToughnessBonusFromCounters();
int loyaltyBefore = this.getCurrentLoyalty();
if (fireEvents) {
final int powerBonusBefore = this.getPowerBonusFromCounters();
final int toughnessBonusBefore = this.getToughnessBonusFromCounters();
final int loyaltyBefore = this.getCurrentLoyalty();
Integer oldValue = this.counters.get(counterType);
int newValue = addAmount + (oldValue == null ? 0 : oldValue.intValue());
this.counters.put(counterType, Integer.valueOf(newValue));
final Integer oldValue = this.counters.get(counterType);
final int newValue = addAmount + (oldValue == null ? 0 : oldValue.intValue());
this.counters.put(counterType, Integer.valueOf(newValue));
//fire card stats changed event if p/t bonuses or loyalty changed from added counters
if (powerBonusBefore != getPowerBonusFromCounters() || toughnessBonusBefore != getToughnessBonusFromCounters() || loyaltyBefore != getCurrentLoyalty()) {
getGame().fireEvent(new GameEventCardStatsChanged(this));
//fire card stats changed event if p/t bonuses or loyalty changed from added counters
if (powerBonusBefore != getPowerBonusFromCounters() || toughnessBonusBefore != getToughnessBonusFromCounters() || loyaltyBefore != getCurrentLoyalty()) {
getGame().fireEvent(new GameEventCardStatsChanged(this));
}
// play the Add Counter sound
getGame().fireEvent(new GameEventCardCounters(this, counterType, oldValue == null ? 0 : oldValue.intValue(), newValue));
}
// play the Add Counter sound
getGame().fireEvent(new GameEventCardCounters(this, counterType, oldValue == null ? 0 : oldValue.intValue(), newValue));
// Run triggers
final Map<String, Object> runParams = new TreeMap<String, Object>();
runParams.put("Card", this);