Search in sources :

Example 21 with TargetCardInLibrary

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

the class SecretSalvageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Card targetCard = game.getCard(getTargetPointer().getFirst(game, source));
        if (targetCard != null) {
            controller.moveCards(targetCard, Zone.EXILED, source, game);
            String nameToSearch = CardUtil.getCardNameForSameNameSearch(targetCard);
            FilterCard nameFilter = new FilterCard();
            nameFilter.add(new NamePredicate(nameToSearch));
            TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, nameFilter);
            if (controller.searchLibrary(target, source, game)) {
                if (!target.getTargets().isEmpty()) {
                    Cards cards = new CardsImpl();
                    for (UUID cardId : target.getTargets()) {
                        Card card = controller.getLibrary().remove(cardId, game);
                        if (card != null) {
                            cards.add(card);
                        }
                    }
                    controller.revealCards(sourceObject.getIdName(), cards, game);
                    controller.moveCards(cards, Zone.HAND, source, game);
                }
                controller.shuffleLibrary(source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard)

Example 22 with TargetCardInLibrary

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

the class CardCanBeCastPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.getLibrary().hasCards()) {
            /**
             * 10/1/2005 Any card you find must be legally cast-able (for
             * example, you have to be able to choose a legal target for
             * it). If you can't find a cast-able card (or choose not to),
             * nothing happens and you shuffle your library.
             */
            FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
            TargetCardInLibrary target = new TargetCardInLibrary(filter);
            filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
            filter.add(CardType.INSTANT.getPredicate());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
            filter.add(new CardCanBeCastPredicate(source.getControllerId()));
            if (controller.searchLibrary(target, source, game, controller.getId())) {
                UUID targetId = target.getFirstTarget();
                Card card = game.getCard(targetId);
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 23 with TargetCardInLibrary

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

the class TezzeretTheSeekerEffect3 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof PayVariableLoyaltyCost) {
            cmc = ((PayVariableLoyaltyCost) cost).getAmount();
        }
    }
    FilterArtifactCard filter = new FilterArtifactCard("artifact card with mana value " + cmc + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) FilterArtifactCard(mage.filter.common.FilterArtifactCard) Cost(mage.abilities.costs.Cost) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 24 with TargetCardInLibrary

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

the class ThassasOracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (player.getLibrary().size() == 0) {
        player.won(game);
        return true;
    }
    int xValue = DevotionCount.U.calculate(game, source, this);
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD);
    player.choose(Outcome.DrawCard, cards, target, game);
    Card card = game.getCard(target.getFirstTarget());
    cards.remove(card);
    player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    if (xValue >= player.getLibrary().size()) {
        player.won(game);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 25 with TargetCardInLibrary

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

the class TraverseTheOutlandsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterLandPermanent filter = new FilterLandPermanent();
    filter.add(TargetController.YOU.getControllerPredicate());
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game);
    int amount = 0;
    for (Permanent creature : creatures) {
        int power = creature.getPower().getValue();
        if (amount < power) {
            amount = power;
        }
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl)

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