Search in sources :

Example 36 with TargetCardInHand

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

the class OracleOfBonesCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
            Card cardToCast = null;
            boolean cancel = false;
            while (controller.canRespond() && !cancel) {
                if (controller.chooseTarget(outcome, target, source, game)) {
                    cardToCast = game.getCard(target.getFirstTarget());
                    if (cardToCast != null && 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;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 37 with TargetCardInHand

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

the class AssemblyHallEffect 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 || controller.getHand().isEmpty() || sourceObject == null) {
        return false;
    }
    Card cardToReveal = null;
    Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(true);
    if (controller.chooseTarget(outcome, target, source, game)) {
        cardToReveal = game.getCard(target.getFirstTarget());
    }
    if (cardToReveal == null) {
        return false;
    }
    controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
    String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
    FilterCard filterCard = new FilterCard("card named " + nameToSearch);
    filterCard.add(new NamePredicate(nameToSearch));
    return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 38 with TargetCardInHand

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

the class ExtortionEffect 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;
    }
    you.lookAtCards("Discard", targetPlayer.getHand(), game);
    TargetCard target = new TargetCardInHand(0, 2, StaticFilters.FILTER_CARD_CARDS);
    target.setNotTarget(true);
    you.choose(Outcome.Discard, 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 39 with TargetCardInHand

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

the class HypergenesisEffect 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(filter);
        while (controller.canRespond()) {
            if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                if (firstInactivePlayer == null) {
                    firstInactivePlayer = currentPlayer.getId();
                }
                target.clearChosen();
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put card 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.getId().equals(firstInactivePlayer)) {
                break;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) PlayerList(mage.players.PlayerList) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 40 with TargetCardInHand

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

the class MindSwordsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Store for each player the cards to exile, that's important because all exile shall happen at the same time
    Map<UUID, Cards> cardsToExile = new HashMap<>();
    // Each player chooses 2 cards to discard
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int numberOfCardsToExile = Math.min(2, player.getHand().size());
        Cards cards = new CardsImpl();
        Target target = new TargetCardInHand(numberOfCardsToExile, new FilterCard());
        player.chooseTarget(Outcome.Exile, target, source, game);
        cards.addAll(target.getTargets());
        cardsToExile.put(playerId, cards);
    }
    // Exile all choosen cards
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cardsPlayerChoseToExile = cardsToExile.get(playerId);
        if (cardsPlayerChoseToExile == null) {
            continue;
        }
        player.moveCards(cardsPlayerChoseToExile.getCards(game), Zone.EXILED, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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