mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
remove games from list when finished + added name and owner to tables
This commit is contained in:
parent
2f515e242b
commit
017b2b4339
12 changed files with 770 additions and 624 deletions
|
|
@ -66,26 +66,29 @@ public class TableController {
|
|||
|
||||
private UUID sessionId;
|
||||
private UUID chatId;
|
||||
private String controllerName;
|
||||
private Table table;
|
||||
private Match match;
|
||||
private MatchOptions options;
|
||||
private Tournament tournament;
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||
|
||||
public TableController(UUID sessionId, MatchOptions options) {
|
||||
public TableController(UUID roomId, UUID sessionId, MatchOptions options) {
|
||||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.options = options;
|
||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
||||
controllerName = SessionManager.getInstance().getSession(sessionId).getUsername();
|
||||
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
||||
init();
|
||||
}
|
||||
|
||||
public TableController(UUID sessionId, TournamentOptions options) {
|
||||
public TableController(UUID roomId, UUID sessionId, TournamentOptions options) {
|
||||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
||||
controllerName = SessionManager.getInstance().getSession(sessionId).getUsername();
|
||||
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
|
@ -320,7 +323,7 @@ public class TableController {
|
|||
UUID choosingPlayerId = match.getChooser();
|
||||
match.endGame();
|
||||
table.endGame();
|
||||
GameManager.getInstance().saveGame(match.getGame().getId());
|
||||
// GameManager.getInstance().saveGame(match.getGame().getId());
|
||||
GameManager.getInstance().removeGame(match.getGame().getId());
|
||||
try {
|
||||
if (!match.isMatchOver()) {
|
||||
|
|
@ -328,6 +331,9 @@ public class TableController {
|
|||
match.sideboard();
|
||||
startGame(choosingPlayerId);
|
||||
}
|
||||
else {
|
||||
GamesRoomManager.getInstance().getRoom(table.getRoomId()).removeTable(sessionId, table.getId());
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
logger.fatal(null, ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,22 +58,22 @@ public class TableManager {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public Table createTable(UUID sessionId, MatchOptions options) {
|
||||
TableController tableController = new TableController(sessionId, options);
|
||||
public Table createTable(UUID roomId, UUID sessionId, MatchOptions options) {
|
||||
TableController tableController = new TableController(roomId, sessionId, options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
return tableController.getTable();
|
||||
}
|
||||
|
||||
public Table createTable(MatchOptions options) {
|
||||
TableController tableController = new TableController(UUID.randomUUID(), options);
|
||||
public Table createTable(UUID roomId, MatchOptions options) {
|
||||
TableController tableController = new TableController(roomId, UUID.randomUUID(), options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
return tableController.getTable();
|
||||
}
|
||||
|
||||
public Table createTournamentTable(UUID sessionId, TournamentOptions options) {
|
||||
TableController tableController = new TableController(sessionId, options);
|
||||
public Table createTournamentTable(UUID roomId, UUID sessionId, TournamentOptions options) {
|
||||
TableController tableController = new TableController(roomId, sessionId, options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
return tableController.getTable();
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
|
||||
@Override
|
||||
public TableView createTable(UUID sessionId, MatchOptions options) {
|
||||
Table table = TableManager.getInstance().createTable(sessionId, options);
|
||||
Table table = TableManager.getInstance().createTable(this.getRoomId(), sessionId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
|
||||
@Override
|
||||
public TableView createTournamentTable(UUID sessionId, TournamentOptions options) {
|
||||
Table table = TableManager.getInstance().createTournamentTable(sessionId, options);
|
||||
Table table = TableManager.getInstance().createTournamentTable(this.getRoomId(), sessionId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import mage.game.tournament.TournamentPairing;
|
|||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.TournamentView;
|
||||
|
|
@ -169,7 +170,7 @@ public class TournamentController {
|
|||
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
|
||||
try {
|
||||
TableManager tableManager = TableManager.getInstance();
|
||||
Table table = tableManager.createTable(matchOptions);
|
||||
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
|
||||
TournamentPlayer player1 = pair.getPlayer1();
|
||||
TournamentPlayer player2 = pair.getPlayer2();
|
||||
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue