mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
* Server: fixed that multiplayer game can be closed on "1x human + 1x AI" remain (see #6178);
This commit is contained in:
parent
3da525520c
commit
e488997124
2 changed files with 21 additions and 12 deletions
|
@ -48,7 +48,7 @@ public class TableController {
|
|||
private final UUID chatId;
|
||||
private final String controllerName;
|
||||
private final Table table;
|
||||
private final ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<>(); // human players only, use table.seats for AI
|
||||
|
||||
private Match match;
|
||||
private MatchOptions options;
|
||||
|
@ -985,10 +985,14 @@ public class TableController {
|
|||
// return false;
|
||||
}
|
||||
}
|
||||
|
||||
// check for active players
|
||||
int validHumanPlayers = 0;
|
||||
int validAIPlayers = 0;
|
||||
int aiPlayers = 0;
|
||||
int humanPlayers = 0;
|
||||
|
||||
// check humans
|
||||
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
|
||||
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
||||
if (matchPlayer == null) {
|
||||
|
@ -1016,12 +1020,21 @@ public class TableController {
|
|||
// user exits on the server and match player has not quit -> player is valid
|
||||
validHumanPlayers++;
|
||||
}
|
||||
} else {
|
||||
aiPlayers++;
|
||||
}
|
||||
}
|
||||
// if at least 2 human players are valid (multiplayer) or all human players are valid the table is valid or it's an AI match
|
||||
return validHumanPlayers >= 2 || validHumanPlayers == humanPlayers || aiPlayers > 1;
|
||||
|
||||
// check AI
|
||||
for (MatchPlayer matchPlayer : match.getPlayers()) {
|
||||
if (!matchPlayer.getPlayer().isHuman()) {
|
||||
aiPlayers++;
|
||||
if (matchPlayer.getPlayer().isInGame()) {
|
||||
validAIPlayers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// table must contain minimum two active players
|
||||
return (validAIPlayers + validHumanPlayers) >= 2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -47,12 +47,8 @@ public class TableManagerImpl implements TableManager {
|
|||
private final ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<>();
|
||||
private final ReadWriteLock tablesLock = new ReentrantReadWriteLock();
|
||||
|
||||
/**
|
||||
* Defines how often checking process should be run on server.
|
||||
* <p>
|
||||
* In minutes.
|
||||
*/
|
||||
private static final int EXPIRE_CHECK_PERIOD = 10;
|
||||
// defines how often checking process should be run on server (in minutes)
|
||||
private static final int TABLE_HEALTH_CHECK_TIMEOUT_MINS = 10;
|
||||
|
||||
public TableManagerImpl(ManagerFactory managerFactory) {
|
||||
this.managerFactory = managerFactory;
|
||||
|
@ -66,7 +62,7 @@ public class TableManagerImpl implements TableManager {
|
|||
} catch (Exception ex) {
|
||||
logger.fatal("Check table health state job error:", ex);
|
||||
}
|
||||
}, EXPIRE_CHECK_PERIOD, EXPIRE_CHECK_PERIOD, TimeUnit.MINUTES);
|
||||
}, TABLE_HEALTH_CHECK_TIMEOUT_MINS, TABLE_HEALTH_CHECK_TIMEOUT_MINS, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue