Stop permanents getting counters when phased out (#9194)

This commit is contained in:
Alex Vasile 2022-07-04 09:33:30 -04:00 committed by GitHub
parent 97fd9b6b6e
commit b52576fcf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 49 deletions

View file

@ -69,62 +69,68 @@ public class AddCountersSourceEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (counter == null) {
return false;
}
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller == null) {
if (putOnCard) { return false;
Card card = game.getCard(source.getSourceId()); }
if (card != null) {
if (counter != null) { if (putOnCard) {
Counter newCounter = counter.copy(); Card card = game.getCard(source.getSourceId());
int countersToAdd = amount.calculate(game, source, this); if (card == null) {
if (countersToAdd > 0 && newCounter.getCount() == 1) { return false;
countersToAdd--; }
}
newCounter.add(countersToAdd); Counter newCounter = counter.copy();
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects"); int countersToAdd = amount.calculate(game, source, this);
card.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects); if (countersToAdd > 0 && newCounter.getCount() == 1) {
if (informPlayers && !game.isSimulation()) { countersToAdd--;
Player player = game.getPlayer(source.getControllerId()); }
if (player != null) { newCounter.add(countersToAdd);
game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + card.getLogName()); List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
} card.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects);
} if (informPlayers && !game.isSimulation()) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + card.getLogName());
}
}
return true;
} else {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
if (permanent == null) {
return false;
}
if ((source.getSourceObjectZoneChangeCounter() == 0 // from static ability
|| source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) { // prevent to add counters to later source objects
Counter newCounter = counter.copy();
int countersToAdd = amount.calculate(game, source, this);
if (amount instanceof StaticValue || countersToAdd > 0) {
if (countersToAdd > 0 && newCounter.getCount() == 1) {
countersToAdd--;
} }
return true; newCounter.add(countersToAdd);
} int before = permanent.getCounters(game).getCount(newCounter.getName());
} else { List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
Permanent permanent = game.getPermanent(source.getSourceId()); permanent.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects); // if used from a replacement effect, the basic event determines if an effect was already applied to an event
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) { if (informPlayers && !game.isSimulation()) {
permanent = game.getPermanentEntering(source.getSourceId()); int amountAdded = permanent.getCounters(game).getCount(newCounter.getName()) - before;
} Player player = game.getPlayer(source.getControllerId());
if (permanent != null if (player != null) {
&& (source.getSourceObjectZoneChangeCounter() == 0 // from static ability game.informPlayers(player.getLogName() + " puts " + amountAdded + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + permanent.getLogName());
|| source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) { // prevent to add counters to later source objects
if (counter != null) {
Counter newCounter = counter.copy();
int countersToAdd = amount.calculate(game, source, this);
if (amount instanceof StaticValue || countersToAdd > 0) {
if (countersToAdd > 0 && newCounter.getCount() == 1) {
countersToAdd--;
}
newCounter.add(countersToAdd);
int before = permanent.getCounters(game).getCount(newCounter.getName());
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects); // if used from a replacement effect, the basic event determines if an effect was already applied to an event
if (informPlayers && !game.isSimulation()) {
int amountAdded = permanent.getCounters(game).getCount(newCounter.getName()) - before;
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
game.informPlayers(player.getLogName() + " puts " + amountAdded + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + permanent.getLogName());
}
}
} }
} }
} }
} }
return true;
} }
return false; return true;
} }
private void setText() { private void setText() {

View file

@ -699,6 +699,12 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
} }
public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List<UUID> appliedEffects, boolean isEffect, int maxCounters) { public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List<UUID> appliedEffects, boolean isEffect, int maxCounters) {
if (this instanceof Permanent) {
if (!((Permanent) this).isPhasedIn()) {
return false;
}
}
boolean returnCode = true; boolean returnCode = true;
GameEvent addingAllEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, source, playerAddingCounters, counter.getName(), counter.getCount()); GameEvent addingAllEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, source, playerAddingCounters, counter.getName(), counter.getCount());
addingAllEvent.setAppliedEffects(appliedEffects); addingAllEvent.setAppliedEffects(appliedEffects);