Search in sources :

Example 26 with NamePredicate

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

the class DwarvenShrineEffect 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("dwarvenShrine" + 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);
                    }
                }
                controller.damage(count * 2, mageObject.getId(), source, game);
                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) Spell(mage.game.stack.Spell)

Example 27 with NamePredicate

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

the class MimeofactureEffect 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) {
        return false;
    }
    Player opponent = game.getPlayer(permanent.getControllerId());
    if (opponent == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card named " + permanent.getName());
    filter.add(new NamePredicate(permanent.getName()));
    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
    if (controller.searchLibrary(target, source, game, opponent.getId())) {
        Card card = opponent.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    opponent.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 28 with NamePredicate

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

the class DestroyAllNamedPermanentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetPermanent == null) {
        return false;
    }
    FilterPermanent filter = new FilterPermanent();
    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 perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        perm.destroy(source, game, false);
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent)

Example 29 with NamePredicate

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

the class MitoticManipulationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Set<String> permanentNames = new HashSet<>();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
            permanentNames.add(permanent.getName());
        }
        Cards cardsFromTop = new CardsImpl();
        cardsFromTop.addAll(controller.getLibrary().getTopCards(game, 7));
        controller.lookAtCards(sourceObject.getIdName(), cardsFromTop, game);
        FilterCard filter = new FilterCard("card to put onto the battlefield");
        List<NamePredicate> namePredicates = new ArrayList<>();
        for (String name : permanentNames) {
            namePredicates.add(new NamePredicate(name));
        }
        if (!namePredicates.isEmpty() && !cardsFromTop.isEmpty()) {
            filter.add(Predicates.or(namePredicates));
            TargetCard target = new TargetCard(Zone.LIBRARY, filter);
            if (cardsFromTop.count(filter, source.getSourceId(), source.getControllerId(), game) > 0 && controller.chooseUse(Outcome.PutCardInPlay, "Put a card on the battlefield?", source, game)) {
                if (controller.choose(Outcome.PutCardInPlay, cardsFromTop, target, game)) {
                    Card card = cardsFromTop.get(target.getFirstTarget(), game);
                    if (card != null) {
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                        cardsFromTop.remove(card);
                    }
                }
            }
        }
        controller.putCardsOnBottomOfLibrary(cardsFromTop, game, source, true);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) HashSet(java.util.HashSet)

Example 30 with NamePredicate

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

the class ArachnusSpinnerEffect 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 Arachnus Web");
    filter.add(new NamePredicate("Arachnus Web"));
    Card card = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for Arachnus Web?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
        }
        controller.shuffleLibrary(source, game);
    }
    if (card != null) {
        Permanent permanent = game.getPermanent(source.getFirstTarget());
        if (permanent != null) {
            game.getState().setValue("attachTo:" + card.getId(), permanent.getId());
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                // shouldn't this be done automatically by the logic using the "attachTo:" calue?
                permanent.addAttachment(card.getId(), source, game);
            }
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

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