Search in sources :

Example 71 with TargetCardInHand

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

the class SpectersShriekEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    if (controller == null || player == null) {
        return false;
    }
    player.revealCards(source, player.getHand(), game);
    if (player.getHand().count(StaticFilters.FILTER_CARD_NON_LAND, game) == 0 || !controller.chooseUse(Outcome.Benefit, "Exile a card from " + player.getName() + "'s hand?", source, game)) {
        return false;
    }
    TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard());
    target.setNotTarget(true);
    target.setRequired(false);
    if (!controller.chooseTarget(Outcome.Benefit, player.getHand(), target, source, game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    boolean isBlack = card.getColor(game).isBlack();
    player.moveCards(card, Zone.EXILED, source, game);
    if (isBlack || controller.getHand().isEmpty()) {
        return true;
    }
    target = new TargetCardInHand(filter);
    target.setNotTarget(true);
    return controller.choose(Outcome.Detriment, controller.getHand(), target, game) && controller.moveCards(game.getCard(target.getFirstTarget()), Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 72 with TargetCardInHand

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

the class CardIdPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.drawCards(2, source, game);
        SylvanLibraryCardsDrawnThisTurnWatcher watcher = game.getState().getWatcher(SylvanLibraryCardsDrawnThisTurnWatcher.class);
        if (watcher != null) {
            Cards cards = new CardsImpl();
            Set<UUID> cardsDrawnThisTurn = watcher.getCardsDrawnThisTurn(controller.getId());
            for (UUID cardId : controller.getHand()) {
                if (cardsDrawnThisTurn != null && cardsDrawnThisTurn.contains(cardId)) {
                    Card card = game.getCard(cardId);
                    if (card != null) {
                        cards.add(card);
                    }
                }
            }
            int numberOfTargets = Math.min(2, cards.size());
            if (numberOfTargets > 0) {
                FilterCard filter = new FilterCard(numberOfTargets + " cards of cards drawn this turn");
                filter.add(new CardIdPredicate(cards));
                TargetCardInHand target = new TargetCardInHand(numberOfTargets, filter);
                controller.choose(outcome, target, source.getSourceId(), game);
                Cards cardsPutBack = new CardsImpl();
                for (UUID cardId : target.getTargets()) {
                    Card card = cards.get(cardId, game);
                    if (card != null) {
                        if (controller.canPayLifeCost(source) && controller.getLife() >= 4 && controller.chooseUse(outcome, "Pay 4 life for " + card.getLogName() + "? (Otherwise it's put on top of your library)", source, game)) {
                            controller.loseLife(4, game, source, false);
                            game.informPlayers(controller.getLogName() + " pays 4 life to keep a card on hand");
                        } else {
                            cardsPutBack.add(card);
                        }
                    }
                }
                controller.putCardsOnTopOfLibrary(cardsPutBack, game, source, true);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 73 with TargetCardInHand

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

the class SyphonMindEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int amount = 0;
    boolean result = false;
    Player you = game.getPlayer(source.getControllerId());
    if (you != null) {
        for (UUID playerId : game.getState().getPlayersInRange(you.getId(), game)) {
            if (!playerId.equals(you.getId())) {
                Player otherPlayer = game.getPlayer(playerId);
                if (otherPlayer != null && !otherPlayer.getHand().isEmpty()) {
                    TargetCardInHand target = new TargetCardInHand();
                    if (otherPlayer.choose(Outcome.Discard, target, source.getSourceId(), game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            if (otherPlayer.discard(card, false, source, game)) {
                                amount += 1;
                                result = true;
                                target.clearChosen();
                            }
                        }
                    }
                }
            }
        }
        you.drawCards(amount, source, game);
    }
    return result;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Card(mage.cards.Card)

Example 74 with TargetCardInHand

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

the class ContinuousEffects method applySpliceEffects.

/**
 * Checks all available splice effects to be applied.
 *
 * @param abilityToModify
 * @param game
 */
public void applySpliceEffects(Ability abilityToModify, Game game) {
    // splice spell - spell can't be spliced again
    if (CardUtil.isSpliceAbility(abilityToModify, game)) {
        return;
    }
    // fused spell - can be spliced only to main fused ability, not to parts
    if (CardUtil.isFusedPartAbility(abilityToModify, game)) {
        return;
    }
    List<SpliceCardEffect> spliceEffects = getApplicableSpliceCardEffects(game, abilityToModify.getControllerId());
    // get the applyable splice abilities
    List<Ability> spliceAbilities = new ArrayList<>();
    for (SpliceCardEffect effect : spliceEffects) {
        Set<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
        for (Ability ability : abilities) {
            if (effect.applies(abilityToModify, ability, game)) {
                spliceAbilities.add(ability);
            }
        }
    }
    if (!spliceAbilities.isEmpty()) {
        Player controller = game.getPlayer(abilityToModify.getControllerId());
        if (controller.chooseUse(Outcome.Benefit, "Splice a card?", abilityToModify, game)) {
            Cards cardsToReveal = new CardsImpl();
            do {
                FilterCard filter = new FilterCard("a card to splice");
                List<Predicate<MageObject>> idPredicates = new ArrayList<>();
                for (Ability ability : spliceAbilities) {
                    idPredicates.add(new CardIdPredicate((ability.getSourceId())));
                }
                filter.add(Predicates.or(idPredicates));
                TargetCardInHand target = new TargetCardInHand(filter);
                controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
                UUID cardId = target.getFirstTarget();
                if (cardId != null) {
                    Ability selectedAbility = null;
                    for (Ability ability : spliceAbilities) {
                        if (ability.getSourceId().equals(cardId)) {
                            selectedAbility = ability;
                            break;
                        }
                    }
                    if (selectedAbility != null) {
                        SpliceCardEffect spliceEffect = (SpliceCardEffect) selectedAbility.getEffects().get(0);
                        spliceEffect.apply(game, selectedAbility, abilityToModify);
                        cardsToReveal.add(game.getCard(cardId));
                        spliceAbilities.remove(selectedAbility);
                    }
                }
            } while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", abilityToModify, game));
            controller.revealCards("Spliced cards", cardsToReveal, game);
        }
    }
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) Predicate(mage.filter.predicate.Predicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate) FilterCard(mage.filter.FilterCard) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 75 with TargetCardInHand

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

the class LondonMulligan method mulligan.

@Override
public void mulligan(Game game, UUID playerId) {
    Player player = game.getPlayer(playerId);
    int numCards = startingHandSizes.get(player.getId());
    player.getLibrary().addAll(player.getHand().getCards(game), game);
    player.getHand().clear();
    player.shuffleLibrary(null, game);
    int deduction = 1;
    if (freeMulligans > 0) {
        if (usedFreeMulligans.containsKey(player.getId())) {
            int used = usedFreeMulligans.get(player.getId());
            if (used < freeMulligans) {
                deduction = 0;
                usedFreeMulligans.put(player.getId(), used + 1);
            }
        } else {
            deduction = 0;
            usedFreeMulligans.put(player.getId(), 1);
        }
    }
    openingHandSizes.put(playerId, openingHandSizes.get(playerId) - deduction);
    int newHandSize = openingHandSizes.get(player.getId());
    if (deduction == 0) {
        game.fireInformEvent(player.getLogName() + " mulligans for free.");
    } else {
        game.fireInformEvent(player.getLogName() + " mulligans down to " + newHandSize + (newHandSize == 1 ? " card" : " cards"));
    }
    player.drawCards(numCards, null, game);
    while (player.canRespond() && player.getHand().size() > newHandSize) {
        Target target = new TargetCardInHand(new FilterCard("card (" + (player.getHand().size() - newHandSize) + " more) to put on the bottom of your library"));
        player.chooseTarget(Outcome.Discard, target, null, game);
        player.putCardsOnBottomOfLibrary(new CardsImpl(target.getTargets()), game, null, true);
    }
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) TargetCardInHand(mage.target.common.TargetCardInHand) 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