Search in sources :

Example 1 with FilterPermanentOrPlayerWithCounter

use of mage.filter.common.FilterPermanentOrPlayerWithCounter 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;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Target(mage.target.Target) Serializable(java.io.Serializable) FilterPermanentOrPlayerWithCounter(mage.filter.common.FilterPermanentOrPlayerWithCounter) Counter(mage.counters.Counter) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Permanent(mage.game.permanent.Permanent) HashMap(java.util.HashMap) FilterPermanentOrPlayerWithCounter(mage.filter.common.FilterPermanentOrPlayerWithCounter) UUID(java.util.UUID)

Aggregations

Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Counter (mage.counters.Counter)1 FilterPermanentOrPlayerWithCounter (mage.filter.common.FilterPermanentOrPlayerWithCounter)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetPermanentOrPlayer (mage.target.common.TargetPermanentOrPlayer)1