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,12 +69,21 @@ 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) {
return false;
}
if (putOnCard) { if (putOnCard) {
Card card = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
if (card != null) { if (card == null) {
if (counter != null) { return false;
}
Counter newCounter = counter.copy(); Counter newCounter = counter.copy();
int countersToAdd = amount.calculate(game, source, this); int countersToAdd = amount.calculate(game, source, this);
if (countersToAdd > 0 && newCounter.getCount() == 1) { if (countersToAdd > 0 && newCounter.getCount() == 1) {
@ -89,18 +98,18 @@ public class AddCountersSourceEffect extends OneShotEffect {
game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + card.getLogName()); game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + card.getLogName());
} }
} }
}
return true; return true;
}
} else { } else {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) { if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId()); permanent = game.getPermanentEntering(source.getSourceId());
} }
if (permanent != null if (permanent == null) {
&& (source.getSourceObjectZoneChangeCounter() == 0 // from static ability return false;
}
if ((source.getSourceObjectZoneChangeCounter() == 0 // from static ability
|| source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) { // prevent to add counters to later source objects || source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) { // prevent to add counters to later source objects
if (counter != null) {
Counter newCounter = counter.copy(); Counter newCounter = counter.copy();
int countersToAdd = amount.calculate(game, source, this); int countersToAdd = amount.calculate(game, source, this);
if (amount instanceof StaticValue || countersToAdd > 0) { if (amount instanceof StaticValue || countersToAdd > 0) {
@ -121,11 +130,8 @@ public class AddCountersSourceEffect extends OneShotEffect {
} }
} }
} }
}
return true; return true;
} }
return false;
}
private void setText() { private void setText() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

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);