mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
GameEntity: setCounter now removes counterType directly when its not used anymore
Card and Player updated to use that directly instead of doing it on their own
This commit is contained in:
@@ -336,8 +336,12 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCounters(final CounterType counterType, final Integer num) {
|
public void setCounters(final CounterType counterType, final Integer num) {
|
||||||
|
if (num <= 0) {
|
||||||
|
counters.remove(counterType);
|
||||||
|
} else {
|
||||||
counters.put(counterType, num);
|
counters.put(counterType, num);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract public void setCounters(final Map<CounterType, Integer> allCounters);
|
abstract public void setCounters(final Map<CounterType, Integer> allCounters);
|
||||||
|
|
||||||
|
|||||||
@@ -1023,7 +1023,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
final int toughnessBonusBefore = getToughnessBonusFromCounters();
|
final int toughnessBonusBefore = getToughnessBonusFromCounters();
|
||||||
final int loyaltyBefore = getCurrentLoyalty();
|
final int loyaltyBefore = getCurrentLoyalty();
|
||||||
|
|
||||||
counters.put(counterType, newValue);
|
setCounters(counterType, newValue);
|
||||||
getController().addCounterToPermThisTurn(counterType, addAmount);
|
getController().addCounterToPermThisTurn(counterType, addAmount);
|
||||||
view.updateCounters(this);
|
view.updateCounters(this);
|
||||||
|
|
||||||
@@ -1093,12 +1093,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
int toughnessBonusBefore = getToughnessBonusFromCounters();
|
int toughnessBonusBefore = getToughnessBonusFromCounters();
|
||||||
int loyaltyBefore = getCurrentLoyalty();
|
int loyaltyBefore = getCurrentLoyalty();
|
||||||
|
|
||||||
if (newValue > 0) {
|
setCounters(counterName, newValue);
|
||||||
counters.put(counterName, newValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
counters.remove(counterName);
|
|
||||||
}
|
|
||||||
view.updateCounters(this);
|
view.updateCounters(this);
|
||||||
|
|
||||||
//fire card stats changed event if p/t bonuses or loyalty changed from subtracted counters
|
//fire card stats changed event if p/t bonuses or loyalty changed from subtracted counters
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cnt -= lostEnergy;
|
cnt -= lostEnergy;
|
||||||
this.setCounters(CounterType.ENERGY, cnt);
|
this.setCounters(CounterType.ENERGY, cnt, true);
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,12 +896,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
|
|
||||||
final int oldValue = getCounters(counterType);
|
final int oldValue = getCounters(counterType);
|
||||||
final int newValue = addAmount + oldValue;
|
final int newValue = addAmount + oldValue;
|
||||||
counters.put(counterType, newValue);
|
this.setCounters(counterType, newValue, fireEvents);
|
||||||
view.updateCounters(this);
|
|
||||||
|
|
||||||
if (fireEvents) {
|
|
||||||
getGame().fireEvent(new GameEventPlayerCounters(this, counterType, oldValue, newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, Object> runParams = Maps.newHashMap();
|
final Map<String, Object> runParams = Maps.newHashMap();
|
||||||
runParams.put("Player", this);
|
runParams.put("Player", this);
|
||||||
@@ -922,16 +917,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
final int delta = oldValue - newValue;
|
final int delta = oldValue - newValue;
|
||||||
if (delta == 0) { return; }
|
if (delta == 0) { return; }
|
||||||
|
|
||||||
|
setCounters(counterName, newValue, true);
|
||||||
if (newValue > 0) {
|
|
||||||
counters.put(counterName, newValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
counters.remove(counterName);
|
|
||||||
}
|
|
||||||
view.updateCounters(this);
|
|
||||||
|
|
||||||
getGame().fireEvent(new GameEventPlayerCounters(this, counterName, oldValue, newValue));
|
|
||||||
|
|
||||||
/* TODO Run triggers when something cares
|
/* TODO Run triggers when something cares
|
||||||
int curCounters = oldValue;
|
int curCounters = oldValue;
|
||||||
@@ -952,10 +938,13 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
getGame().fireEvent(new GameEventPlayerCounters(this, null, 0, 0));
|
getGame().fireEvent(new GameEventPlayerCounters(this, null, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCounters(final CounterType counterType, final Integer num) {
|
public void setCounters(final CounterType counterType, final Integer num, boolean fireEvents) {
|
||||||
|
Integer old = getCounters(counterType);
|
||||||
counters.put(counterType, num);
|
counters.put(counterType, num);
|
||||||
view.updateCounters(this);
|
view.updateCounters(this);
|
||||||
getGame().fireEvent(new GameEventPlayerCounters(this, counterType, 0, 0));
|
if (fireEvents) {
|
||||||
|
getGame().fireEvent(new GameEventPlayerCounters(this, counterType, old, num));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -971,7 +960,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
}
|
}
|
||||||
public final void setPoisonCounters(final int num, Card source) {
|
public final void setPoisonCounters(final int num, Card source) {
|
||||||
int oldPoison = getCounters(CounterType.POISON);
|
int oldPoison = getCounters(CounterType.POISON);
|
||||||
setCounters(CounterType.POISON, num);
|
setCounters(CounterType.POISON, num, true);
|
||||||
game.fireEvent(new GameEventPlayerPoisoned(this, source, oldPoison, num));
|
game.fireEvent(new GameEventPlayerPoisoned(this, source, oldPoison, num));
|
||||||
}
|
}
|
||||||
public final void addPoisonCounters(final int num, final Card source) {
|
public final void addPoisonCounters(final int num, final Card source) {
|
||||||
|
|||||||
Reference in New Issue
Block a user