use of mage.game.tournament.Tournament in project mage by magefree.
the class TournamentController method init.
private void init() {
tournament.addTableEventListener((Listener<TableEvent>) event -> {
switch(event.getEventType()) {
case CHECK_STATE_PLAYERS:
checkPlayersState();
break;
case INFO:
managerFactory.chatManager().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, null, MessageType.STATUS, null);
logger.debug(tournament.getId() + " " + event.getMessage());
break;
case START_DRAFT:
startDraft(event.getDraft());
break;
case CONSTRUCT:
if (!isAbort()) {
construct();
} else {
endTournament();
}
break;
case START_MATCH:
if (!isAbort()) {
initTournament();
startMatch(event.getPair(), event.getMatchOptions());
}
break;
case START_MULTIPLAYER_MATCH:
if (!isAbort()) {
initTournament();
MatchOptions matchOptions = event.getMatchOptions();
if (matchOptions != null && event.getMultiplayerRound() != null) {
for (TournamentPlayer player : event.getMultiplayerRound().getAllPlayers()) {
matchOptions.getPlayerTypes().add(player.getPlayerType());
}
}
startMultiplayerMatch(event.getMultiplayerRound(), event.getMatchOptions());
}
break;
case END:
endTournament();
break;
}
});
tournament.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
try {
switch(event.getQueryType()) {
case CONSTRUCT:
construct(event.getPlayerId(), event.getMax());
break;
}
} catch (MageException ex) {
logger.fatal("Player event listener error", ex);
}
});
for (TournamentPlayer player : tournament.getPlayers()) {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
}
}
checkStart();
}
use of mage.game.tournament.Tournament 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);
}
}
Aggregations