summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt4
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt11
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt4
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt14
5 files changed, 26 insertions, 9 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
index ce0ef1fd..4185a6e4 100644
--- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
+++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
@@ -139,4 +139,8 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat
suspend fun unprepareMove() {
stompSession.sendEmptyMsg("/app/game/unprepareMove")
}
+
+ suspend fun leaveGame() {
+ stompSession.sendEmptyMsg("/app/game/leave")
+ }
}
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt
index b79fd381..8a5c1d93 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt
@@ -171,7 +171,7 @@ class Game internal constructor(
private fun executeEndOfAgeEvents() = table.resolveMilitaryConflicts()
- private fun endOfGameReached(): Boolean = endOfAgeReached() && table.currentAge == LAST_AGE
+ fun endOfGameReached(): Boolean = endOfAgeReached() && table.currentAge == LAST_AGE
private fun rotateHandsIfRelevant() {
// we don't rotate hands if some player can play his last card (with the special ability)
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
index 32359d58..be5d916b 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
@@ -76,6 +76,9 @@ class GameController @Autowired constructor(
logger.info("Game {}: all players have prepared their move, executing turn...", game.id)
game.playTurn()
sendTurnInfo(player.lobby.getPlayers(), game, true)
+ if (game.endOfGameReached()) {
+ player.lobby.setEndOfGame()
+ }
}
return action.move
}
@@ -105,6 +108,14 @@ class GameController @Autowired constructor(
}
}
+ @MessageMapping("/game/leave")
+ fun leave(principal: Principal) {
+ val player = principal.player
+ val game = player.game
+ player.leave()
+ logger.info("Game {}: player {} left the game", game.id, principal.name)
+ }
+
companion object {
private val logger = LoggerFactory.getLogger(GameController::class.java)
}
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt
index eadc1742..24bf5066 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt
@@ -88,6 +88,10 @@ class Lobby(
return player
}
+ fun setEndOfGame() {
+ state = State.FINISHED
+ }
+
internal class GameAlreadyStartedException(name: String) :
IllegalStateException("Game '$name' has already started")
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt
index 48592778..b9f456e5 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt
@@ -4,13 +4,9 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import org.luxons.sevenwonders.client.SevenWondersSession
-import org.luxons.sevenwonders.ui.redux.PlayerReadyEvent
-import org.luxons.sevenwonders.ui.redux.PreparedCardEvent
-import org.luxons.sevenwonders.ui.redux.PreparedMoveEvent
-import org.luxons.sevenwonders.ui.redux.RequestPrepareMove
-import org.luxons.sevenwonders.ui.redux.RequestSayReady
-import org.luxons.sevenwonders.ui.redux.RequestUnprepareMove
-import org.luxons.sevenwonders.ui.redux.TurnInfoEvent
+import org.luxons.sevenwonders.ui.redux.*
+import org.luxons.sevenwonders.ui.router.Navigate
+import org.luxons.sevenwonders.ui.router.Route
suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) {
val game = getState().gameState ?: error("Game saga run without a current game")
@@ -24,7 +20,9 @@ suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) {
launch { onEach<RequestPrepareMove> { session.prepareMove(it.move) } }
launch { onEach<RequestUnprepareMove> { session.unprepareMove() } }
- // TODO await game end and cancel this scope to unsubscribe everything
+ next<RequestLeaveGame>()
+ session.leaveGame()
+ dispatch(Navigate(Route.GAME_BROWSER))
}
console.log("End of game saga")
}
bgstack15