mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
disable timeout if game contains any non-human players
This commit is contained in:
parent
8c23757260
commit
8fd03a5bb5
2 changed files with 13 additions and 3 deletions
|
@ -85,7 +85,7 @@ public class GameController implements GameCallback {
|
|||
private UUID tableId;
|
||||
private UUID choosingPlayerId;
|
||||
private Future<?> gameFuture;
|
||||
|
||||
private boolean useTimeout = true;
|
||||
|
||||
public GameController(Game game, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
gameSessionId = UUID.randomUUID();
|
||||
|
@ -94,6 +94,12 @@ public class GameController implements GameCallback {
|
|||
this.game = game;
|
||||
this.tableId = tableId;
|
||||
this.choosingPlayerId = choosingPlayerId;
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
if (!player.isHuman()) {
|
||||
useTimeout = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -185,7 +191,7 @@ public class GameController implements GameCallback {
|
|||
|
||||
public void join(UUID userId) {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
GameSession gameSession = new GameSession(game, userId, playerId);
|
||||
GameSession gameSession = new GameSession(game, userId, playerId, useTimeout);
|
||||
gameSessions.put(playerId, gameSession);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
gameSession.setUserData(user.getUserData());
|
||||
|
|
|
@ -57,15 +57,17 @@ import mage.view.SimpleCardsView;
|
|||
public class GameSession extends GameWatcher {
|
||||
|
||||
private UUID playerId;
|
||||
private boolean useTimeout;
|
||||
|
||||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
private UserData userData;
|
||||
|
||||
public GameSession(Game game, UUID userId, UUID playerId) {
|
||||
public GameSession(Game game, UUID userId, UUID playerId, boolean useTimeout) {
|
||||
super(userId, game);
|
||||
this.playerId = playerId;
|
||||
this.useTimeout = useTimeout;
|
||||
}
|
||||
|
||||
public void ask(final String question) {
|
||||
|
@ -158,6 +160,8 @@ public class GameSession extends GameWatcher {
|
|||
}
|
||||
|
||||
private synchronized void setupTimeout() {
|
||||
if (!useTimeout)
|
||||
return;
|
||||
cancelTimeout();
|
||||
futureTimeout = timeoutExecutor.schedule(
|
||||
new Runnable() {
|
||||
|
|
Loading…
Reference in a new issue