use of mage.target.common.TargetPermanentOrPlayer in project mage by magefree.
the class ProliferateEffect method apply.
@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);
Map<String, Serializable> options = new HashMap<>();
options.put("UI.right.btn.text", "Done");
controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options);
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.");
}
}
} 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.");
}
}
}
}
}
return true;
}
Aggregations