Search in sources :

Example 66 with TargetCardInLibrary

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

the class CartographersHawkEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (permanent == null || player == null) {
        return false;
    }
    if (!player.moveCards(permanent, Zone.HAND, source, game)) {
        return false;
    }
    if (!player.chooseUse(Outcome.PutLandInPlay, "Search your library for Plains card?", source, game)) {
        return true;
    }
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 67 with TargetCardInLibrary

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

the class CaravanVigilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && controller != null) {
        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) {
                Cards cards = new CardsImpl(card);
                if (MorbidCondition.instance.apply(game, source) && controller.chooseUse(Outcome.PutLandInPlay, "Put the card onto the battlefield instead?", source, game)) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                } else {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
                controller.revealCards(sourceObject.getIdName(), cards, game);
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 68 with TargetCardInLibrary

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

the class CruelFateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller == null || opponent == null) {
        return false;
    }
    Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 5));
    if (cards.isEmpty()) {
        return false;
    }
    if (cards.size() == 1) {
        return controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    }
    TargetCard targetCard = new TargetCardInLibrary();
    controller.choose(outcome, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card != null) {
        controller.moveCards(card, Zone.GRAVEYARD, source, game);
        cards.remove(card);
    }
    return controller.putCardsOnTopOfLibrary(card, game, source, true);
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) TargetCard(mage.target.TargetCard)

Example 69 with TargetCardInLibrary

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

the class CurseOfMisfortunesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (controller != null && enchantment != null && enchantment.getAttachedTo() != null) {
        Player targetPlayer = game.getPlayer(enchantment.getAttachedTo());
        Player player = game.getPlayer(source.getControllerId());
        if (player != null && targetPlayer != null) {
            FilterCard filter = new FilterCard("Curse card that doesn't have the same name as a Curse attached to enchanted player");
            filter.add(SubType.CURSE.getPredicate());
            // get the names of attached Curses
            for (UUID attachmentId : targetPlayer.getAttachments()) {
                Permanent attachment = game.getPermanent(attachmentId);
                if (attachment != null && attachment.hasSubtype(SubType.CURSE, game)) {
                    filter.add(Predicates.not(new NamePredicate(attachment.getName())));
                }
            }
            TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
            if (player.searchLibrary(targetCard, source, game)) {
                Card card = game.getCard(targetCard.getFirstTarget());
                if (card != null) {
                    this.setTargetPointer(new FixedTarget(targetPlayer.getId()));
                    game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        targetPlayer.addAttachment(card.getId(), source, game);
                    }
                }
            }
            player.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 70 with TargetCardInLibrary

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

the class EcologicalAppreciationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {

        @Override
        public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
            if (!super.canTarget(playerId, id, source, game)) {
                return false;
            }
            Card card = game.getCard(id);
            Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
            return isValidTarget(card, disallowedCards);
        }
    };
    targetCardsInLibrary.setNotTarget(true);
    targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
    player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
    Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
    boolean status = !cards.isEmpty();
    if (status) {
        int remainingCards = 4 - cards.size();
        if (remainingCards > 0) {
            TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {

                @Override
                public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
                    if (!super.canTarget(playerId, id, source, game)) {
                        return false;
                    }
                    Card card = game.getCard(id);
                    Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
                    Set<Card> checkList = new HashSet<>();
                    checkList.addAll(disallowedCards);
                    checkList.addAll(cards.getCards(game));
                    return isValidTarget(card, checkList);
                }
            };
            targetCardsInGY.setNotTarget(true);
            targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
            player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
            cards.addAll(targetCardsInGY.getTargets());
        }
        TargetOpponent targetOpponent = new TargetOpponent();
        targetOpponent.setNotTarget(true);
        player.choose(outcome, targetOpponent, source.getSourceId(), game);
        Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
        if (opponent == null) {
            status = false;
        }
        if (status) {
            TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
            chosenCards.setNotTarget(true);
            opponent.choose(outcome, cards, chosenCards, game);
            Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
            player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
            cards.removeAll(toShuffle);
            player.moveCards(cards, Zone.BATTLEFIELD, source, game);
        }
    }
    player.shuffleLibrary(source, game);
    return status;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Game(mage.game.Game) UUID(java.util.UUID) HashSet(java.util.HashSet)

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