use of mage.game.Table in project mage by magefree.
the class TournamentController method startMultiplayerMatch.
private void startMultiplayerMatch(MultiplayerRound round, MatchOptions matchOptions) {
try {
TableManager tableManager = managerFactory.tableManager();
Table table = tableManager.createTable(managerFactory.gamesRoomManager().getMainRoomId(), matchOptions);
table.setTournamentSubTable(true);
table.setTournament(tournament);
table.setState(TableState.WAITING);
if (round.getAllPlayers().stream().allMatch(tournamentPlayer -> getPlayerUserId(tournamentPlayer.getPlayer().getId()).isPresent())) {
for (TournamentPlayer player : round.getAllPlayers()) {
tableManager.addPlayer(getPlayerUserId(player.getPlayer().getId()).get(), table.getId(), player);
}
table.setState(TableState.STARTING);
tableManager.startTournamentSubMatch(null, table.getId());
tableManager.getMatch(table.getId()).ifPresent(match -> {
match.setTableId(tableId);
round.setMatch(match);
round.setTableId(table.getId());
for (TournamentPlayer player : round.getAllPlayers()) {
player.setState(TournamentPlayerState.DUELING);
}
});
}
} catch (GameException ex) {
logger.fatal("TournamentController startMatch error", ex);
}
}
use of mage.game.Table in project mage by magefree.
the class TournamentController method startMatch.
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
try {
TableManager tableManager = managerFactory.tableManager();
Table table = tableManager.createTable(managerFactory.gamesRoomManager().getMainRoomId(), matchOptions);
table.setTournamentSubTable(true);
table.setTournament(tournament);
table.setState(TableState.WAITING);
TournamentPlayer player1 = pair.getPlayer1();
TournamentPlayer player2 = pair.getPlayer2();
UUID user1Uuid = null;
UUID user2Uuid = null;
if (player1.getPlayerType() == PlayerType.HUMAN) {
Optional<UUID> user1Id = getPlayerUserId(player1.getPlayer().getId());
if (!user1Id.isPresent()) {
logger.fatal("Player 1 not found");
} else {
user1Uuid = user1Id.get();
}
}
if (player2.getPlayerType() == PlayerType.HUMAN) {
Optional<UUID> user2Id = getPlayerUserId(player2.getPlayer().getId());
if (!user2Id.isPresent()) {
logger.fatal("Player 2 not found");
} else {
user2Uuid = user2Id.get();
}
}
tableManager.addPlayer(user1Uuid, table.getId(), player1);
tableManager.addPlayer(user2Uuid, table.getId(), player2);
table.setState(TableState.STARTING);
tableManager.startTournamentSubMatch(null, table.getId());
tableManager.getMatch(table.getId()).ifPresent(match -> {
match.setTableId(tableId);
pair.setMatch(match);
pair.setTableId(table.getId());
player1.setState(TournamentPlayerState.DUELING);
player2.setState(TournamentPlayerState.DUELING);
});
} catch (GameException ex) {
logger.fatal("TournamentController startMatch error", ex);
}
}
use of mage.game.Table in project mage by magefree.
the class User method getGameInfo.
public String getGameInfo() {
StringBuilder sb = new StringBuilder();
int draft = 0, match = 0, sideboard = 0, tournament = 0, construct = 0, waiting = 0;
for (Map.Entry<UUID, Table> tableEntry : tables.entrySet()) {
if (tableEntry != null) {
Table table = tableEntry.getValue();
if (table != null) {
if (table.isTournament()) {
if (tableEntry.getKey() != null) {
TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(tableEntry.getKey());
if (tournamentPlayer != null) {
if (!tournamentPlayer.isEliminated()) {
switch(table.getState()) {
case WAITING:
case STARTING:
case READY_TO_START:
waiting++;
break;
case CONSTRUCTING:
construct++;
break;
case DRAFTING:
draft++;
break;
case DUELING:
tournament++;
break;
}
switch(getUserState()) {
case Disconnected:
tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ')');
break;
case Offline:
tournamentPlayer.setDisconnectInfo(" Offline");
break;
default:
tournamentPlayer.setDisconnectInfo("");
}
}
} else {
// can happen if tournamet has just ended
logger.debug(userName + " tournament player missing - tableId:" + table.getId(), null);
tablesToDelete.add(tableEntry.getKey());
}
} else {
logger.error(userName + " tournament key missing - tableId: " + table.getId(), null);
}
} else {
switch(table.getState()) {
case WAITING:
case STARTING:
case READY_TO_START:
waiting++;
break;
case SIDEBOARDING:
sideboard++;
break;
case DUELING:
match++;
break;
}
}
}
}
}
if (!tablesToDelete.isEmpty()) {
for (UUID keyId : tablesToDelete) {
removeTable(keyId);
}
tablesToDelete.clear();
}
if (waiting > 0) {
sb.append("Wait: ").append(waiting).append(' ');
}
if (match > 0) {
sb.append("Match: ").append(match).append(' ');
}
if (sideboard > 0) {
sb.append("Sideb: ").append(sideboard).append(' ');
}
if (draft > 0) {
sb.append("Draft: ").append(draft).append(' ');
}
if (construct > 0) {
sb.append("Const: ").append(construct).append(' ');
}
if (tournament > 0) {
sb.append("Tourn: ").append(tournament).append(' ');
}
if (!watchedGames.isEmpty()) {
sb.append("Watch: ").append(watchedGames.size()).append(' ');
}
return sb.toString();
}
use of mage.game.Table in project mage by magefree.
the class UserNameSorter method createTournamentTable.
@Override
public TableView createTournamentTable(UUID userId, TournamentOptions options) {
Table table = managerFactory.tableManager().createTournamentTable(this.getRoomId(), userId, options);
tables.put(table.getId(), table);
return new TableView(table);
}
use of mage.game.Table in project mage by magefree.
the class TableManagerImpl method removeTable.
@Override
public void removeTable(UUID tableId) {
TableController tableController = controllers.get(tableId);
if (tableController != null) {
Lock w = controllersLock.writeLock();
w.lock();
try {
controllers.remove(tableId);
} finally {
w.unlock();
}
// deletes the table chat and references to users
tableController.cleanUp();
Table table = tables.get(tableId);
w = tablesLock.writeLock();
w.lock();
try {
tables.remove(tableId);
} finally {
w.unlock();
}
Match match = table.getMatch();
Game game = null;
if (match != null) {
game = match.getGame();
if (game != null && !game.hasEnded()) {
game.end();
}
}
// If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update())
if (table.getState() != TableState.FINISHED) {
if (game != null) {
managerFactory.gameManager().removeGame(game.getId());
// something goes wrong, so don't add it to ended stats
}
managerFactory.gamesRoomManager().removeTable(tableId);
}
}
}
Aggregations