Search in sources :

Example 61 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class CastSplitCardsWithCostModificationTest method prepareReduceEffect.

private void prepareReduceEffect(String cardNameToReduce, int reduceAmount) {
    FilterCard filter = new FilterCard();
    filter.add(new NamePredicate(cardNameToReduce));
    addCustomCardWithAbility("reduce", playerA, new SimpleStaticAbility(new SpellsCostReductionAllEffect(filter, reduceAmount)));
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) SpellsCostReductionAllEffect(mage.abilities.effects.common.cost.SpellsCostReductionAllEffect)

Example 62 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect method applySearchAndExile.

/**
 * @param game
 * @param source
 * @param cardName       name of the card to exile
 * @param targetPlayerId id of the target player to exile card name from his
 *                       or her zones
 * @return
 */
public boolean applySearchAndExile(Game game, Ability source, String cardName, UUID targetPlayerId) {
    Player controller = game.getPlayer(source.getControllerId());
    if (cardName != null && controller != null) {
        Player targetPlayer = game.getPlayer(targetPlayerId);
        if (targetPlayer != null) {
            FilterCard filter = new FilterCard("card named " + cardName);
            filter.add(new NamePredicate(cardName));
            // cards in Graveyard
            int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
            if (cardsCount > 0) {
                filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
                TargetCard target = new TargetCard((graveyardExileOptional ? 0 : cardsCount), cardsCount, Zone.GRAVEYARD, filter);
                if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
                    controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
                }
            }
            // cards in Hand
            cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
            filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
            // cards in Library
            Cards cardsInLibrary = new CardsImpl();
            cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
            cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
            filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
            TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
            if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
                controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
            }
            targetPlayer.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl) Cards(mage.cards.Cards) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 63 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate 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 64 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate 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 65 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class LobotomyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (targetPlayer != null && sourceObject != null && controller != null) {
        // reveal hand of target player
        targetPlayer.revealCards(sourceObject.getIdName(), targetPlayer.getHand(), game);
        // You choose card other than a basic land card
        TargetCard target = new TargetCard(Zone.HAND, filter);
        target.setNotTarget(true);
        Card chosenCard = null;
        if (controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), target, source, game)) {
            chosenCard = game.getCard(target.getFirstTarget());
        }
        // Exile all cards with the same name
        // Building a card filter with the name
        FilterCard filterNamedCards = new FilterCard();
        // so no card matches
        String nameToSearch = "---";
        if (chosenCard != null) {
            nameToSearch = CardUtil.getCardNameForSameNameSearch(chosenCard);
            filterNamedCards.setMessage("cards named " + nameToSearch);
        }
        filterNamedCards.add(new NamePredicate(nameToSearch));
        Cards cardsToExile = new CardsImpl();
        // search cards in graveyard
        if (chosenCard != null) {
            for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
                if (checkCard.getName().equals(chosenCard.getName())) {
                    cardsToExile.add(checkCard);
                }
            }
            // search cards in hand
            TargetCard targetCardsHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
            controller.chooseTarget(outcome, targetPlayer.getHand(), targetCardsHand, source, game);
            for (UUID cardId : targetCardsHand.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    cardsToExile.add(card);
                }
            }
        }
        // If the player has no nonland cards in their hand, you can still search that player's library and have that player shuffle it.
        if (chosenCard != null || controller.chooseUse(outcome, "Search library anyway?", source, game)) {
            TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
            controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
            for (UUID cardId : targetCardsLibrary.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    cardsToExile.add(card);
                }
            }
        }
        if (!cardsToExile.isEmpty()) {
            controller.moveCards(cardsToExile, Zone.EXILED, source, game);
        }
        targetPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Aggregations

NamePredicate (mage.filter.predicate.mageobject.NamePredicate)78 FilterCard (mage.filter.FilterCard)55 Player (mage.players.Player)55 Permanent (mage.game.permanent.Permanent)31 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)30 Card (mage.cards.Card)24 MageObject (mage.MageObject)22 UUID (java.util.UUID)19 FilterPermanent (mage.filter.FilterPermanent)16 TargetCard (mage.target.TargetCard)14 Spell (mage.game.stack.Spell)12 CardsImpl (mage.cards.CardsImpl)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)9 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 TargetPlayer (mage.target.TargetPlayer)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6