simplify proliferate effect

This commit is contained in:
theelk801 2023-01-28 10:18:24 -05:00
parent fee324010a
commit a10180f30d

View file

@ -4,6 +4,8 @@ import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.counters.Counter; import mage.counters.Counter;
import mage.counters.CounterType;
import mage.filter.common.FilterPermanentOrPlayer;
import mage.filter.common.FilterPermanentOrPlayerWithCounter; import mage.filter.common.FilterPermanentOrPlayerWithCounter;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -22,6 +24,8 @@ import java.util.UUID;
*/ */
public class ProliferateEffect extends OneShotEffect { public class ProliferateEffect extends OneShotEffect {
private static final FilterPermanentOrPlayer filter = new FilterPermanentOrPlayerWithCounter();
public ProliferateEffect() { public ProliferateEffect() {
this("", true); this("", true);
} }
@ -45,11 +49,10 @@ public class ProliferateEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Counter newCounter = null;
if (controller == null) { if (controller == null) {
return false; return false;
} }
Target target = new TargetPermanentOrPlayer(0, Integer.MAX_VALUE, new FilterPermanentOrPlayerWithCounter(), true); Target target = new TargetPermanentOrPlayer(0, Integer.MAX_VALUE, filter, true);
Map<String, Serializable> options = new HashMap<>(); Map<String, Serializable> options = new HashMap<>();
options.put("UI.right.btn.text", "Done"); options.put("UI.right.btn.text", "Done");
controller.choose(Outcome.Benefit, target, source, game, options); controller.choose(Outcome.Benefit, target, source, game, options);
@ -57,33 +60,22 @@ public class ProliferateEffect extends OneShotEffect {
for (UUID chosen : target.getTargets()) { for (UUID chosen : target.getTargets()) {
Permanent permanent = game.getPermanent(chosen); Permanent permanent = game.getPermanent(chosen);
if (permanent != null) { if (permanent != null) {
if (!permanent.getCounters(game).isEmpty()) {
for (Counter counter : permanent.getCounters(game).values()) { for (Counter counter : permanent.getCounters(game).values()) {
newCounter = new Counter(counter.getName()); Counter newCounter = CounterType.findByName(counter.getName()).createInstance();
permanent.addCounters(newCounter, source.getControllerId(), source, game); if (permanent.addCounters(newCounter, source.getControllerId(), source, game)) {
} game.informPlayers(permanent.getName() + " had " + newCounter.getDescription() + " added to it.");
if (newCounter != null) {
game.informPlayers(permanent.getName()
+ " had 1 "
+ newCounter.getName()
+ " counter added to it.");
} }
} }
} else { continue;
}
Player player = game.getPlayer(chosen); Player player = game.getPlayer(chosen);
if (player != null) { if (player == null) {
if (!player.getCounters().isEmpty()) { continue;
}
for (Counter counter : player.getCounters().values()) { for (Counter counter : player.getCounters().values()) {
newCounter = new Counter(counter.getName()); Counter newCounter = CounterType.findByName(counter.getName()).createInstance();
player.addCounters(newCounter, source.getControllerId(), source, game); if (player.addCounters(newCounter, source.getControllerId(), source, game)) {
} game.informPlayers(player.getLogName() + " had " + newCounter.getDescription() + " added to them.");
if (newCounter != null) {
game.informPlayers(player.getLogName()
+ " had 1 "
+ newCounter.getName()
+ " counter added to them.");
}
}
} }
} }
} }