mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
* Game watching - Show number of games watched by player in player list.
This commit is contained in:
parent
83be13a68b
commit
3a5dd428e6
4 changed files with 25 additions and 4 deletions
|
@ -337,9 +337,7 @@ public class TableController {
|
|||
if (userPlayerMap.get(userId) != null) {
|
||||
return false;
|
||||
}
|
||||
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
|
||||
return true;
|
||||
|
||||
return UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
package mage.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -75,6 +76,7 @@ public class User {
|
|||
private final Map<UUID, TournamentSession> tournamentSessions;
|
||||
private final Map<UUID, TournamentSession> constructing;
|
||||
private final Map<UUID, Deck> sideboarding;
|
||||
private final List<UUID> watchedGames;
|
||||
|
||||
private String sessionId;
|
||||
private String info;
|
||||
|
@ -97,6 +99,7 @@ public class User {
|
|||
this.tournamentSessions = new ConcurrentHashMap<>();
|
||||
this.constructing = new ConcurrentHashMap<>();
|
||||
this.sideboarding = new ConcurrentHashMap<>();
|
||||
this.watchedGames = new ArrayList<>();
|
||||
|
||||
this.sessionId = "";
|
||||
}
|
||||
|
@ -205,8 +208,9 @@ public class User {
|
|||
fireCallback(new ClientCallback("showUserMessage", null, messageData ));
|
||||
}
|
||||
|
||||
public void watchGame(final UUID gameId) {
|
||||
public boolean watchGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("watchGame", gameId));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replayGame(final UUID gameId) {
|
||||
|
@ -405,6 +409,10 @@ public class User {
|
|||
if (tournament > 0) {
|
||||
sb.append("TP: ").append(tournament).append(" ");
|
||||
}
|
||||
if (watchedGames.size() > 0) {
|
||||
sb.append("WA: ").append(watchedGames.size()).append(" ");
|
||||
}
|
||||
|
||||
sb.append(disconnectInfo);
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -416,4 +424,12 @@ public class User {
|
|||
public void setInfo(String Info) {
|
||||
this.info = Info;
|
||||
}
|
||||
|
||||
public void addGameWatchInfo(UUID gameId) {
|
||||
watchedGames.add(gameId);
|
||||
}
|
||||
|
||||
public void removeGameWatchInfo(UUID gameId) {
|
||||
watchedGames.remove(gameId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,11 +336,16 @@ public class GameController implements GameCallback {
|
|||
// You can't watch a game if you already a player in it
|
||||
return;
|
||||
}
|
||||
if (watchers.get(userId) != null) {
|
||||
// You can't watch a game if you already watch it
|
||||
return;
|
||||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
GameWatcher gameWatcher = new GameWatcher(userId, game, false);
|
||||
watchers.put(userId, gameWatcher);
|
||||
gameWatcher.init();
|
||||
user.addGameWatchInfo(game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
||||
}
|
||||
}
|
||||
|
@ -349,6 +354,7 @@ public class GameController implements GameCallback {
|
|||
watchers.remove(userId);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.removeGameWatchInfo(game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ public class GameWatcher {
|
|||
if (!killed) {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.removeGameWatchInfo(game.getId());
|
||||
user.fireCallback(new ClientCallback("gameOver", game.getId(), message));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue