Search in sources :

Example 26 with TargetCardInHand

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

the class BrainstormEffect method putOnLibrary.

private boolean putOnLibrary(Player player, Ability source, Game game) {
    TargetCardInHand target = new TargetCardInHand();
    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
        player.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Card card = player.getHand().get(target.getFirstTarget(), game);
        if (card != null) {
            return player.moveCardToLibraryWithInfo(card, source, game, Zone.HAND, true, false);
        }
    }
    return false;
}
Also used : TargetCardInHand(mage.target.common.TargetCardInHand) Card(mage.cards.Card)

Example 27 with TargetCardInHand

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

the class CastWithoutPayingManaCostEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = manaCost.calculate(game, source, this);
    FilterCard filter = this.filter.copy();
    filter.setMessage(filter.getMessage().replace("%mv", "" + cmc));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    Target target = new TargetCardInHand(filter);
    if (!target.canChoose(source.getSourceId(), controller.getId(), game) || !controller.chooseUse(Outcome.PlayForFree, "Cast " + CardUtil.addArticle(filter.getMessage()) + " without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (controller.canRespond() && !cancel) {
        if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast != null) {
                if (cardToCast.getSpellAbility() == null) {
                    Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
                    cancel = true;
                }
                if (cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                    cancel = true;
                }
            }
        } else {
            cancel = true;
        }
    }
    if (cardToCast != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
        controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 28 with TargetCardInHand

use of mage.target.common.TargetCardInHand 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 29 with TargetCardInHand

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

the class EurekaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        PlayerList playerList = game.getState().getPlayerList().copy();
        while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        UUID firstInactivePlayer = null;
        Target target = new TargetCardInHand(new FilterPermanentCard());
        while (controller.canRespond()) {
            if (firstInactivePlayer == null) {
                firstInactivePlayer = currentPlayer.getId();
            }
            if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                target.clearChosen();
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put permanent from your hand to play?", source, game)) {
                    if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
                            firstInactivePlayer = null;
                        }
                    }
                }
            }
            // get next player
            playerList.getNext();
            currentPlayer = game.getPlayer(playerList.get());
            // if all player since this player didn't put permanent in play finish the process
            if (currentPlayer != null && currentPlayer.getId().equals(firstInactivePlayer)) {
                break;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanentCard(mage.filter.common.FilterPermanentCard) PlayerList(mage.players.PlayerList) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 30 with TargetCardInHand

use of mage.target.common.TargetCardInHand 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)

Aggregations

TargetCardInHand (mage.target.common.TargetCardInHand)148 Player (mage.players.Player)133 Card (mage.cards.Card)96 FilterCard (mage.filter.FilterCard)61 Permanent (mage.game.permanent.Permanent)45 CardsImpl (mage.cards.CardsImpl)41 UUID (java.util.UUID)39 Cards (mage.cards.Cards)24 Target (mage.target.Target)21 TargetCard (mage.target.TargetCard)21 MageObject (mage.MageObject)17 FixedTarget (mage.target.targetpointer.FixedTarget)14 ApprovingObject (mage.ApprovingObject)13 FilterCreatureCard (mage.filter.common.FilterCreatureCard)12 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)10 RevealTargetFromHandCost (mage.abilities.costs.common.RevealTargetFromHandCost)10 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)10 ContinuousEffect (mage.abilities.effects.ContinuousEffect)9 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9