Search in sources :

Example 56 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class LilianaOfTheVeilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (player != null && targetPlayer != null) {
        int count = game.getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
        TargetPermanent target = new TargetPermanent(0, count, new FilterPermanent("permanents to put in the first pile"), true);
        List<Permanent> pile1 = new ArrayList<>();
        target.setRequired(false);
        if (player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Permanent p = game.getPermanent(targetId);
                if (p != null) {
                    pile1.add(p);
                }
            }
        }
        List<Permanent> pile2 = new ArrayList<>();
        for (Permanent p : game.getBattlefield().getAllActivePermanents(targetPlayer.getId())) {
            if (!pile1.contains(p)) {
                pile2.add(p);
            }
        }
        boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to sacrifice.", pile1, pile2, game);
        if (choice) {
            sacrificePermanents(pile1, game, source);
        } else {
            sacrificePermanents(pile2, game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 57 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class MistOfStagnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    if (activePlayer != null) {
        int cardsInGrave = activePlayer.getGraveyard().size();
        if (cardsInGrave > 0) {
            TargetPermanent target = new TargetPermanent(cardsInGrave, cardsInGrave, new FilterPermanent("permanents to untap"), true);
            activePlayer.chooseTarget(outcome, target, source, game);
            for (UUID oneTarget : target.getTargets()) {
                Permanent p = game.getPermanent(oneTarget);
                if (p != null) {
                    p.untap(game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 58 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class MythosOfSnapdaxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    boolean conditionMet = condition.apply(game, source);
    List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
    Set<UUID> toKeep = new HashSet();
    for (Player player : playerList) {
        for (CardType cardType : cardTypes) {
            String message = cardType.toString().equals("Artifact") ? "an " : "a ";
            message += cardType.toString().toLowerCase(Locale.ENGLISH);
            message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
            FilterPermanent filter = new FilterNonlandPermanent(message);
            filter.add(cardType.getPredicate());
            filter.add(new ControllerIdPredicate(player.getId()));
            if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
                continue;
            }
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (conditionMet) {
                controller.choose(outcome, target, source.getSourceId(), game);
            } else {
                player.choose(outcome, target, source.getSourceId(), game);
            }
            toKeep.add(target.getFirstTarget());
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
        if (permanent == null || toKeep.contains(permanent.getId())) {
            continue;
        }
        permanent.sacrifice(source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 59 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class SharedAnimosityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (permanent == null) {
        return false;
    }
    FilterPermanent filter = new FilterAttackingCreature();
    filter.add(new SharesCreatureTypePredicate(permanent));
    filter.add(AnotherPredicate.instance);
    int count = game.getBattlefield().count(filter, permanent.getId(), source.getControllerId(), game);
    if (count > 0) {
        game.addEffect(new BoostTargetEffect(count, 0, Duration.EndOfTurn).setTargetPointer(new FixedTarget(permanent, game)), source);
    }
    return true;
}
Also used : FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) FixedTarget(mage.target.targetpointer.FixedTarget) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect)

Example 60 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class SwayOfTheStarsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
                player.moveCards(player.getGraveyard(), Zone.LIBRARY, source, game);
                FilterPermanent filter = new FilterPermanent();
                filter.add(new OwnerIdPredicate(playerId));
                Cards toLib = new CardsImpl();
                for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), source.getSourceId(), game)) {
                    toLib.add(permanent);
                }
                player.shuffleCardsToLibrary(toLib, game, source);
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10