Search in sources :

Example 71 with NamePredicate

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

the class PartnersWithSearchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player player = game.getPlayer(source.getFirstTarget());
        if (player != null) {
            FilterCard filter = new FilterCard("card named " + partnerName);
            filter.add(new NamePredicate(partnerName));
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            if (player.chooseUse(Outcome.Benefit, "Search your library for a card named " + partnerName + " and put it into your hand?", source, game)) {
                player.searchLibrary(target, source, game);
                for (UUID cardId : target.getTargets()) {
                    Card card = player.getLibrary().getCard(cardId, game);
                    if (card != null) {
                        player.revealCards(source, new CardsImpl(card), game);
                        player.moveCards(card, Zone.HAND, source, game);
                    }
                }
                player.shuffleLibrary(source, game);
            }
        }
        // prevent undo
        controller.resetStoredBookmark(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) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 72 with NamePredicate

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

the class RippleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player != null) {
        if (!player.chooseUse(Outcome.Neutral, "Reveal " + rippleNumber + " cards from the top of your library?", source, game)) {
            // fizzle
            return true;
        }
        // reveal top cards from library
        Cards cards = new CardsImpl();
        cards.addAll(player.getLibrary().getTopCards(game, rippleNumber));
        player.revealCards(sourceObject.getIdName(), cards, game);
        // determine which card should be rippled
        String cardNameToRipple = sourceObject.getName();
        FilterCard sameNameFilter = new FilterCard("card(s) with the name: \"" + cardNameToRipple + "\" to cast without paying their mana cost");
        sameNameFilter.add(new NamePredicate(cardNameToRipple));
        TargetCard target1 = new TargetCard(Zone.LIBRARY, sameNameFilter);
        target1.setRequired(false);
        // choose cards to play for free
        while (player.canRespond() && cards.count(sameNameFilter, game) > 0 && player.choose(Outcome.PlayForFree, cards, target1, game)) {
            Card card = cards.get(target1.getFirstTarget(), game);
            if (card != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                cards.remove(card);
            }
            target1.clearChosen();
        }
        // move cards that weren't cast to the bottom of the library
        player.putCardsOnBottomOfLibrary(cards, game, source, true);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 73 with NamePredicate

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

the class DeputyOfDetentionExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent targeted = game.getPermanent(source.getFirstTarget());
    if (permanent == null || controller == null || targeted == null) {
        return false;
    }
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ControllerIdPredicate(targeted.getControllerId()));
    filter.add(new NamePredicate(targeted.getName()));
    Set<Card> toExile = new LinkedHashSet<>();
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
        toExile.add(creature);
    }
    if (!toExile.isEmpty()) {
        controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
        new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Example 74 with NamePredicate

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

the class DichotomancyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && opponent != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, opponent.getId(), game)) {
            String name = permanent.getName();
            FilterCard filterCard = new FilterCard("card named \"" + name + '"');
            filterCard.add(new NamePredicate(name));
            TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filterCard);
            if (controller.searchLibrary(target, source, game, opponent.getId())) {
                controller.moveCards(opponent.getLibrary().getCard(target.getFirstTarget(), game), Zone.BATTLEFIELD, source, game);
            }
        }
        opponent.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 75 with NamePredicate

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

the class ClarionUltimatumTarget method makeFilter.

private static FilterCard makeFilter(Set<String> names) {
    FilterCard filter = new FilterCard();
    filter.add(Predicates.or(names.stream().map(name -> new NamePredicate(name)).collect(Collectors.toSet())));
    return filter;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) StaticFilters(mage.filter.StaticFilters) java.util(java.util) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) mage.cards(mage.cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) CardUtil(mage.util.CardUtil) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) CardType(mage.constants.CardType) MageObject(mage.MageObject) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) NamePredicate(mage.filter.predicate.mageobject.NamePredicate)

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