Search in sources :

Example 11 with TargetDiscard

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

the class StrongarmTacticsEffect 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) {
        // choose cards to discard
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                int numberOfCardsToDiscard = Math.min(1, player.getHand().size());
                Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, new FilterCard(), playerId);
                player.chooseTarget(outcome, target, source, game);
                Cards cards = new CardsImpl();
                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) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        if (card != null) {
                            if (!(player.discard(card, false, source, game) && card.isCreature(game))) {
                                player.loseLife(4, game, source, false);
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
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) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 12 with TargetDiscard

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

the class FiendOfTheShadowsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null || player.getHand().isEmpty()) {
        return false;
    }
    TargetCard targetCard = new TargetDiscard(player.getId());
    player.choose(outcome, targetCard, source.getSourceId(), game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return false;
    }
    player.moveCardToExileWithInfo(card, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source), source, game, Zone.HAND, true);
    CardUtil.makeCardPlayable(game, source, card, Duration.Custom, false);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetDiscard(mage.target.common.TargetDiscard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 13 with TargetDiscard

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

the class MindMaggotsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetCard target = new TargetDiscard(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURE, controller.getId());
    controller.choose(outcome, controller.getHand(), target, game);
    int counters = controller.discard(new CardsImpl(target.getTargets()), false, source, game).size();
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null || counters < 1) {
        return true;
    }
    permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) TargetDiscard(mage.target.common.TargetDiscard) CardsImpl(mage.cards.CardsImpl)

Example 14 with TargetDiscard

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

the class ProfessorOnyxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (int i = 0; i < 6; i++) {
        Map<UUID, Card> playerMap = new HashMap<>();
        for (UUID playerId : game.getOpponents(source.getControllerId())) {
            Player player = game.getPlayer(playerId);
            if (player == null) {
                continue;
            }
            TargetDiscard target = new TargetDiscard(0, 1, StaticFilters.FILTER_CARD, playerId);
            player.choose(Outcome.Discard, target, source.getSourceId(), game);
            playerMap.put(playerId, game.getCard(target.getFirstTarget()));
        }
        for (UUID playerId : game.getOpponents(source.getControllerId())) {
            Player player = game.getPlayer(playerId);
            if (player == null) {
                continue;
            }
            if (playerMap.get(playerId) == null || !player.discard(playerMap.get(playerId), false, source, game)) {
                player.loseLife(3, game, source, false);
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Card(mage.cards.Card)

Example 15 with TargetDiscard

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

the class PlayerImpl method getToDiscard.

private Cards getToDiscard(int minAmount, int maxAmount, Ability source, Game game) {
    Cards toDiscard = new CardsImpl();
    if (minAmount > maxAmount) {
        return getToDiscard(maxAmount, minAmount, source, game);
    }
    if (maxAmount < 1) {
        return toDiscard;
    }
    if (getHand().size() <= minAmount) {
        toDiscard.addAll(getHand());
        return toDiscard;
    }
    TargetDiscard target = new TargetDiscard(minAmount, maxAmount, StaticFilters.FILTER_CARD, getId());
    choose(Outcome.Discard, target, source != null ? source.getSourceId() : null, game);
    toDiscard.addAll(target.getTargets());
    return toDiscard;
}
Also used : TargetDiscard(mage.target.common.TargetDiscard)

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