refactor: simplified extra turn code, fixed NPE error on usage (Alchemist's Gambit)

This commit is contained in:
Oleg Agafonov 2023-06-30 06:26:48 +04:00
parent ad461498b0
commit 6529ead72f
9 changed files with 100 additions and 107 deletions

View file

@ -1033,25 +1033,26 @@ public abstract class GameImpl implements Game {
private boolean playExtraTurns() {
//20091005 - 500.7
TurnMod extraTurn = getNextExtraTurn();
while (extraTurn != null) {
GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, extraTurn.getPlayerId());
if (!replaceEvent(event)) {
Player extraPlayer = this.getPlayer(extraTurn.getPlayerId());
if (extraPlayer != null && extraPlayer.canRespond()) {
state.setExtraTurn(true);
state.setTurnId(extraTurn.getId());
if (!this.isSimulation()) {
informPlayers(extraPlayer.getLogName() + " takes an extra turn");
}
if (!playTurn(extraPlayer)) {
return false;
try {
while (extraTurn != null) {
GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, extraTurn.getPlayerId());
if (!replaceEvent(event)) {
Player extraPlayer = this.getPlayer(extraTurn.getPlayerId());
if (extraPlayer != null && extraPlayer.canRespond()) {
state.setExtraTurnId(extraTurn.getId());
if (!this.isSimulation()) {
informPlayers(extraPlayer.getLogName() + " takes an extra turn");
}
if (!playTurn(extraPlayer)) {
return false;
}
}
}
extraTurn = getNextExtraTurn();
}
extraTurn = getNextExtraTurn();
} finally {
state.setExtraTurnId(null);
}
state.setTurnId(null);
state.setExtraTurn(false);
return true;
}