Search in sources :

Example 56 with TargetCard

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

the class CultivatorColossusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    while (player.getHand().count(StaticFilters.FILTER_CARD_LAND, game) > 0) {
        TargetCard target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_LAND);
        player.choose(outcome, target, source.getSourceId(), game);
        Card card = game.getCard(target.getFirstTarget());
        if (card == null) {
            break;
        }
        player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
        if (game.getPermanent(card.getId()) == null) {
            break;
        }
        player.drawCards(1, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 57 with TargetCard

use of mage.target.TargetCard 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 58 with TargetCard

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

the class FinalPartingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Unlike Jarad's Orders, which this mostly copies, you can't fail to find
        TargetCardInLibrary target = new TargetCardInLibrary(2, 2, new FilterCard());
        if (controller.searchLibrary(target, source, game)) {
            if (!target.getTargets().isEmpty()) {
                Cards searched = new CardsImpl();
                for (UUID cardId : target.getTargets()) {
                    Card card = controller.getLibrary().getCard(cardId, game);
                    searched.add(card);
                }
                if (target.getTargets().size() == 2) {
                    TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
                    controller.choose(Outcome.Benefit, searched, target2, game);
                    Card card = searched.get(target2.getFirstTarget(), game);
                    controller.moveCards(card, Zone.HAND, source, game);
                    searched.remove(card);
                    Set<Card> cards = searched.getCards(game);
                    card = cards.isEmpty() ? null : cards.iterator().next();
                    controller.moveCards(card, Zone.GRAVEYARD, source, game);
                } else if (target.getTargets().size() == 1) {
                    Set<Card> cards = searched.getCards(game);
                    Card card = cards.isEmpty() ? null : cards.iterator().next();
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
            controller.shuffleLibrary(source, game);
            return true;
        }
        controller.shuffleLibrary(source, game);
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Set(java.util.Set) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 59 with TargetCard

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

the class HowlpackPiperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getHand().count(StaticFilters.FILTER_CARD_CREATURE, game) < 1) {
        return false;
    }
    TargetCard target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
    player.choose(outcome, player.getHand(), target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    Permanent permanent = game.getPermanent(card.getId());
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent == null || sourcePermanent == null) {
        return true;
    }
    if (permanent.hasSubtype(SubType.WOLF, game) || permanent.hasSubtype(SubType.WEREWOLF, game)) {
        sourcePermanent.untap(game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 60 with TargetCard

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

the class MasterOfPredicamentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (!controller.getHand().isEmpty()) {
            Card cardFromHand = null;
            if (controller.getHand().size() > 1) {
                TargetCard target = new TargetCardInHand(new FilterCard());
                if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
                    cardFromHand = game.getCard(target.getFirstTarget());
                }
            } else {
                cardFromHand = controller.getHand().getRandom(game);
            }
            if (cardFromHand == null) {
                return false;
            }
            Player attackedPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
            if (attackedPlayer == null) {
                return false;
            }
            boolean guessWrong;
            if (attackedPlayer.chooseUse(Outcome.Detriment, "Is the chosen card's " + "mana value greater than 4?", source, game)) {
                game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is greater than 4");
                guessWrong = cardFromHand.getManaValue() <= 4;
            } else {
                game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is not greater than 4");
                guessWrong = cardFromHand.getManaValue() > 4;
            }
            game.informPlayers(attackedPlayer.getLogName() + " guessed " + (guessWrong ? "wrong" : "right"));
            if (guessWrong) {
                if (cardFromHand.isLand(game)) {
                // If the revealed card is a land, you can't cast it. So nothing happens
                } else {
                    if (controller.chooseUse(outcome, "Cast " + cardFromHand.getName() + " without paying its mana cost?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), Boolean.TRUE);
                        controller.cast(controller.chooseAbilityForCast(cardFromHand, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), null);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) 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