Search in sources :

Example 76 with NamePredicate

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

the class BazaarOfWondersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpell(targetPointer.getFirst(game, source));
    if (spell == null) {
        return false;
    }
    String spellName = spell.getName();
    FilterPermanent filter1 = new FilterPermanent();
    filter1.add(new NamePredicate(spellName));
    filter1.add(TokenPredicate.FALSE);
    if (!game.getBattlefield().getActivePermanents(filter1, source.getControllerId(), game).isEmpty()) {
        game.getStack().counter(spell.getId(), source, game);
        return true;
    }
    FilterCard filter2 = new FilterCard();
    filter2.add(new NamePredicate(spellName));
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        if (player.getGraveyard().count(filter2, game) > 0) {
            return game.getStack().counter(spell.getId(), source, game);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 77 with NamePredicate

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

the class AvenShrineEffect 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("avenShrine" + 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.gainLife(count, game, source);
                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 78 with NamePredicate

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

the class DarkSupplicantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    FilterCard filter = new FilterCard("card named Scion of Darkness");
    filter.add(new NamePredicate("Scion of Darkness"));
    if (controller == null) {
        return false;
    }
    Card selectedCard = null;
    // Graveyard check
    if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for Scion of Darkness?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
        if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
            selectedCard = game.getCard(target.getFirstTarget());
        }
    }
    // Hand check
    if (selectedCard == null && controller.chooseUse(Outcome.Benefit, "Search your hand for Scion of Darkness?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(0, 1, filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            if (!target.getTargets().isEmpty()) {
                selectedCard = game.getCard(target.getFirstTarget());
            }
        }
    }
    // Library check
    boolean librarySearched = false;
    if (selectedCard == null && controller.chooseUse(Outcome.Benefit, "Search your library for Scion of Darkness?", source, game)) {
        librarySearched = true;
        TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                selectedCard = game.getCard(target.getFirstTarget());
            }
        }
    }
    if (selectedCard != null) {
        controller.moveCards(selectedCard, 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) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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