[PIP] Implement Nuclear Fallout

This commit is contained in:
Susucre 2024-04-11 19:16:36 +02:00
parent 68cacc78fc
commit e741a453bf
3 changed files with 75 additions and 1 deletions

View file

@ -1,6 +1,8 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
@ -8,6 +10,7 @@ import mage.counters.Counter;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.*;
@ -17,11 +20,17 @@ import java.util.*;
public class AddCountersPlayersEffect extends OneShotEffect {
private final Counter counter;
private final DynamicValue amount;
private final TargetController targetController;
public AddCountersPlayersEffect(Counter counter, TargetController targetController) {
this(counter, StaticValue.get(0), targetController);
}
public AddCountersPlayersEffect(Counter counter, DynamicValue amount, TargetController targetController) {
super(Outcome.Benefit);
this.counter = counter;
this.amount = amount;
this.targetController = targetController;
staticText = makeText();
}
@ -29,6 +38,7 @@ public class AddCountersPlayersEffect extends OneShotEffect {
private AddCountersPlayersEffect(final AddCountersPlayersEffect effect) {
super(effect);
this.counter = effect.counter;
this.amount = effect.amount;
this.targetController = effect.targetController;
}
@ -62,10 +72,27 @@ public class AddCountersPlayersEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Counter newCounter = counter.copy();
int calculated = amount.calculate(game, source, this);
if (!(amount instanceof StaticValue) || calculated > 0) {
// If dynamic, or static and set to a > 0 value, we use that instead of the counter's internal amount.
newCounter.remove(newCounter.getCount());
newCounter.add(calculated);
} else {
// StaticValue 0 -- the default counter has the amount, so no adjustment.
}
if (newCounter.getCount() <= 0) {
return false; // no need to iterate on targets, no counters will be put on them
}
for (UUID playerId : getPlayers(game, source)) {
Counter newCounterForPlayer = newCounter.copy();
Player player = game.getPlayer(playerId);
if (player != null) {
player.addCounters(counter, source.getControllerId(), source, game);
player.addCounters(newCounterForPlayer, source.getControllerId(), source, game);
game.informPlayers(player.getLogName() + " gets "
+ newCounterForPlayer.getCount() + ' ' + newCounterForPlayer.getName() + " counters"
+ CardUtil.getSourceLogName(game, source));
}
}
return true;