Search in sources :

Example 41 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class SovereignsOfLostAlaraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && attackingCreature != null) {
        FilterCard filter = new FilterCard("aura that could enchant the lone attacking creature");
        filter.add(SubType.AURA.getPredicate());
        filter.add(new AuraCardCanAttachToPermanentId(attackingCreature.getId()));
        if (controller.chooseUse(Outcome.Benefit, "Search your library?", source, game)) {
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            target.setNotTarget(true);
            if (controller.searchLibrary(target, source, game)) {
                if (target.getFirstTarget() != null) {
                    Card aura = game.getCard(target.getFirstTarget());
                    game.getState().setValue("attachTo:" + aura.getId(), attackingCreature);
                    controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
                    attackingCreature.addAttachment(aura.getId(), source, game);
                }
            }
        }
        controller.shuffleLibrary(source, game);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AuraCardCanAttachToPermanentId(mage.filter.predicate.card.AuraCardCanAttachToPermanentId) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 42 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class TappingAtTheWindowEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
    TargetCard target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE);
    player.choose(outcome, cards, target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card != null) {
        player.revealCards(source, new CardsImpl(card), game);
        player.moveCards(card, Zone.HAND, source, game);
    }
    cards.retainZone(Zone.LIBRARY, game);
    player.moveCards(card, Zone.GRAVEYARD, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) TargetCard(mage.target.TargetCard)

Example 43 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary in project mage by magefree.

the class TajuruParagonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
    player.revealCards(source, cards, game);
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (permanent != null) {
        FilterCard filter = new FilterCard("card that shares a creature type with " + permanent.getName());
        filter.add(new SharesCreatureTypePredicate(permanent));
        TargetCard target = new TargetCardInLibrary(0, 1, filter);
        player.choose(outcome, cards, target, game);
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            player.moveCards(card, Zone.HAND, source, game);
            cards.remove(card);
        }
    }
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 44 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary 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 45 with TargetCardInLibrary

use of mage.target.common.TargetCardInLibrary 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)

Aggregations

TargetCardInLibrary (mage.target.common.TargetCardInLibrary)225 Player (mage.players.Player)207 FilterCard (mage.filter.FilterCard)120 Card (mage.cards.Card)110 Permanent (mage.game.permanent.Permanent)68 UUID (java.util.UUID)65 CardsImpl (mage.cards.CardsImpl)53 TargetCard (mage.target.TargetCard)53 MageObject (mage.MageObject)37 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)31 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)28 Cards (mage.cards.Cards)26 TargetPlayer (mage.target.TargetPlayer)19 FilterCreatureCard (mage.filter.common.FilterCreatureCard)18 FilterPermanent (mage.filter.FilterPermanent)14 TargetPermanent (mage.target.TargetPermanent)14 FixedTarget (mage.target.targetpointer.FixedTarget)14 Cost (mage.abilities.costs.Cost)13 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)13 SearchLibraryPutInPlayEffect (mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)12