Search in sources :

Example 6 with TargetDiscard

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

the class DiscardEachPlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    // Store for each player the cards to discard, that's important because all discard shall happen at the same time
    Map<UUID, Cards> cardsToDiscard = new HashMap<>();
    if (controller == null) {
        return true;
    }
    int toDiscard = amount.calculate(game, source, this);
    // choose cards to discard
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        switch(targetController) {
            case NOT_YOU:
                if (playerId.equals(source.getControllerId())) {
                    continue;
                }
                break;
            case OPPONENT:
                if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
                    continue;
                }
                break;
        }
        if (randomDiscard) {
            player.discard(toDiscard, true, false, source, game);
            continue;
        }
        int numberOfCardsToDiscard = Math.min(toDiscard, player.getHand().size());
        Cards cards = new CardsImpl();
        if (numberOfCardsToDiscard > 0) {
            Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, StaticFilters.FILTER_CARD, playerId);
            player.chooseTarget(outcome, target, source, game);
            cards.addAll(target.getTargets());
        }
        cardsToDiscard.put(playerId, cards);
    }
    if (randomDiscard) {
        return true;
    }
    // discard all choosen cards
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        player.discard(cardsToDiscard.get(playerId), false, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 7 with TargetDiscard

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

the class WrenchMindEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (targetPlayer == null || targetPlayer.getHand().isEmpty()) {
        return false;
    }
    if (targetPlayer.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game) < 1 || !targetPlayer.chooseUse(Outcome.Benefit, "Discard an artifact card?", source, game)) {
        return !targetPlayer.discard(2, false, false, source, game).isEmpty();
    }
    TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD_ARTIFACT_AN, targetPlayer.getId());
    targetPlayer.choose(Outcome.Discard, target, source.getSourceId(), game);
    Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
    if (card != null && targetPlayer.discard(card, false, source, game)) {
        return true;
    }
    return !targetPlayer.discard(2, false, false, source, game).isEmpty();
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetDiscard(mage.target.common.TargetDiscard) Card(mage.cards.Card)

Example 8 with TargetDiscard

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

the class SpellboundDragonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Permanent dragon = game.getPermanent(source.getSourceId());
    if (you != null) {
        you.drawCards(1, source, game);
        TargetDiscard target = new TargetDiscard(you.getId());
        you.choose(Outcome.Discard, target, source.getSourceId(), game);
        Card card = you.getHand().get(target.getFirstTarget(), game);
        if (card != null && you.discard(card, false, source, game)) {
            int cmc = card.getManaValue();
            if (dragon != null) {
                game.addEffect(new BoostSourceEffect(cmc, 0, Duration.EndOfTurn), source);
                return true;
            }
        }
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetDiscard(mage.target.common.TargetDiscard) Card(mage.cards.Card)

Example 9 with TargetDiscard

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

the class LilianaWakerOfTheDeadDiscardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Map<UUID, Cards> cardsToDiscard = new HashMap<>();
    if (controller == null) {
        return true;
    }
    // choose cards to discard
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int numberOfCardsToDiscard = Math.min(1, player.getHand().size());
        Cards cards = new CardsImpl();
        Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, StaticFilters.FILTER_CARD, playerId);
        player.chooseTarget(outcome, target, source, game);
        cards.addAll(target.getTargets());
        cardsToDiscard.put(playerId, cards);
    }
    // discard all choosen cards
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int amountDiscarded = player.discard(cardsToDiscard.get(playerId), false, source, game).size();
        if (controller.hasOpponent(playerId, game) && amountDiscarded == 0) {
            player.loseLife(3, game, source, false);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards) ValueHint(mage.abilities.hint.ValueHint) CardsImpl(mage.cards.CardsImpl)

Example 10 with TargetDiscard

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

the class ScytheSpecterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Map<UUID, Card> cardDiscarded = new HashMap<>();
    Map<UUID, Integer> discardedCheck = new HashMap<>();
    Integer highestCMC = 0;
    Integer currentCMC = 0;
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(playerId);
            if (opponent != null) {
                Target target = new TargetDiscard(new FilterCard(), playerId);
                opponent.chooseTarget(Outcome.Discard, target, source, game);
                Card targetCard = game.getCard(target.getFirstTarget());
                if (targetCard != null) {
                    currentCMC = targetCard.getManaValue();
                    if (highestCMC <= currentCMC) {
                        highestCMC = currentCMC;
                    }
                    cardDiscarded.put(playerId, targetCard);
                }
            }
        }
        for (UUID opponentId : cardDiscarded.keySet()) {
            // discard must happen simultaneously
            Player player = game.getPlayer(opponentId);
            if (player != null && player.discard(cardDiscarded.get(opponentId), false, source, game)) {
                // note that a card was discarded
                discardedCheck.put(opponentId, 1);
            }
        }
        for (UUID playerId : game.getOpponents(controller.getId())) {
            // lose life equal to CMC
            Card card = cardDiscarded.get(playerId);
            if ((card != null) && (card.getManaValue() == highestCMC)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null && discardedCheck.get(playerId) == 1) {
                    // check that card was discarded
                    opponent.loseLife(highestCMC, game, source, false);
                }
            }
        }
        cardDiscarded.clear();
        discardedCheck.clear();
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Aggregations

TargetDiscard (mage.target.common.TargetDiscard)18 Player (mage.players.Player)17 UUID (java.util.UUID)10 HashMap (java.util.HashMap)9 Card (mage.cards.Card)9 Cards (mage.cards.Cards)7 CardsImpl (mage.cards.CardsImpl)7 Target (mage.target.Target)7 FilterCard (mage.filter.FilterCard)4 Permanent (mage.game.permanent.Permanent)3 TargetCard (mage.target.TargetCard)3 TargetPlayer (mage.target.TargetPlayer)3 Map (java.util.Map)2 MageObject (mage.MageObject)2 ArrayList (java.util.ArrayList)1 BoostSourceEffect (mage.abilities.effects.common.continuous.BoostSourceEffect)1 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)1 ValueHint (mage.abilities.hint.ValueHint)1 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)1 FixedTarget (mage.target.targetpointer.FixedTarget)1