Search in sources :

Example 1 with TargetDiscard

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

the class BorderlandExplorerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        // 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<>();
        // Store for each player the lands to reveal, that's important because all reveals shall happen at the same time
        Map<UUID, Cards> cardsToReveal = new HashMap<>();
        // choose cards to discard
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Target target = new TargetDiscard(0, 1, new FilterCard(), playerId);
                player.chooseTarget(outcome, target, source, game);
                Cards cards = new CardsImpl(target.getTargets());
                cardsToDiscard.put(playerId, cards);
            }
        }
        // discard all chosen 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);
                        player.discard(card, false, source, game);
                    }
                }
            }
        }
        // search for a land for each player that discarded
        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 && !cardsPlayer.isEmpty()) {
                    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                    if (player.searchLibrary(target, source, game)) {
                        if (!target.getTargets().isEmpty()) {
                            Cards cards = new CardsImpl(target.getTargets());
                            cards.addAll(target.getTargets());
                            cardsToReveal.put(playerId, cards);
                        }
                    }
                }
            }
        }
        // reveal the searched lands, put in hands, and shuffle
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToReveal.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        Cards cards = new CardsImpl(game.getCard(cardId));
                        if (card != null && !cards.isEmpty()) {
                            player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
                            player.moveCards(card, Zone.HAND, source, game);
                            player.shuffleLibrary(source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 2 with TargetDiscard

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

the class CourtOfAmbitionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int discardCount = source.isControlledBy(game.getMonarchId()) ? 2 : 1;
    String message = "Discard " + CardUtil.numberToText(discardCount, "a") + " card" + (discardCount > 1 ? 's' : "") + "? If not you lose " + (discardCount * 3) + " life";
    Map<UUID, Cards> discardMap = new HashMap<>();
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        if (player.getHand().size() < discardCount || !player.chooseUse(Outcome.LoseLife, message, source, game)) {
            player.loseLife(discardCount * 3, game, source, false);
            continue;
        }
        TargetDiscard target = new TargetDiscard(discardCount, StaticFilters.FILTER_CARD, playerId);
        player.choose(Outcome.Discard, target, source.getSourceId(), game);
        discardMap.put(playerId, new CardsImpl(target.getTargets()));
    }
    for (Map.Entry<UUID, Cards> entry : discardMap.entrySet()) {
        Player player = game.getPlayer(entry.getKey());
        if (player != null) {
            player.discard(entry.getValue(), false, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 3 with TargetDiscard

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

the class CompulsiveResearchDiscardEffect 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_LAND, game) < 1 || !targetPlayer.chooseUse(outcome, "Discard a land card?", source, game)) {
        return !targetPlayer.discard(2, false, false, source, game).isEmpty();
    }
    TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD_LAND_A, 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 4 with TargetDiscard

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

the class MindBombEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Map<UUID, Cards> cardsToDiscard = new HashMap<>();
    // choose
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cards = new CardsImpl();
        Target target = new TargetDiscard(0, 3, new FilterCard(), playerId);
        player.chooseTarget(Outcome.Discard, target, source, game);
        cards.addAll(target.getTargets());
        cardsToDiscard.put(playerId, cards);
    }
    // discard
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            Cards cardsPlayer = cardsToDiscard.get(playerId);
            cardsToDiscard.put(playerId, player.discard(cardsPlayer, false, source, game));
        }
    }
    // damage
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cardsPlayer = cardsToDiscard.get(playerId);
        if (cardsPlayer != null) {
            player.damage(3 - cardsPlayer.size(), source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 5 with TargetDiscard

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

the class MonomaniaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    if (player == null || player.getHand().isEmpty()) {
        return false;
    }
    TargetCard target = new TargetDiscard(player.getId());
    player.choose(Outcome.Benefit, player.getHand(), target, game);
    Cards cards = player.getHand().copy();
    cards.removeIf(target.getTargets()::contains);
    return !player.discard(cards, false, source, game).isEmpty();
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards)

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