refactor: added counter removal events (#11989)

This commit is contained in:
jimga150 2024-05-02 09:32:55 -04:00 committed by GitHub
parent 860a767cca
commit 52ddcac59d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 385 additions and 36 deletions

View file

@ -815,35 +815,46 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
@Override
public void removeCounters(String name, int amount, Ability source, Game game) {
public void removeCounters(String name, int amount, Ability source, Game game, boolean isDamage) {
if (amount <= 0){
return;
}
if (getCounters(game).getCount(name) <= 0){
return;
}
GameEvent removeCountersEvent = new RemoveCountersEvent(name, this, source, amount, isDamage);
if (game.replaceEvent(removeCountersEvent)){
return;
}
int finalAmount = 0;
for (int i = 0; i < amount; i++) {
for (int i = 0; i < removeCountersEvent.getAmount(); i++) {
GameEvent event = new RemoveCounterEvent(name, this, source, isDamage);
if (game.replaceEvent(event)){
continue;
}
if (!getCounters(game).removeCounter(name, 1)) {
break;
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTER_REMOVED, objectId, source, getControllerOrOwnerId());
if (source != null
&& source.getControllerId() != null) {
event.setPlayerId(source.getControllerId()); // player who controls the source ability that removed the counter
}
event.setData(name);
event = new CounterRemovedEvent(name, this, source, isDamage);
game.fireEvent(event);
finalAmount++;
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTERS_REMOVED, objectId, source, getControllerOrOwnerId());
if (source != null
&& source.getControllerId() != null) {
event.setPlayerId(source.getControllerId()); // player who controls the source ability that removed the counter
}
event.setData(name);
event.setAmount(finalAmount);
GameEvent event = new CountersRemovedEvent(name, this, source, finalAmount, isDamage);
game.fireEvent(event);
}
@Override
public void removeCounters(Counter counter, Ability source, Game game) {
public void removeCounters(Counter counter, Ability source, Game game, boolean isDamage) {
if (counter != null) {
removeCounters(counter.getName(), counter.getCount(), source, game);
removeCounters(counter.getName(), counter.getCount(), source, game, isDamage);
}
}