fix: remove major flaw in state manipulation

This commit is contained in:
2021-06-04 06:41:59 +02:00
parent 4eb71fa972
commit b20b428705
2 changed files with 66 additions and 23 deletions

View File

@ -99,7 +99,8 @@ class GameStateManager {
* @return The optionally resulting {@link Event Events}
*/
public ArrayList<Event> checkPostPhase() {
ArrayList<Event> result = GameLogic.checkTurnEnd(state);
GameState snapshot = state.snapshot();
ArrayList<Event> result = GameLogic.checkTurnEnd(snapshot);
applyEvents(result);
return result;
}
@ -111,10 +112,14 @@ class GameStateManager {
* @return The resulting {@link Event Events}
*/
public ArrayList<Event> startGame(ArrayList<Integer> selectedCharacters1, ArrayList<Integer> selectedCharacters2) {
ArrayList<Event> result = GameLogic.startGame(state, selectedCharacters1, selectedCharacters2);
GameState snapshot = state.snapshot();
ArrayList<Event> result = GameLogic.startGame(snapshot, selectedCharacters1, selectedCharacters2);
applyEvents(result);
ArrayList<Event> result2 = GameLogic.startRound(state);
snapshot = state.snapshot();
ArrayList<Event> result2 = GameLogic.startRound(snapshot);
applyEvents(result2);
result.addAll(result2);
@ -127,7 +132,8 @@ class GameStateManager {
* @return The resulting {@link Event Events}
*/
public ArrayList<Event> endTurn() {
ArrayList<Event> result = GameLogic.endTurn(state);
GameState snapshot = state.snapshot();
ArrayList<Event> result = GameLogic.endTurn(snapshot);
applyEvents(result);
return result;
}