Search in sources :

Example 11 with NamePredicate

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

the class CephalidShrineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int count = 0;
    MageObject mageObject = game.getObject(source.getSourceId());
    if (mageObject != null) {
        Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
        if (spell != null) {
            Player controller = game.getPlayer(spell.getControllerId());
            if (controller != null) {
                String name = spell.getName();
                FilterCard filterCardName = new FilterCard();
                filterCardName.add(new NamePredicate(name));
                for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                    Player player = game.getPlayer(playerId);
                    if (player != null) {
                        count += player.getGraveyard().count(filterCardName, game);
                    }
                }
                // even if the cost is 0, we still offer
                Cost cost = ManaUtil.createManaCost(count, true);
                if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
                    return false;
                } else {
                    game.getStack().counter(spell.getId(), source, game);
                    game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell)

Example 12 with NamePredicate

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

the class DoublingChantTarget method makeFilter.

private static FilterCard makeFilter(Set<String> names) {
    FilterCard filter = new FilterCreatureCard();
    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) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Game(mage.game.Game) CardType(mage.constants.CardType) MageObject(mage.MageObject) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Ability(mage.abilities.Ability) FilterCreatureCard(mage.filter.common.FilterCreatureCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate)

Example 13 with NamePredicate

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

the class MoratoriumStoneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    if (card == null) {
        return false;
    }
    String cardName = card.getName();
    FilterCard filter1 = new FilterCard();
    filter1.add(new NamePredicate(cardName));
    FilterPermanent filter2 = new FilterPermanent();
    filter2.add(new NamePredicate(cardName));
    return new ExileGraveyardAllPlayersEffect(filter1).apply(game, source) && new ExileAllEffect(filter2).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) ExileGraveyardAllPlayersEffect(mage.abilities.effects.common.ExileGraveyardAllPlayersEffect) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) ExileAllEffect(mage.abilities.effects.common.ExileAllEffect) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 14 with NamePredicate

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

the class ThoughtHemorrhageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (sourceObject != null && controller != null && cardName != null && !cardName.isEmpty()) {
        Player targetPlayer = game.getPlayer(source.getFirstTarget());
        if (targetPlayer != null) {
            targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
            int cardsFound = 0;
            for (Card card : targetPlayer.getHand().getCards(game)) {
                if (CardUtil.haveSameNames(card, cardName, game)) {
                    cardsFound++;
                }
            }
            if (cardsFound > 0) {
                targetPlayer.damage(3 * cardsFound, source.getSourceId(), source, game);
            }
            // Exile all cards with the same name
            // Building a card filter with the name
            FilterCard filterNamedCards = new FilterCard();
            filterNamedCards.add(new NamePredicate(cardName));
            Set<Card> toExile = new LinkedHashSet<>();
            // search cards in graveyard
            for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
                if (checkCard.getName().equals(cardName)) {
                    toExile.add(checkCard);
                }
            }
            // search cards in Hand
            TargetCard targetCardInHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
            if (controller.chooseTarget(Outcome.Exile, targetPlayer.getHand(), targetCardInHand, source, game)) {
                List<UUID> targets = targetCardInHand.getTargets();
                for (UUID targetId : targets) {
                    Card targetCard = targetPlayer.getHand().get(targetId, game);
                    if (targetCard != null) {
                        toExile.add(targetCard);
                    }
                }
            }
            // search cards in Library
            // If the player has no nonland cards in their hand, you can still search
            // that player's library and have that player shuffle it.
            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) {
                    toExile.add(card);
                }
            }
            controller.moveCards(toExile, Zone.EXILED, source, game);
            targetPlayer.shuffleLibrary(source, game);
            return true;
        }
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) UUID(java.util.UUID)

Example 15 with NamePredicate

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

the class BifurcateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    FilterCard filter = new FilterPermanentCard();
    filter.add(new NamePredicate(permanent.getName()));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

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