mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Server: fixed correct game finish on no players in game (rare race conditional);
This commit is contained in:
parent
7670619fc6
commit
0496ea9509
1 changed files with 14 additions and 3 deletions
|
@ -799,14 +799,23 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void play(UUID nextPlayerId) {
|
protected void play(UUID nextPlayerId) {
|
||||||
|
boolean forcedToFinished = false;
|
||||||
if (!isPaused() && !checkIfGameIsOver()) {
|
if (!isPaused() && !checkIfGameIsOver()) {
|
||||||
playerList = state.getPlayerList(nextPlayerId);
|
playerList = state.getPlayerList(nextPlayerId);
|
||||||
Player playerByOrder = getPlayer(playerList.get());
|
Player playerByOrder = getPlayer(playerList.get());
|
||||||
state.setPlayerByOrderId(playerByOrder.getId());
|
state.setPlayerByOrderId(playerByOrder == null ? null : playerByOrder.getId());
|
||||||
|
|
||||||
|
// PLAY game
|
||||||
while (!isPaused() && !checkIfGameIsOver()) {
|
while (!isPaused() && !checkIfGameIsOver()) {
|
||||||
if (!playExtraTurns()) {
|
if (!playExtraTurns()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (playerByOrder == null) {
|
||||||
|
logger.error("Can't find next player by order, but game stil run. Finish it.");
|
||||||
|
forcedToFinished = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, playerByOrder.getId());
|
GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, playerByOrder.getId());
|
||||||
if (!replaceEvent(event)) {
|
if (!replaceEvent(event)) {
|
||||||
if (!playTurn(playerByOrder)) {
|
if (!playTurn(playerByOrder)) {
|
||||||
|
@ -822,7 +831,9 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkIfGameIsOver() && !isSimulation()) {
|
|
||||||
|
// END game
|
||||||
|
if (checkIfGameIsOver() && !isSimulation() || forcedToFinished) {
|
||||||
winnerId = findWinnersAndLosers();
|
winnerId = findWinnersAndLosers();
|
||||||
StringBuilder sb = new StringBuilder("GAME END gameId: ").append(this.getId()).append(' ');
|
StringBuilder sb = new StringBuilder("GAME END gameId: ").append(this.getId()).append(' ');
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
Loading…
Reference in a new issue