mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Stop permanents getting counters when phased out (#9194)
This commit is contained in:
parent
97fd9b6b6e
commit
b52576fcf9
2 changed files with 61 additions and 49 deletions
|
@ -69,62 +69,68 @@ public class AddCountersSourceEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (counter == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
if (putOnCard) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
if (counter != null) {
|
||||
Counter newCounter = counter.copy();
|
||||
int countersToAdd = amount.calculate(game, source, this);
|
||||
if (countersToAdd > 0 && newCounter.getCount() == 1) {
|
||||
countersToAdd--;
|
||||
}
|
||||
newCounter.add(countersToAdd);
|
||||
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());
|
||||
}
|
||||
}
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (putOnCard) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Counter newCounter = counter.copy();
|
||||
int countersToAdd = amount.calculate(game, source, this);
|
||||
if (countersToAdd > 0 && newCounter.getCount() == 1) {
|
||||
countersToAdd--;
|
||||
}
|
||||
newCounter.add(countersToAdd);
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
|
||||
permanent = game.getPermanentEntering(source.getSourceId());
|
||||
}
|
||||
if (permanent != null
|
||||
&& (source.getSourceObjectZoneChangeCounter() == 0 // from static ability
|
||||
|| 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());
|
||||
}
|
||||
}
|
||||
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() {
|
||||
|
|
|
@ -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) {
|
||||
if (this instanceof Permanent) {
|
||||
if (!((Permanent) this).isPhasedIn()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean returnCode = true;
|
||||
GameEvent addingAllEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, source, playerAddingCounters, counter.getName(), counter.getCount());
|
||||
addingAllEvent.setAppliedEffects(appliedEffects);
|
||||
|
|
Loading…
Reference in a new issue