Search in sources :

Example 31 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class RegnasSanctionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    if (!choice.chooseFriendOrFoe(controller, source, game)) {
        return false;
    }
    FilterPermanent filterToTap = new FilterCreaturePermanent();
    for (Player player : choice.getFoes()) {
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (game.getBattlefield().contains(filter, source, game, 1) && player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
            filterToTap.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
        }
    }
    choice.getFriends().stream().map(MageItem::getId).map(ControllerIdPredicate::new).map(Predicates::not).forEach(filterToTap::add);
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
        if (choice.getFriends().stream().map(MageItem::getId).anyMatch(permanent::isControlledBy)) {
            permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
        }
    }
    return new TapAllEffect(filterToTap).apply(game, source);
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TapAllEffect(mage.abilities.effects.common.TapAllEffect) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 32 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class PreventAllDamageToAllEffect method createFilter.

private static FilterPermanentOrPlayer createFilter(FilterPermanent filterPermanent, FilterPlayer filterPlayer) {
    String mes1 = filterPermanent != null ? filterPermanent.getMessage() : "";
    String mes2 = filterPlayer != null ? filterPlayer.getMessage() : "";
    String message;
    if (!mes1.isEmpty() && !mes2.isEmpty()) {
        message = mes1 + " and " + mes2;
    } else {
        message = mes1 + mes2;
    }
    FilterPermanent filter1 = filterPermanent;
    if (filter1 == null) {
        filter1 = new FilterPermanent();
        // disable filter
        filter1.add(new PermanentIdPredicate(UUID.randomUUID()));
    }
    FilterPlayer filter2 = filterPlayer;
    if (filter2 == null) {
        filter2 = new FilterPlayer();
        // disable filter
        filter2.add(new PlayerIdPredicate(UUID.randomUUID()));
    }
    return new FilterPermanentOrPlayer(message, filter1, filter2);
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterPermanentOrPlayer(mage.filter.common.FilterPermanentOrPlayer) FilterPermanent(mage.filter.FilterPermanent) FilterPlayer(mage.filter.FilterPlayer) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate)

Example 33 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class EchoingCourageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (targetPermanent != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        if (CardUtil.haveEmptyName(targetPermanent)) {
            // if no name (face down creature) only the creature itself is selected
            filter.add(new PermanentIdPredicate(targetPermanent.getId()));
        } else {
            filter.add(new NamePredicate(targetPermanent.getName()));
        }
        ContinuousEffect effect = new BoostAllEffect(2, 2, Duration.EndOfTurn, filter, false);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Example 34 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class ReturnToHandAllNamedPermanentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (controller != null && permanent != null) {
        FilterPermanent filter = new FilterPermanent();
        if (CardUtil.haveEmptyName(permanent)) {
            // if no name (face down creature) only the creature itself is selected
            filter.add(new PermanentIdPredicate(permanent.getId()));
        } else {
            filter.add(new NamePredicate(permanent.getName()));
        }
        Cards cardsToHand = new CardsImpl();
        for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
            cardsToHand.add(perm);
        }
        controller.moveCards(cardsToHand, Zone.HAND, source, game);
        return true;
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 35 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate 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)

Aggregations

PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)45 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)26 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)24 FilterPermanent (mage.filter.FilterPermanent)19 TargetPermanent (mage.target.TargetPermanent)19 Target (mage.target.Target)17 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)17 UUID (java.util.UUID)14 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)5 MageObject (mage.MageObject)4 Predicate (mage.filter.predicate.Predicate)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 BecomesFaceDownCreatureAllEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect)3 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)3 AbilityPredicate (mage.filter.predicate.mageobject.AbilityPredicate)3 ArrayList (java.util.ArrayList)2