mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* Fixed wrong timer handling while other player controlled a player's turn. Attackers now marked with blue frame. Playable cards have a violet frame. If a player has to select cards from hand, the possible cards are marked yellow now. Discard of multiple cards now marks already selected cards and happens in one selection.
This commit is contained in:
parent
194efe6237
commit
67479bb5a4
20 changed files with 205 additions and 163 deletions
|
|
@ -44,7 +44,7 @@ import mage.interfaces.callback.ClientCallback;
|
|||
import mage.players.net.UserData;
|
||||
import mage.server.draft.DraftSession;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.GameSession;
|
||||
import mage.server.game.GameSessionPlayer;
|
||||
import mage.server.tournament.TournamentSession;
|
||||
import mage.server.util.SystemUtil;
|
||||
import mage.view.TableClientMessage;
|
||||
|
|
@ -68,7 +68,7 @@ public class User {
|
|||
private final String host;
|
||||
private final Date connectionTime;
|
||||
private final Map<UUID, Table> tables;
|
||||
private final Map<UUID, GameSession> gameSessions;
|
||||
private final Map<UUID, GameSessionPlayer> gameSessions;
|
||||
private final Map<UUID, DraftSession> draftSessions;
|
||||
private final Map<UUID, TournamentSession> tournamentSessions;
|
||||
private final Map<UUID, TournamentSession> constructing;
|
||||
|
|
@ -269,7 +269,7 @@ public class User {
|
|||
entry.getValue().update();
|
||||
}
|
||||
|
||||
for (Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
for (Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
|
||||
gameStarted(entry.getValue().getGameId(), entry.getKey());
|
||||
entry.getValue().init();
|
||||
GameManager.getInstance().sendPlayerString(entry.getValue().getGameId(), userId, "");
|
||||
|
|
@ -290,7 +290,7 @@ public class User {
|
|||
}
|
||||
}
|
||||
|
||||
public void addGame(UUID playerId, GameSession gameSession) {
|
||||
public void addGame(UUID playerId, GameSessionPlayer gameSession) {
|
||||
gameSessions.put(playerId, gameSession);
|
||||
}
|
||||
|
||||
|
|
@ -336,7 +336,7 @@ public class User {
|
|||
|
||||
public void remove(DisconnectReason reason) {
|
||||
logger.debug("REMOVE " + getName() + " Game sessions: " + gameSessions.size() );
|
||||
for (GameSession gameSession: gameSessions.values()) {
|
||||
for (GameSessionPlayer gameSession: gameSessions.values()) {
|
||||
logger.debug("-- kill game session of gameId: " + gameSession.getGameId() );
|
||||
gameSession.quitGame();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,8 +95,8 @@ public class GameController implements GameCallback {
|
|||
private static final ExecutorService gameExecutor = ThreadExecutor.getInstance().getGameExecutor();
|
||||
private static final Logger logger = Logger.getLogger(GameController.class);
|
||||
|
||||
private ConcurrentHashMap<UUID, GameSession> gameSessions = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<UUID, GameWatcher> watchers = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<UUID, GameSessionPlayer> gameSessions = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<UUID, GameSessionWatcher> watchers = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<UUID, PriorityTimer> timers = new ConcurrentHashMap<>();
|
||||
|
||||
private ConcurrentHashMap<UUID, UUID> userPlayerMap;
|
||||
|
|
@ -300,10 +300,10 @@ public class GameController implements GameCallback {
|
|||
logger.fatal("Player not found - playerId: " +playerId);
|
||||
return;
|
||||
}
|
||||
GameSession gameSession = gameSessions.get(playerId);
|
||||
GameSessionPlayer gameSession = gameSessions.get(playerId);
|
||||
String joinType;
|
||||
if (gameSession == null) {
|
||||
gameSession = new GameSession(game, userId, playerId, useTimeout);
|
||||
gameSession = new GameSessionPlayer(game, userId, playerId, useTimeout);
|
||||
gameSessions.put(playerId, gameSession);
|
||||
gameSession.setUserData(user.getUserData());
|
||||
joinType = "joined";
|
||||
|
|
@ -318,7 +318,7 @@ public class GameController implements GameCallback {
|
|||
|
||||
private synchronized void startGame() {
|
||||
if (gameFuture == null) {
|
||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
for (final Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
|
||||
if (!entry.getValue().init()) {
|
||||
logger.fatal("Unable to initialize client");
|
||||
//TODO: generate client error message
|
||||
|
|
@ -363,7 +363,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
GameWatcher gameWatcher = new GameWatcher(userId, game, false);
|
||||
GameSessionWatcher gameWatcher = new GameSessionWatcher(userId, game, false);
|
||||
watchers.put(userId, gameWatcher);
|
||||
gameWatcher.init();
|
||||
user.addGameWatchInfo(game.getId());
|
||||
|
|
@ -400,7 +400,7 @@ public class GameController implements GameCallback {
|
|||
public void quitMatch(UUID userId) {
|
||||
UUID playerId = getPlayerId(userId);
|
||||
if (playerId != null) {
|
||||
GameSession gameSession = gameSessions.get(playerId);
|
||||
GameSessionPlayer gameSession = gameSessions.get(playerId);
|
||||
if (gameSession != null) {
|
||||
gameSession.quitGame();
|
||||
}
|
||||
|
|
@ -456,7 +456,7 @@ public class GameController implements GameCallback {
|
|||
if (grantingPlayer != null) {
|
||||
if (!grantingPlayer.getUsersAllowedToSeeHandCards().contains(userIdRequester)) {
|
||||
if (grantingPlayer.isHuman()) {
|
||||
GameSession gameSession = gameSessions.get(userIdGranter);
|
||||
GameSessionPlayer gameSession = gameSessions.get(userIdGranter);
|
||||
if (gameSession != null) {
|
||||
UUID requestingPlayer = getPlayerId(userIdRequester);
|
||||
if (requestingPlayer == null || !requestingPlayer.equals(grantingPlayer.getId())) { // don't allow request for your own cards
|
||||
|
|
@ -527,11 +527,11 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
|
||||
public void endGame(final String message) throws MageException {
|
||||
for (final GameSession gameSession: gameSessions.values()) {
|
||||
for (final GameSessionPlayer gameSession: gameSessions.values()) {
|
||||
gameSession.gameOver(message);
|
||||
gameSession.removeGame();
|
||||
}
|
||||
for (final GameWatcher gameWatcher: watchers.values()) {
|
||||
for (final GameSessionWatcher gameWatcher: watchers.values()) {
|
||||
gameWatcher.gameOver(message);
|
||||
}
|
||||
TableManager.getInstance().endGame(tableId);
|
||||
|
|
@ -601,10 +601,10 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (final GameSession gameSession: gameSessions.values()) {
|
||||
for (final GameSessionPlayer gameSession: gameSessions.values()) {
|
||||
gameSession.update();
|
||||
}
|
||||
for (final GameWatcher gameWatcher: watchers.values()) {
|
||||
for (final GameSessionWatcher gameWatcher: watchers.values()) {
|
||||
gameWatcher.update();
|
||||
}
|
||||
}
|
||||
|
|
@ -613,7 +613,7 @@ public class GameController implements GameCallback {
|
|||
Table table = TableManager.getInstance().getTable(tableId);
|
||||
if (table != null) {
|
||||
if (table.getMatch() != null) {
|
||||
for (final GameSession gameSession: gameSessions.values()) {
|
||||
for (final GameSessionPlayer gameSession: gameSessions.values()) {
|
||||
gameSession.endGameInfo(table);
|
||||
}
|
||||
}
|
||||
|
|
@ -741,12 +741,12 @@ public class GameController implements GameCallback {
|
|||
message.append(game.getStep().getType().toString()).append(" - ");
|
||||
}
|
||||
message.append("Waiting for ").append(game.getPlayer(playerId).getName());
|
||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
for (final Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
|
||||
if (!entry.getKey().equals(playerId)) {
|
||||
entry.getValue().inform(message.toString());
|
||||
}
|
||||
}
|
||||
for (final GameWatcher watcher: watchers.values()) {
|
||||
for (final GameSessionWatcher watcher: watchers.values()) {
|
||||
watcher.inform(message.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -761,7 +761,7 @@ public class GameController implements GameCallback {
|
|||
return;
|
||||
}
|
||||
final String message = new StringBuilder(game.getStep().getType().toString()).append(" - Waiting for ").append(controller.getName()).toString();
|
||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
for (final Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
|
||||
boolean skip = false;
|
||||
for (UUID uuid : players) {
|
||||
if (entry.getKey().equals(uuid)) {
|
||||
|
|
@ -773,7 +773,7 @@ public class GameController implements GameCallback {
|
|||
entry.getValue().inform(message);
|
||||
}
|
||||
}
|
||||
for (final GameWatcher watcher: watchers.values()) {
|
||||
for (final GameSessionWatcher watcher: watchers.values()) {
|
||||
watcher.inform(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -795,7 +795,7 @@ public class GameController implements GameCallback {
|
|||
for (StackTraceElement e: ex.getStackTrace()) {
|
||||
sb.append(e.toString()).append("\n");
|
||||
}
|
||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
for (final Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
|
||||
entry.getValue().gameError(sb.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -898,7 +898,7 @@ public class GameController implements GameCallback {
|
|||
void execute(UUID player);
|
||||
}
|
||||
|
||||
private GameSession getGameSession(UUID playerId) {
|
||||
private GameSessionPlayer getGameSession(UUID playerId) {
|
||||
if (!timers.isEmpty()) {
|
||||
Player player = game.getState().getPlayer(playerId);
|
||||
PriorityTimer timer = timers.get(playerId);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import mage.game.Table;
|
|||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.Player;
|
||||
import mage.players.net.UserData;
|
||||
import mage.server.Main;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
|
|
@ -66,9 +67,9 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameSession extends GameWatcher {
|
||||
public class GameSessionPlayer extends GameSessionWatcher {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(GameSession.class);
|
||||
private static final Logger logger = Logger.getLogger(GameSessionPlayer.class);
|
||||
|
||||
private final UUID playerId;
|
||||
private final boolean useTimeout;
|
||||
|
|
@ -79,7 +80,7 @@ public class GameSession extends GameWatcher {
|
|||
|
||||
private UserData userData;
|
||||
|
||||
public GameSession(Game game, UUID userId, UUID playerId, boolean useTimeout) {
|
||||
public GameSessionPlayer(Game game, UUID userId, UUID playerId, boolean useTimeout) {
|
||||
super(userId, game, true);
|
||||
this.playerId = playerId;
|
||||
this.useTimeout = useTimeout;
|
||||
|
|
@ -228,7 +229,8 @@ public class GameSession extends GameWatcher {
|
|||
}
|
||||
}
|
||||
},
|
||||
ConfigSettings.getInstance().getMaxSecondsIdle(), TimeUnit.SECONDS
|
||||
Main.isTestMode() ? 3600 :ConfigSettings.getInstance().getMaxSecondsIdle(),
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -269,7 +271,9 @@ public class GameSession extends GameWatcher {
|
|||
player.setUserData(this.userData);
|
||||
GameView gameView = new GameView(game.getState(), game, playerId, null);
|
||||
gameView.setHand(new CardsView(player.getHand().getCards(game)));
|
||||
gameView.setCanPlayInHand(player.getPlayableInHand(game));
|
||||
if (gameView.getPriorityPlayerName().equals(player.getName())) {
|
||||
gameView.setCanPlayInHand(player.getPlayableInHand(game));
|
||||
}
|
||||
|
||||
processControlledPlayers(player, gameView);
|
||||
processWatchedHands(userId, gameView);
|
||||
|
|
@ -47,16 +47,16 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameWatcher {
|
||||
public class GameSessionWatcher {
|
||||
|
||||
protected final static Logger logger = Logger.getLogger(GameWatcher.class);
|
||||
protected final static Logger logger = Logger.getLogger(GameSessionWatcher.class);
|
||||
|
||||
protected UUID userId;
|
||||
protected Game game;
|
||||
protected boolean killed = false;
|
||||
protected boolean isPlayer;
|
||||
|
||||
public GameWatcher(UUID userId, Game game, boolean isPlayer) {
|
||||
public GameSessionWatcher(UUID userId, Game game, boolean isPlayer) {
|
||||
this.userId = userId;
|
||||
this.game = game;
|
||||
this.isPlayer = isPlayer;
|
||||
Loading…
Add table
Add a link
Reference in a new issue