Search in sources :

Example 31 with Zone

use of mage.constants.Zone in project mage by magefree.

the class DeathOrGloryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl(controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
        if (!cards.isEmpty()) {
            TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
            List<Card> pile1 = new ArrayList<>();
            if (controller.choose(Outcome.Neutral, cards, targetCards, game)) {
                List<UUID> targets = targetCards.getTargets();
                for (UUID targetId : targets) {
                    Card card = cards.get(targetId, game);
                    if (card != null) {
                        pile1.add(card);
                        cards.remove(card);
                    }
                }
            }
            List<Card> pile2 = new ArrayList<>();
            pile2.addAll(cards.getCards(game));
            StringBuilder sb = new StringBuilder("First pile of ").append(controller.getLogName()).append(": ");
            sb.append(pile1.stream().map(Card::getLogName).collect(Collectors.joining(", ")));
            game.informPlayers(sb.toString());
            sb = new StringBuilder("Second pile of ").append(controller.getLogName()).append(": ");
            sb.append(pile2.stream().map(Card::getLogName).collect(Collectors.joining(", ")));
            game.informPlayers(sb.toString());
            Set<UUID> opponents = game.getOpponents(source.getControllerId());
            if (!opponents.isEmpty()) {
                Player opponent = game.getPlayer(opponents.iterator().next());
                if (opponents.size() > 1) {
                    Target targetOpponent = new TargetOpponent(true);
                    if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                        opponent = game.getPlayer(targetOpponent.getFirstTarget());
                        game.informPlayers(controller.getLogName() + " chose " + opponent.getLogName() + " to choose their pile");
                    }
                }
                if (opponent != null) {
                    boolean choice = opponent.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
                    Zone pile1Zone = Zone.EXILED;
                    Zone pile2Zone = Zone.BATTLEFIELD;
                    if (choice) {
                        pile1Zone = Zone.BATTLEFIELD;
                        pile2Zone = Zone.EXILED;
                    }
                    Set<Card> pile1Set = new HashSet<>();
                    Set<Card> pile2Set = new HashSet<>();
                    pile1Set.addAll(pile1);
                    pile2Set.addAll(pile2);
                    controller.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
                    controller.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target)

Aggregations

Zone (mage.constants.Zone)31 Player (mage.players.Player)18 Card (mage.cards.Card)15 MageObject (mage.MageObject)13 Permanent (mage.game.permanent.Permanent)12 FilterCard (mage.filter.FilterCard)11 TargetCard (mage.target.TargetCard)9 UUID (java.util.UUID)7 Target (mage.target.Target)7 TargetOpponent (mage.target.common.TargetOpponent)6 ArrayList (java.util.ArrayList)5 CardsImpl (mage.cards.CardsImpl)5 Cards (mage.cards.Cards)4 PermanentCard (mage.game.permanent.PermanentCard)4 ZoneChangeEvent (mage.game.events.ZoneChangeEvent)3 java.util (java.util)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Matcher (java.util.regex.Matcher)2 Ability (mage.abilities.Ability)2