Search in sources :

Example 66 with FilterCard

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

the class ThoughtpickerWitchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (controller != null && opponent != null) {
        Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
        if (!cards.isEmpty()) {
            TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile"));
            if (controller.choose(Outcome.Exile, cards, target, game)) {
                Card card = cards.get(target.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    opponent.moveCards(card, Zone.EXILED, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 67 with FilterCard

use of mage.filter.FilterCard 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 68 with FilterCard

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

the class WatchersOfTheDeadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (controller != null) {
        for (UUID opponentId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null && !opponent.equals(controller)) {
                TargetCard target = new TargetCardInYourGraveyard(2, 2, new FilterCard());
                target.setNotTarget(true);
                Cards cardsInGraveyard = opponent.getGraveyard();
                if (cardsInGraveyard.size() > 1) {
                    opponent.choose(outcome, cardsInGraveyard, target, game);
                    for (Card cardInGraveyard : cardsInGraveyard.getCards(game)) {
                        if (!target.getTargets().contains(cardInGraveyard.getId())) {
                            opponent.moveCardToExileWithInfo(cardInGraveyard, CardUtil.getCardExileZoneId(game, source.getId()), sourceObject.getLogName(), source, game, Zone.GRAVEYARD, true);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 69 with FilterCard

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

the class GainProtectionFromColorTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (creature != null) {
        FilterCard protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter();
        protectionFilter.add(new ColorPredicate(choice.getColor()));
        protectionFilter.setMessage(choice.getChoice());
        ((ProtectionAbility) ability).setFilter(protectionFilter);
        creature.addAbility(ability, source.getSourceId(), game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 70 with FilterCard

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

the class CastWithoutPayingManaCostEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = manaCost.calculate(game, source, this);
    FilterCard filter = this.filter.copy();
    filter.setMessage(filter.getMessage().replace("%mv", "" + cmc));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    Target target = new TargetCardInHand(filter);
    if (!target.canChoose(source.getSourceId(), controller.getId(), game) || !controller.chooseUse(Outcome.PlayForFree, "Cast " + CardUtil.addArticle(filter.getMessage()) + " without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (controller.canRespond() && !cancel) {
        if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast != null) {
                if (cardToCast.getSpellAbility() == null) {
                    Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
                    cancel = true;
                }
                if (cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                    cancel = true;
                }
            }
        } else {
            cancel = true;
        }
    }
    if (cardToCast != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
        controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

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