Search in sources :

Example 1 with PlayableObjectsList

use of mage.players.PlayableObjectsList in project mage by magefree.

the class ReplayTask method prepareSelectableView.

private void prepareSelectableView() {
    // make cards/perm selectable/chooseable/playable update game data updates
    if (lastGameData.game == null) {
        return;
    }
    Zone needZone = Zone.ALL;
    if (lastGameData.options != null && lastGameData.options.containsKey("targetZone")) {
        needZone = (Zone) lastGameData.options.get("targetZone");
    }
    List<UUID> needChoosen;
    if (lastGameData.options != null && lastGameData.options.containsKey("chosen")) {
        needChoosen = (List<UUID>) lastGameData.options.get("chosen");
    } else {
        needChoosen = new ArrayList<>();
    }
    Set<UUID> needSelectable;
    if (lastGameData.targets != null) {
        needSelectable = lastGameData.targets;
    } else {
        needSelectable = new HashSet<>();
    }
    PlayableObjectsList needPlayable;
    if (lastGameData.showPlayable && lastGameData.game.getCanPlayObjects() != null) {
        needPlayable = lastGameData.game.getCanPlayObjects();
    } else {
        needPlayable = new PlayableObjectsList();
    }
    if (needChoosen.isEmpty() && needSelectable.isEmpty() && needPlayable.isEmpty()) {
        return;
    }
    // hand
    if (needZone == Zone.HAND || needZone == Zone.ALL) {
        for (CardView card : lastGameData.game.getHand().values()) {
            if (needSelectable.contains(card.getId())) {
                card.setChoosable(true);
            }
            if (needChoosen.contains(card.getId())) {
                card.setSelected(true);
            }
            if (needPlayable.containsObject(card.getId())) {
                card.setPlayableStats(needPlayable.getStats(card.getId()));
            }
        }
    }
    // stack
    if (needZone == Zone.STACK || needZone == Zone.ALL) {
        for (Map.Entry<UUID, CardView> card : lastGameData.game.getStack().entrySet()) {
            if (needSelectable.contains(card.getKey())) {
                card.getValue().setChoosable(true);
            }
            if (needChoosen.contains(card.getKey())) {
                card.getValue().setSelected(true);
            }
            // users can activate abilities of the spell on the stack (example: Lightning Storm);
            if (needPlayable.containsObject(card.getKey())) {
                card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
            }
        }
    }
    // battlefield
    if (needZone == Zone.BATTLEFIELD || needZone == Zone.ALL) {
        for (PlayerView player : lastGameData.game.getPlayers()) {
            for (Map.Entry<UUID, PermanentView> perm : player.getBattlefield().entrySet()) {
                if (needSelectable.contains(perm.getKey())) {
                    perm.getValue().setChoosable(true);
                }
                if (needChoosen.contains(perm.getKey())) {
                    perm.getValue().setSelected(true);
                }
                if (needPlayable.containsObject(perm.getKey())) {
                    perm.getValue().setPlayableStats(needPlayable.getStats(perm.getKey()));
                }
            }
        }
    }
    // graveyard
    if (needZone == Zone.GRAVEYARD || needZone == Zone.ALL) {
        for (PlayerView player : lastGameData.game.getPlayers()) {
            for (Map.Entry<UUID, CardView> card : player.getGraveyard().entrySet()) {
                if (needSelectable.contains(card.getKey())) {
                    card.getValue().setChoosable(true);
                }
                if (needChoosen.contains(card.getKey())) {
                    card.getValue().setSelected(true);
                }
                if (needPlayable.containsObject(card.getKey())) {
                    card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
                }
            }
        }
    }
    // sideboard
    if (needZone == Zone.OUTSIDE || needZone == Zone.ALL) {
        for (PlayerView player : lastGameData.game.getPlayers()) {
            for (Map.Entry<UUID, CardView> card : player.getSideboard().entrySet()) {
                if (needSelectable.contains(card.getKey())) {
                    card.getValue().setChoosable(true);
                }
                if (needChoosen.contains(card.getKey())) {
                    card.getValue().setSelected(true);
                }
                if (needPlayable.containsObject(card.getKey())) {
                    card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
                }
            }
        }
    }
    // sideboards (old windows all the time, e.g. unattached from game data)
    prepareSelectableWindows(sideboardWindows.values(), needSelectable, needChoosen, needPlayable);
    // exile
    if (needZone == Zone.EXILED || needZone == Zone.ALL) {
        // exile from player panel
        for (PlayerView player : lastGameData.game.getPlayers()) {
            for (CardView card : player.getExile().values()) {
                if (needSelectable.contains(card.getId())) {
                    card.setChoosable(true);
                }
                if (needChoosen.contains(card.getId())) {
                    card.setSelected(true);
                }
                if (needPlayable.containsObject(card.getId())) {
                    card.setPlayableStats(needPlayable.getStats(card.getId()));
                }
            }
        }
        // exile from windows
        for (ExileView exile : lastGameData.game.getExile()) {
            for (Map.Entry<UUID, CardView> card : exile.entrySet()) {
                if (needSelectable.contains(card.getKey())) {
                    card.getValue().setChoosable(true);
                }
                if (needChoosen.contains(card.getKey())) {
                    card.getValue().setSelected(true);
                }
                if (needPlayable.containsObject(card.getKey())) {
                    card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
                }
            }
        }
    }
    // command
    if (needZone == Zone.COMMAND || needZone == Zone.ALL) {
        for (PlayerView player : lastGameData.game.getPlayers()) {
            for (CommandObjectView com : player.getCommandObjectList()) {
                if (needSelectable.contains(com.getId())) {
                    com.setChoosable(true);
                }
                if (needChoosen.contains(com.getId())) {
                    com.setSelected(true);
                }
                if (needPlayable.containsObject(com.getId())) {
                    com.setPlayableStats(needPlayable.getStats(com.getId()));
                }
            }
        }
    }
    // companion
    for (RevealedView rev : lastGameData.game.getCompanion()) {
        for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) {
            if (needSelectable.contains(card.getKey())) {
                card.getValue().setChoosable(true);
            }
            if (needChoosen.contains(card.getKey())) {
                card.getValue().setSelected(true);
            }
            if (needPlayable.containsObject(card.getKey())) {
                card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
            }
        }
    }
    // revealed (current cards)
    for (RevealedView rev : lastGameData.game.getRevealed()) {
        for (Map.Entry<UUID, CardView> card : rev.getCards().entrySet()) {
            if (needSelectable.contains(card.getKey())) {
                card.getValue().setChoosable(true);
            }
            if (needChoosen.contains(card.getKey())) {
                card.getValue().setSelected(true);
            }
            if (needPlayable.containsObject(card.getKey())) {
                card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
            }
        }
    }
    // revealed (old windows)
    prepareSelectableWindows(revealed.values(), needSelectable, needChoosen, needPlayable);
    // looked at (current cards)
    for (LookedAtView look : lastGameData.game.getLookedAt()) {
        for (Map.Entry<UUID, SimpleCardView> card : look.getCards().entrySet()) {
            if (needPlayable.containsObject(card.getKey())) {
                card.getValue().setPlayableStats(needPlayable.getStats(card.getKey()));
            }
        }
    }
    // looked at (old windows)
    prepareSelectableWindows(lookedAt.values(), needSelectable, needChoosen, needPlayable);
}
Also used : PlayableObjectsList(mage.players.PlayableObjectsList)

Aggregations

PlayableObjectsList (mage.players.PlayableObjectsList)1