Search in sources :

Example 1 with Draft

use of mage.game.draft.Draft in project mage by magefree.

the class DraftController method init.

private void init() {
    draft.addTableEventListener((Listener<TableEvent>) event -> {
        try {
            switch(event.getEventType()) {
                case UPDATE:
                    updateDraft();
                    break;
                case END:
                    endDraft();
                    break;
            }
        } catch (MageException ex) {
            logger.fatal("Table event listener error", ex);
        }
    });
    draft.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
        try {
            switch(event.getQueryType()) {
                case PICK_CARD:
                    pickCard(event.getPlayerId(), event.getMax());
                    break;
            }
        } catch (MageException ex) {
            logger.fatal("Table event listener error", ex);
        }
    });
    for (DraftPlayer player : draft.getPlayers()) {
        if (!player.getPlayer().isHuman()) {
            player.setJoined();
            logger.debug("player " + player.getPlayer().getId() + " has joined draft " + draft.getId());
        }
    }
    checkStart();
}
Also used : DraftPickView(mage.view.DraftPickView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TableEvent(mage.game.events.TableEvent) Set(java.util.Set) UUID(java.util.UUID) MageException(mage.MageException) DraftPlayer(mage.game.draft.DraftPlayer) Player(mage.players.Player) ConcurrentMap(java.util.concurrent.ConcurrentMap) Logger(org.apache.log4j.Logger) PlayerQueryEvent(mage.game.events.PlayerQueryEvent) ManagerFactory(mage.server.managers.ManagerFactory) Entry(java.util.Map.Entry) Optional(java.util.Optional) Listener(mage.game.events.Listener) GameController(mage.server.game.GameController) Draft(mage.game.draft.Draft) DraftPlayer(mage.game.draft.DraftPlayer) TableEvent(mage.game.events.TableEvent) MageException(mage.MageException) PlayerQueryEvent(mage.game.events.PlayerQueryEvent)

Example 2 with Draft

use of mage.game.draft.Draft in project mage by magefree.

the class TournamentController method quit.

public void quit(UUID userId) {
    UUID playerId = userPlayerMap.get(userId);
    if (playerId == null) {
        logger.debug("Player not found userId:" + userId + " tournId: " + tournament.getId());
        return;
    }
    TournamentPlayer tournamentPlayer = tournament.getPlayer(playerId);
    if (tournamentPlayer == null) {
        logger.debug("TournamentPlayer not found userId: " + userId + " tournId: " + tournament.getId());
        return;
    }
    if (!started) {
        tournament.leave(playerId);
        return;
    }
    TournamentSession tournamentSession = tournamentSessions.get(playerId);
    if (tournamentSession == null) {
        logger.debug("TournamentSession not found userId: " + userId + " tournId: " + tournament.getId());
        return;
    }
    tournamentSession.setKilled();
    if (tournamentPlayer.isInTournament()) {
        String info;
        TourneyQuitStatus status;
        if (tournament.isDoneConstructing()) {
            info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
            // quit active matches of that tournament
            managerFactory.tableManager().userQuitTournamentSubTables(tournament.getId(), userId);
            status = TourneyQuitStatus.DURING_ROUND;
        } else if (tournamentPlayer.getState() == TournamentPlayerState.DRAFTING) {
            info = "during Draft phase";
            if (!checkToReplaceDraftPlayerByAi(userId, tournamentPlayer)) {
                this.abortDraftTournament();
            } else {
                managerFactory.draftManager().getController(tableId).ifPresent(draftController -> {
                    draftController.getDraftSession(playerId).ifPresent(draftSession -> managerFactory.draftManager().kill(draftSession.getDraftId(), userId));
                });
            }
            status = TourneyQuitStatus.DURING_DRAFTING;
        } else if (tournamentPlayer.getState() == TournamentPlayerState.CONSTRUCTING) {
            info = "during Construction phase";
            status = TourneyQuitStatus.DURING_CONSTRUCTION;
        } else {
            info = "";
            status = TourneyQuitStatus.NO_TOURNEY_QUIT;
        }
        tournamentPlayer.setQuit(info, status);
        tournament.quit(playerId);
        tournamentSession.quit();
        managerFactory.chatManager().broadcast(chatId, "", tournamentPlayer.getPlayer().getLogName() + " has quit the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
    }
}
Also used : MultiplayerRound(mage.game.tournament.MultiplayerRound) MessageType(mage.view.ChatMessage.MessageType) DraftController(mage.server.draft.DraftController) MessageColor(mage.view.ChatMessage.MessageColor) TableEvent(mage.game.events.TableEvent) ConcurrentMap(java.util.concurrent.ConcurrentMap) Logger(org.apache.log4j.Logger) TableManager(mage.server.managers.TableManager) MatchOptions(mage.game.match.MatchOptions) User(mage.server.User) Draft(mage.game.draft.Draft) TournamentPairing(mage.game.tournament.TournamentPairing) TourneyQuitStatus(mage.game.result.ResultProtos.TourneyQuitStatus) TournamentView(mage.view.TournamentView) TableState(mage.constants.TableState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Deck(mage.cards.decks.Deck) UUID(java.util.UUID) MageException(mage.MageException) PlayerType(mage.players.PlayerType) SoundToPlay(mage.view.ChatMessage.SoundToPlay) PlayerQueryEvent(mage.game.events.PlayerQueryEvent) ManagerFactory(mage.server.managers.ManagerFactory) TournamentPlayer(mage.game.tournament.TournamentPlayer) Entry(java.util.Map.Entry) Table(mage.game.Table) Optional(java.util.Optional) TournamentPlayerState(mage.constants.TournamentPlayerState) Listener(mage.game.events.Listener) GameException(mage.game.GameException) Tournament(mage.game.tournament.Tournament) TournamentPlayer(mage.game.tournament.TournamentPlayer) UUID(java.util.UUID) TourneyQuitStatus(mage.game.result.ResultProtos.TourneyQuitStatus)

Aggregations

Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 MageException (mage.MageException)2 Draft (mage.game.draft.Draft)2 Listener (mage.game.events.Listener)2 PlayerQueryEvent (mage.game.events.PlayerQueryEvent)2 TableEvent (mage.game.events.TableEvent)2 ManagerFactory (mage.server.managers.ManagerFactory)2 Logger (org.apache.log4j.Logger)2 Set (java.util.Set)1 Deck (mage.cards.decks.Deck)1 TableState (mage.constants.TableState)1 TournamentPlayerState (mage.constants.TournamentPlayerState)1 GameException (mage.game.GameException)1 Table (mage.game.Table)1 DraftPlayer (mage.game.draft.DraftPlayer)1 MatchOptions (mage.game.match.MatchOptions)1