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