Search in sources :

Example 21 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class MemoryLeakEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller == null || opponent == null) {
        return false;
    }
    opponent.revealCards(source, opponent.getHand(), game);
    TargetCard target;
    Cards cards;
    if (controller.chooseUse(outcome, "Exile a card from hand or graveyard?", null, "Hand", "Graveyard", source, game)) {
        FilterCard filter = new FilterNonlandCard("nonland card in " + opponent.getName() + "'s hand");
        target = new TargetCard(Zone.HAND, filter);
        target.setNotTarget(true);
        cards = opponent.getHand();
    } else {
        FilterCard filter = new FilterNonlandCard("nonland card in " + opponent.getName() + "'s graveyard");
        target = new TargetCard(Zone.GRAVEYARD, filter);
        target.setNotTarget(true);
        cards = opponent.getGraveyard();
    }
    if (controller.choose(outcome, cards, target, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            controller.moveCards(card, Zone.EXILED, source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 22 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class MurmursFromBeyondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
        if (!cards.isEmpty()) {
            controller.revealCards(staticText, cards, game);
            Card cardToGraveyard;
            if (cards.size() == 1) {
                cardToGraveyard = cards.getRandom(game);
            } else {
                Player opponent;
                Set<UUID> opponents = game.getOpponents(controller.getId());
                if (opponents.size() == 1) {
                    opponent = game.getPlayer(opponents.iterator().next());
                } else {
                    Target target = new TargetOpponent(true);
                    controller.chooseTarget(Outcome.Detriment, target, source, game);
                    opponent = game.getPlayer(target.getFirstTarget());
                }
                TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
                opponent.chooseTarget(outcome, cards, target, source, game);
                cardToGraveyard = game.getCard(target.getFirstTarget());
            }
            if (cardToGraveyard != null) {
                controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
                cards.remove(cardToGraveyard);
            }
            controller.moveCards(cards, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 23 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class NissasEncouragementTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (player == null || sourceCard == null) {
        return false;
    }
    NissasEncouragementTarget target = new NissasEncouragementTarget(filter);
    if (player.searchLibrary(target, source, game)) {
        boolean searchGY = false;
        if (target.getTargets().size() < 3) {
            searchGY = true;
        }
        Map<String, Integer> foundCards = new HashMap<>();
        foundCards.put("Forest", 0);
        foundCards.put("Brambleweft Behemoth", 0);
        foundCards.put("Nissa, Genesis Mage", 0);
        Cards cards = new CardsImpl();
        if (!target.getTargets().isEmpty()) {
            for (UUID cardId : target.getTargets()) {
                Card card = player.getLibrary().remove(cardId, game);
                if (card != null) {
                    cards.add(card);
                    foundCards.put(card.getName(), 1);
                }
            }
        }
        if (searchGY) {
            for (String name : foundCards.keySet()) {
                if (foundCards.get(name) == 1) {
                    continue;
                }
                // Look in graveyard for any with this name
                // never change static objects so copy the object here before
                FilterCard namedFilterGY = filterGY.copy();
                namedFilterGY.add(new NamePredicate(name));
                if (player.getGraveyard().count(namedFilterGY, game) > 0) {
                    TargetCard targetGY = new TargetCard(0, 1, Zone.GRAVEYARD, namedFilterGY);
                    if (player.choose(Outcome.ReturnToHand, player.getGraveyard(), targetGY, game)) {
                        for (UUID cardIdGY : targetGY.getTargets()) {
                            Card cardGY = player.getGraveyard().get(cardIdGY, game);
                            cards.add(cardGY);
                        }
                    }
                }
            }
        }
        if (!cards.isEmpty()) {
            player.revealCards(sourceCard.getIdName(), cards, game);
            player.moveCards(cards, Zone.HAND, source, game);
            player.shuffleLibrary(source, game);
            return true;
        }
    }
    player.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) HashMap(java.util.HashMap) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) UUID(java.util.UUID)

Example 24 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class PsychoticEpisodeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player != null && controller != null && sourceObject != null) {
        TargetCard targetCard = new TargetCard(Zone.ALL, new FilterCard());
        targetCard.setRequired(true);
        Cards options = player.getHand().copy();
        Card topdeck = player.getLibrary().getFromTop(game);
        options.add(topdeck);
        controller.lookAtCards("Top of Library (Psychotic Episode)", topdeck, game);
        if (controller.choose(Outcome.Discard, options, targetCard, game)) {
            Card card = game.getCard(targetCard.getFirstTarget());
            if (card != null) {
                CardsImpl cards = new CardsImpl();
                cards.add(card);
                player.revealCards(sourceObject.getIdName(), cards, game);
                player.putCardsOnBottomOfLibrary(cards, game, source, true);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) 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 25 with FilterCard

use of mage.filter.FilterCard in project mage by magefree.

the class RemembranceTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!((ZoneChangeEvent) event).isDiesEvent()) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (permanent != null && filter.match(permanent, game)) {
        FilterCard filterCard = new FilterCard("card named " + permanent.getName());
        filterCard.add(new NamePredicate(permanent.getName()));
        this.getEffects().clear();
        this.addEffect(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true));
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Aggregations

FilterCard (mage.filter.FilterCard)337 Player (mage.players.Player)287 Card (mage.cards.Card)148 TargetCard (mage.target.TargetCard)127 UUID (java.util.UUID)97 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)87 Permanent (mage.game.permanent.Permanent)79 MageObject (mage.MageObject)75 CardsImpl (mage.cards.CardsImpl)75 Cards (mage.cards.Cards)60 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)56 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)54 Target (mage.target.Target)41 TargetCardInHand (mage.target.common.TargetCardInHand)41 TargetPlayer (mage.target.TargetPlayer)35 ApprovingObject (mage.ApprovingObject)29 FilterCreatureCard (mage.filter.common.FilterCreatureCard)25 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)24 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)22 ArrayList (java.util.ArrayList)21