Search in sources :

Example 11 with TargetCardInLibrary

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

the class JungleWayfinderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) {
                    player.searchLibrary(target, source, game);
                    for (UUID cardId : target.getTargets()) {
                        Card card = player.getLibrary().getCard(cardId, game);
                        if (card != null) {
                            player.revealCards(source, new CardsImpl(card), game);
                            player.moveCards(card, Zone.HAND, source, game);
                        }
                    }
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // prevent undo
        controller.resetStoredBookmark(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 12 with TargetCardInLibrary

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

the class KotoseTheSilentSpiderWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller == null || card == null) {
        return false;
    }
    Player opponent = game.getPlayer(card.getOwnerId());
    if (opponent == null) {
        return false;
    }
    UUID exileId = CardUtil.getExileZoneId(game, source);
    String exileName = CardUtil.getSourceName(game, source);
    controller.moveCardsToExile(card, source, game, true, exileId, exileName);
    Cards cards = new CardsImpl();
    FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
    filter.add(new NamePredicate(card.getName()));
    TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
    cards.addAll(targetCardInGraveyard.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
    TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
    cards.addAll(targetCardInHand.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
    TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
    controller.searchLibrary(target, source, game, opponent.getId());
    target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
    Set<Card> cardSet = cards.getCards(game);
    controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
    opponent.shuffleLibrary(source, game);
    cardSet.add(card);
    if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
        return true;
    }
    KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
    for (Card exiledCard : cardSet) {
        CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) mage.cards(mage.cards) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard)

Example 13 with TargetCardInLibrary

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

the class LongTermPlansEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInLibrary target = new TargetCardInLibrary();
        if (player.searchLibrary(target, source, game)) {
            Card card = player.getLibrary().remove(target.getFirstTarget(), game);
            if (card != null) {
                player.shuffleLibrary(source, game);
                // must hides the card name from other players
                player.putCardOnTopXOfLibrary(card, game, source, 3, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 14 with TargetCardInLibrary

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

the class MausoleumSecretsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int critterCount = player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game);
    FilterCard filter = new FilterCard("a black card with mana value less than or equal to " + critterCount);
    filter.add(new ColorPredicate(ObjectColor.BLACK));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, critterCount + 1));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 15 with TargetCardInLibrary

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

the class NobleBenefactorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInLibrary target = new TargetCardInLibrary();
                if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) {
                    player.searchLibrary(target, source, game);
                    for (UUID cardId : target.getTargets()) {
                        Card card = player.getLibrary().getCard(cardId, game);
                        if (card != null) {
                            player.moveCards(card, Zone.HAND, source, game);
                        }
                    }
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // prevent undo
        controller.resetStoredBookmark(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

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