Search in sources :

Example 1 with TargetNonlandPermanent

use of mage.target.common.TargetNonlandPermanent in project mage by magefree.

the class EyeOfDoomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Map<UUID, Permanent> permanents = new HashMap<>();
    Target target = new TargetNonlandPermanent();
    target.setNotTarget(true);
    PlayerList playerList = game.getPlayerList().copy();
    playerList.setCurrent(game.getActivePlayerId());
    Player player = game.getPlayer(game.getActivePlayerId());
    do {
        target.clearChosen();
        if (player != null && player.chooseTarget(outcome, target, source, game)) {
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                permanents.put(player.getId(), permanent);
                game.informPlayers(player.getLogName() + " chooses " + permanent.getName());
            }
        }
        player = playerList.getNext(game, false);
    } while (player != null && !player.getId().equals(game.getActivePlayerId()));
    for (Map.Entry<UUID, Permanent> entry : permanents.entrySet()) {
        entry.getValue().addCounters(CounterType.DOOM.createInstance(), entry.getKey(), source, game);
    }
    return true;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) PlayerList(mage.players.PlayerList)

Example 2 with TargetNonlandPermanent

use of mage.target.common.TargetNonlandPermanent in project mage by magefree.

the class FortunateFewEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<Permanent, Integer> chosenCards = new HashMap<>(2);
        int maxCount = 0;
        // Players each choose a legal permanent
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterNonlandPermanent filter = new FilterNonlandPermanent("a nonland permanent you don't control");
                filter.add(Predicates.not(new ControllerIdPredicate(player.getId())));
                for (Permanent chosenPerm : chosenCards.keySet()) {
                    filter.add(Predicates.not(new PermanentIdPredicate(chosenPerm.getId())));
                }
                Target target = new TargetNonlandPermanent(filter);
                target.setNotTarget(true);
                if (player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        chosenCards.put(permanent, 1);
                        game.informPlayers(player.getLogName() + " has chosen: " + permanent.getName());
                    }
                }
            }
        }
        for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
            if (!chosenCards.containsKey(permanent)) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) HashMap(java.util.HashMap) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 3 with TargetNonlandPermanent

use of mage.target.common.TargetNonlandPermanent in project mage by magefree.

the class ConsumingTideEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    HashSet<UUID> chosenPermanents = new HashSet<>();
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            TargetNonlandPermanent target = new TargetNonlandPermanent();
            target.setNotTarget(true);
            player.choose(Outcome.Benefit, target, source.getSourceId(), game);
            UUID permId = target.getFirstTarget();
            if (permId != null) {
                chosenPermanents.add(permId);
            }
        }
    }
    HashSet<Card> permanentsToHand = new HashSet<>();
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, controller.getId(), source.getSourceId(), game)) {
        if (!chosenPermanents.contains(permanent.getId())) {
            permanentsToHand.add(permanent);
        }
    }
    controller.moveCards(permanentsToHand, Zone.HAND, source, game);
    int controllerHandSize = controller.getHand().size();
    int cardsToDraw = 0;
    for (UUID opponentId : game.getOpponents(controller.getId())) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent != null && opponent.getHand().size() > controllerHandSize) {
            cardsToDraw++;
        }
    }
    controller.drawCards(cardsToDraw, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet) Card(mage.cards.Card)

Aggregations

Permanent (mage.game.permanent.Permanent)3 Player (mage.players.Player)3 TargetNonlandPermanent (mage.target.common.TargetNonlandPermanent)3 UUID (java.util.UUID)2 Target (mage.target.Target)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Card (mage.cards.Card)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)1 PlayerList (mage.players.PlayerList)1