Search in sources :

Example 46 with TargetCardInLibrary

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

the class TreasureChestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary();
    player.searchLibrary(target, source, game);
    Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
    if (card == null) {
        player.shuffleLibrary(source, game);
        return true;
    }
    if (CardType.ARTIFACT.getPredicate().apply(card, game) && player.chooseUse(Outcome.PlayForFree, "Put it onto the battlefield or your hand?", null, "Battlefield", "Hand", source, game)) {
        player.moveCards(card, Zone.BATTLEFIELD, source, game);
    } else {
        player.moveCards(card, Zone.HAND, source, game);
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 47 with TargetCardInLibrary

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

the class BifurcateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    FilterCard filter = new FilterPermanentCard();
    filter.add(new NamePredicate(permanent.getName()));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 48 with TargetCardInLibrary

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

the class CleansingWildfireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (permanent == null) {
        return false;
    }
    Player controller = game.getPlayer(permanent.getControllerId());
    if (controller == null) {
        return false;
    }
    if (!controller.chooseUse(Outcome.PutLandInPlay, "Search for a basic land and put it onto the battlefield tapped?", source, game)) {
        return true;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 49 with TargetCardInLibrary

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

the class CultivateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            Cards revealed = new CardsImpl(target.getTargets());
            controller.revealCards(sourceObject.getIdName(), revealed, game);
            if (target.getTargets().size() == 2) {
                TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
                controller.choose(Outcome.Benefit, revealed, target2, game);
                Card card = revealed.get(target2.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                    revealed.remove(card);
                }
                Set<Card> cards = revealed.getCards(game);
                card = cards.isEmpty() ? null : cards.iterator().next();
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            } else if (target.getTargets().size() == 1) {
                Set<Card> cards = revealed.getCards(game);
                Card card = cards.isEmpty() ? null : cards.iterator().next();
                if (card != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                }
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) Set(java.util.Set) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 50 with TargetCardInLibrary

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

the class DenyingWindEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && player != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, 7, new FilterCard("cards from player's library to exile"));
        if (controller.searchLibrary(target, source, game, player.getId())) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Card card = player.getLibrary().remove(targetId, game);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
                }
            }
        }
        player.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) 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