Search in sources :

Example 81 with TargetCardInHand

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

the class TargetCardInMuseVesselExile method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject == null) {
        return false;
    }
    if (player == null) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand();
    if (target.canChoose(source.getSourceId(), player.getId(), game) && target.chooseTarget(Outcome.Exile, player.getId(), source, game)) {
        UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
        return player.moveCardsToExile(new CardsImpl(target.getTargets()).getCards(game), source, game, true, exileId, sourceObject.getIdName());
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl)

Example 82 with TargetCardInHand

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

the class MyojinOfLifesWebPutCreatureOnBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, new FilterCreatureCard("creature cards from your hand to put onto the battlefield"));
    if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
        return controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCardInHand(mage.target.common.TargetCardInHand) CardsImpl(mage.cards.CardsImpl)

Example 83 with TargetCardInHand

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

the class RunedCrownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = null;
    Zone zone = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for a Rune card?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        target.setNotTarget(true);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.GRAVEYARD;
            }
        }
    }
    if (card == null && controller.chooseUse(Outcome.Neutral, "Search your hand for a Rune card?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.HAND;
            }
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.LIBRARY;
            }
        }
        controller.shuffleLibrary(source, game);
    }
    // aura card found - attach it
    if (card == null) {
        return true;
    }
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent != null) {
        game.getState().setValue("attachTo:" + card.getId(), permanent);
    }
    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    if (permanent != null) {
        return permanent.addAttachment(card.getId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Zone(mage.constants.Zone) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 84 with TargetCardInHand

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

the class WidespreadPanicEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (!player.getHand().isEmpty()) {
                    TargetCardInHand target = new TargetCardInHand();
                    target.setTargetName("a card from your hand to put on top of your library");
                    player.choose(Outcome.Detriment, target, source.getSourceId(), game);
                    Card card = player.getHand().get(target.getFirstTarget(), game);
                    if (card != null) {
                        player.moveCardToLibraryWithInfo(card, source, game, Zone.HAND, true, false);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Card(mage.cards.Card)

Example 85 with TargetCardInHand

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

the class SurvivorOfTheUnseenEffect 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)

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