Search in sources :

Example 86 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class InsidiousDreamsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    int amount = GetXValue.instance.calculate(game, source, this);
    if (controller != null && sourceObject != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
        if (controller.searchLibrary(target, source, game)) {
            Cards chosen = new CardsImpl();
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().remove(cardId, game);
                chosen.add(card);
            }
            controller.shuffleLibrary(source, game);
            TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
            while (chosen.size() > 1 && controller.canRespond()) {
                controller.choose(Outcome.Neutral, chosen, targetToLib, game);
                Card card = chosen.get(targetToLib.getFirstTarget(), game);
                if (card != null) {
                    chosen.remove(card);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
                }
                targetToLib.clearChosen();
            }
            if (chosen.size() == 1) {
                Card card = chosen.get(chosen.iterator().next(), game);
                controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 87 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class KingNarfisBetrayalSecondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID controllerId = source.getControllerId();
    Player controller = game.getPlayer(controllerId);
    if (controller == null) {
        return false;
    }
    millEffect.apply(game, source);
    // Controller graveyard
    if (controller.getGraveyard().count(filter, game) != 0) {
        if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from your graveyard?", source, game)) {
            TargetCard target = new TargetCardInYourGraveyard(filter);
            target.setNotTarget(true);
            if (controller.chooseTarget(outcome, controller.getGraveyard(), target, source, game)) {
                controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null));
            }
        }
    }
    // Each opponent's graveyard
    for (UUID opponentId : game.getOpponents(controllerId)) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        if (opponent.getGraveyard().count(filter, game) != 0) {
            if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from " + opponent.getName() + "'s graveyard?", source, game)) {
                TargetCard target = new TargetCardInOpponentsGraveyard(1, 1, filter, true);
                target.setNotTarget(true);
                if (controller.chooseTarget(outcome, opponent.getGraveyard(), target, source, game)) {
                    controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null));
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID)

Example 88 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class MindleechMassEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (opponent != null && controller != null) {
        Cards cardsInHand = new CardsImpl();
        cardsInHand.addAll(opponent.getHand());
        opponent.revealCards("Opponents hand", cardsInHand, game);
        if (!cardsInHand.isEmpty() && !cardsInHand.getCards(new FilterNonlandCard(), game).isEmpty()) {
            TargetCard target = new TargetCard(1, Zone.HAND, new FilterNonlandCard());
            if (controller.chooseTarget(Outcome.PlayForFree, cardsInHand, target, source, game)) {
                Card card = game.getCard(target.getFirstTarget());
                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);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 89 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class MindWarpEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player you = game.getPlayer(source.getControllerId());
    if (targetPlayer == null || you == null) {
        return false;
    }
    int amountToDiscard = source.getManaCostsToPay().getX();
    TargetCard target = new TargetCardInHand(amountToDiscard, StaticFilters.FILTER_CARD_CARDS);
    you.choose(outcome, targetPlayer.getHand(), target, game);
    targetPlayer.discard(new CardsImpl(target.getTargets()), false, source, game);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl)

Example 90 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class PhyrexianPortalEffect 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) {
        if (controller.getLibrary().size() >= 10) {
            Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 10));
            TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
            List<Card> pile1 = new ArrayList<>();
            if (opponent.choose(Outcome.Neutral, cards, target, game)) {
                List<UUID> targets = target.getTargets();
                for (UUID targetId : targets) {
                    Card card = cards.get(targetId, game);
                    if (card != null) {
                        pile1.add(card);
                        cards.remove(card);
                    }
                }
            }
            List<Card> pile2 = new ArrayList<>();
            pile2.addAll(cards.getCards(game));
            game.informPlayers(opponent.getLogName() + " separated the top 10 cards of " + controller.getLogName() + "'s library into two face-down piles (" + pile1.size() + " cards and " + pile2.size() + " cards)");
            // it's not viable to turn cards face down here for choosePile (since they're still library cards), this is a workaround
            boolean choice = controller.chooseUse(outcome, "Choose pile to search for a card (the other will be exiled):", source.getSourceObject(game).getLogName(), "Pile 1 (" + pile1.size() + " cards)", "Pile 2 (" + pile2.size() + " cards)", source, game);
            game.informPlayers(controller.getLogName() + " chooses to search the " + (choice ? "first" : "second") + " pile");
            Cards pileToExile = new CardsImpl();
            pileToExile.addAll(choice ? pile2 : pile1);
            controller.moveCardsToExile(pileToExile.getCards(game), source, game, true, null, "");
            Cards chosenPile = new CardsImpl();
            chosenPile.addAll(choice ? pile1 : pile2);
            TargetCard target2 = new TargetCard(Zone.HAND, new FilterCard("card to put into your hand"));
            if (controller.choose(outcome, chosenPile, target2, game)) {
                Card card = chosenPile.get(target2.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

TargetCard (mage.target.TargetCard)309 Player (mage.players.Player)297 FilterCard (mage.filter.FilterCard)177 Card (mage.cards.Card)130 CardsImpl (mage.cards.CardsImpl)96 UUID (java.util.UUID)83 Cards (mage.cards.Cards)81 MageObject (mage.MageObject)80 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)52 Permanent (mage.game.permanent.Permanent)49 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)30 ApprovingObject (mage.ApprovingObject)26 TargetPlayer (mage.target.TargetPlayer)25 FilterCreatureCard (mage.filter.common.FilterCreatureCard)22 TargetOpponent (mage.target.common.TargetOpponent)22 TargetCardInHand (mage.target.common.TargetCardInHand)21 Target (mage.target.Target)19 FilterNonlandCard (mage.filter.common.FilterNonlandCard)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 ArrayList (java.util.ArrayList)16