Search in sources :

Example 46 with NamePredicate

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

the class GateToTheAfterlifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card named " + cardName);
    filter.add(new NamePredicate(cardName));
    Card card = null;
    // Graveyard check
    if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for " + cardName + "?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
        if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    // Hand check
    if (card == null && controller.chooseUse(Outcome.Benefit, "Search your hand for " + cardName + "?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(0, 1, filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    // Library check
    boolean librarySearched = false;
    if (card == null && controller.chooseUse(Outcome.Benefit, "Search your library for " + cardName + "?", source, game)) {
        librarySearched = true;
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
        }
        controller.shuffleLibrary(source, game);
    }
    if (card != null) {
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    if (librarySearched) {
        controller.shuffleLibrary(source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 47 with NamePredicate

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

the class GuardianProjectEffect method checkCondition.

// This is needed as checkInterveningIfClause can't access trigger event information
static boolean checkCondition(Permanent permanent, UUID controllerId, Game game) {
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    if (!permanent.getName().isEmpty()) {
        FilterCard filterCard = new FilterCard();
        filterCard.add(new NamePredicate(permanent.getName()));
        filterCard.add(new OwnerIdPredicate(controllerId));
        if (player.getGraveyard().count(filterCard, game) > 0) {
            return false;
        }
    }
    FilterPermanent filterPermanent = new FilterCreaturePermanent();
    filterPermanent.add(new NamePredicate(permanent.getName()));
    filterPermanent.add(Predicates.not(new CardIdPredicate(permanent.getId())));
    filterPermanent.add(new ControllerIdPredicate(controllerId));
    if (!game.getBattlefield().getActivePermanents(filterPermanent, controllerId, game).isEmpty()) {
        return false;
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 48 with NamePredicate

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

the class HomingLightningEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
    if (targetPermanent == null) {
        return false;
    }
    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()));
    }
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        if (creature != null) {
            creature.damage(4, source.getSourceId(), source, game, false, true);
        }
    }
    return true;
}
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)

Example 49 with NamePredicate

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

the class NantukoShrineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (spell != null) {
        Player controller = game.getPlayer(spell.getControllerId());
        if (controller != null) {
            int count = 0;
            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);
                }
            }
            if (count > 0) {
                new SquirrelToken().putOntoBattlefield(count, game, source, spell.getControllerId());
            }
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) UUID(java.util.UUID) Spell(mage.game.stack.Spell) SquirrelToken(mage.game.permanent.token.SquirrelToken)

Example 50 with NamePredicate

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

the class RegularExpression method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<NamePredicate> predicates = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().map(Permanent::getName).filter(Objects::nonNull).filter(s -> !s.isEmpty()).map(NamePredicate::new).collect(Collectors.toList());
    FilterCard filter = new FilterCard("a creature card with the same name as another creature you control");
    filter.add(Predicates.or(predicates));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

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