Search in sources :

Example 26 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class TournamentController method endTournament.

private void endTournament() {
    for (TournamentPlayer player : tournament.getPlayers()) {
        player.setStateAtTournamentEnd();
    }
    for (final TournamentSession tournamentSession : tournamentSessions.values()) {
        tournamentSession.tournamentOver();
    }
    this.tournamentSessions.clear();
    managerFactory.tableManager().endTournament(tableId, tournament);
    tournament.cleanUpOnTournamentEnd();
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 27 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class TournamentController method submitDeck.

public void submitDeck(UUID playerId, Deck deck) {
    if (tournamentSessions.containsKey(playerId)) {
        TournamentPlayer player = tournament.getPlayer(playerId);
        if (player != null && !player.hasQuit()) {
            tournamentSessions.get(playerId).submitDeck(deck);
            managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted their tournament deck", MessageColor.BLACK, true, null, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
        }
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 28 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class TournamentController method construct.

private void construct(UUID playerId, int timeout) throws MageException {
    if (tournamentSessions.containsKey(playerId)) {
        TournamentSession tournamentSession = tournamentSessions.get(playerId);
        tournamentSession.construct(timeout);
        getPlayerUserId(playerId).ifPresent(userId -> {
            managerFactory.userManager().getUser(userId).ifPresent(user -> {
                user.addConstructing(playerId, tournamentSession);
                TournamentPlayer player = tournament.getPlayer(playerId);
                player.setState(TournamentPlayerState.CONSTRUCTING);
            });
        });
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 29 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer 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)

Example 30 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class BoosterDraftSwissTournament method draft.

protected void draft() {
    draft = new BoosterDraft((DraftOptions) options.getLimitedOptions(), getSets());
    for (TournamentPlayer player : players.values()) {
        draft.addPlayer(player.getPlayer());
        player.setState(TournamentPlayerState.DRAFTING);
    }
    tableEventSource.fireTableEvent(TableEvent.EventType.START_DRAFT, null, draft);
}
Also used : BoosterDraft(mage.game.draft.BoosterDraft) TournamentPlayer(mage.game.tournament.TournamentPlayer) DraftOptions(mage.game.draft.DraftOptions)

Aggregations

TournamentPlayer (mage.game.tournament.TournamentPlayer)32 TournamentPairing (mage.game.tournament.TournamentPairing)10 ArrayList (java.util.ArrayList)7 DraftOptions (mage.game.draft.DraftOptions)6 Round (mage.game.tournament.Round)6 RoundPairings (mage.game.tournament.pairing.RoundPairings)6 SwissPairingMinimalWeightMatching (mage.game.tournament.pairing.SwissPairingMinimalWeightMatching)6 UUID (java.util.UUID)5 Table (mage.game.Table)5 User (mage.server.User)5 PlayerStub (org.mage.test.stub.PlayerStub)5 TournamentStub (org.mage.test.stub.TournamentStub)5 Deck (mage.cards.decks.Deck)4 GameException (mage.game.GameException)4 MatchPlayer (mage.game.match.MatchPlayer)4 Test (org.junit.Test)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TableManager (mage.server.managers.TableManager)3 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2