mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Added possibility to show tournament panel and watch tournament games (if allowed at tournament start) for spectators .
This commit is contained in:
parent
001f8ec1e6
commit
9838dea551
24 changed files with 520 additions and 311 deletions
|
|
@ -640,6 +640,17 @@ public class MageServerImpl implements MageServer {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTournamentTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return TableManager.getInstance().watchTable(userId, tableId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("watchGame", sessionId, new Action() {
|
||||
|
|
|
|||
|
|
@ -257,15 +257,24 @@ public class TableController {
|
|||
}
|
||||
|
||||
public boolean watchTable(UUID userId) {
|
||||
if (table.getState() != TableState.DUELING) {
|
||||
return false;
|
||||
if (table.isTournament()) {
|
||||
UserManager.getInstance().getUser(userId).showTournament(table.getTournament().getId());
|
||||
return true;
|
||||
} else {
|
||||
if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) {
|
||||
return false;
|
||||
}
|
||||
if (table.getState() != TableState.DUELING) {
|
||||
return false;
|
||||
}
|
||||
// you can't watch your own game
|
||||
if (userPlayerMap.get(userId) != null) {
|
||||
return false;
|
||||
}
|
||||
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
|
||||
return true;
|
||||
|
||||
}
|
||||
// you can't watch your own game
|
||||
if (userPlayerMap.get(userId) != null) {
|
||||
return false;
|
||||
}
|
||||
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean replayTable(UUID userId) {
|
||||
|
|
@ -464,7 +473,6 @@ public class TableController {
|
|||
public void endGame() {
|
||||
// get player that chooses who goes first
|
||||
UUID choosingPlayerId = match.getChooser();
|
||||
logger.warn("endGame() " + match.getPlayers().toString());
|
||||
match.endGame();
|
||||
table.endGame();
|
||||
// Saving of games caused memory leaks - so save is deactivated
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ public class TableManager {
|
|||
List<UUID> toRemove = new ArrayList<UUID>();
|
||||
for (Table table : tables.values()) {
|
||||
if (!table.getState().equals(TableState.FINISHED)) {
|
||||
// remove all tables created more than expire_time ago
|
||||
// remove all not finished tables created more than expire_time ago
|
||||
long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
|
||||
if (diff >= EXPIRE_TIME) {
|
||||
logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
|
||||
|
|
@ -319,8 +319,8 @@ public class TableManager {
|
|||
if (player != null && player.isHuman()) {
|
||||
canBeRemoved = false;
|
||||
}
|
||||
// tournament sub tables may not be removed, will be done by the tournament itself
|
||||
if(table.isTournamentSubTable()){
|
||||
// tournament sub tables may not be removed as long the tournament is not finished
|
||||
if(table.isTournamentSubTable() && table.getTournament().getEndTime() == null) {
|
||||
canBeRemoved = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,10 @@ public class User {
|
|||
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time)));
|
||||
}
|
||||
|
||||
public void showTournament(final UUID tournamentId) {
|
||||
fireCallback(new ClientCallback("showTournament", tournamentId));
|
||||
}
|
||||
|
||||
public void watchGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("watchGame", gameId));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,6 +309,10 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
|
||||
public void watch(UUID userId) {
|
||||
if (userPlayerMap.get(userId) != null) {
|
||||
// You can't watch a game if you already a player in it
|
||||
return;
|
||||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
GameWatcher gameWatcher = new GameWatcher(userId, game);
|
||||
|
|
|
|||
|
|
@ -197,12 +197,14 @@ public class TournamentController {
|
|||
TableManager tableManager = TableManager.getInstance();
|
||||
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
|
||||
table.setTournamentSubTable(true);
|
||||
table.setTournament(tournament);
|
||||
TournamentPlayer player1 = pair.getPlayer1();
|
||||
TournamentPlayer player2 = pair.getPlayer2();
|
||||
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
|
||||
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
|
||||
tableManager.startMatch(null, table.getId());
|
||||
pair.setMatch(tableManager.getMatch(table.getId()));
|
||||
pair.setTableId(table.getId());
|
||||
player1.setState(TournamentPlayerState.DUELING);
|
||||
player2.setState(TournamentPlayerState.DUELING);
|
||||
} catch (GameException ex) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue