summaryrefslogtreecommitdiff
path: root/sw-server/src/main/kotlin/org
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2020-12-12 02:03:45 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2020-12-12 02:44:13 +0100
commit9ba1b1251d16956fe3b9cd07f198577b63d4a486 (patch)
treea780a985f022a8ab9699a8990174630089e5feb3 /sw-server/src/main/kotlin/org
parentImprove score board tags colors (diff)
downloadseven-wonders-9ba1b1251d16956fe3b9cd07f198577b63d4a486.tar.gz
seven-wonders-9ba1b1251d16956fe3b9cd07f198577b63d4a486.tar.bz2
seven-wonders-9ba1b1251d16956fe3b9cd07f198577b63d4a486.zip
Make ready button optional (server side)
Resolves: https://github.com/joffrey-bion/seven-wonders/issues/63
Diffstat (limited to 'sw-server/src/main/kotlin/org')
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt1
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt17
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt15
3 files changed, 27 insertions, 6 deletions
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt
index 12f346a2..5689247b 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt
@@ -13,6 +13,7 @@ fun Lobby.toDTO(): LobbyDTO = LobbyDTO(
players = getPlayers().zip(getAssignedWonders()).map { (p, w) -> p.toDTO(w) },
allWonders = allWonders,
state = state,
+ settings = settings,
hasEnoughPlayers = hasEnoughPlayers(),
maxPlayersReached = maxPlayersReached(),
)
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 51e8ba4f..94ebceab 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
@@ -31,14 +31,20 @@ class GameController(
@MessageMapping("/game/sayReady")
fun ready(principal: Principal) {
val player = principal.player
- player.isReady = true
+ val lobby = player.lobby
+ if (!lobby.settings.askForReadiness) {
+ logger.warn("Game {}: player {} is saying ready but readiness concept is disabled", lobby.id, player)
+ return
+ }
+
val game = player.game
- logger.info("Game {}: player {} is ready for the next turn", game.id, player)
+ player.isReady = true
- synchronized(player.lobby) {
- val players = player.lobby.getPlayers()
+ synchronized(lobby) {
+ val players = lobby.getPlayers()
sendPlayerReady(game.id, player)
+ logger.info("Game {}: player {} is ready for the next turn", game.id, player)
val allReady = players.all { it.isReady }
if (allReady) {
@@ -58,6 +64,7 @@ class GameController(
@MessageMapping("/game/prepareMove")
fun prepareMove(action: PrepareMoveAction, principal: Principal) {
val player = principal.player
+ val lobby = player.lobby
val game = player.game
synchronized(game) {
val preparedCardBack = game.prepareMove(player.index, action.move)
@@ -68,7 +75,7 @@ class GameController(
if (game.allPlayersPreparedTheirMove()) {
logger.info("Game {}: all players have prepared their move, executing turn...", game.id)
game.playTurn()
- sendTurnInfo(player.lobby.getPlayers(), game, true)
+ sendTurnInfo(player.lobby.getPlayers(), game, hideHands = lobby.settings.askForReadiness)
if (game.endOfGameReached()) {
player.lobby.setEndOfGame()
}
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
index 6cc404e9..f73d5481 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
@@ -156,12 +156,25 @@ class LobbyController(
val game = lobby.startGame()
logger.info("Game {} successfully started", game.id)
- game.getCurrentTurnInfo().hideHandsAndWaitForReadiness().forEach {
+ val currentTurnInfo = game.getCurrentTurnInfo().let {
+ if (lobby.settings.askForReadiness) it.hideHandsAndWaitForReadiness() else it
+ }
+
+ // even if we don't care about ready state for business logic, the UI may use it nonetheless
+ lobby.initializePlayersReadyState()
+
+ currentTurnInfo.forEach {
val player = lobby.getPlayers()[it.playerIndex]
template.convertAndSendToUser(player.username, "/queue/lobby/" + lobby.id + "/started", it)
}
}
+ private fun Lobby.initializePlayersReadyState() {
+ val players = getPlayers()
+ val initialReadyState = !settings.askForReadiness
+ players.forEach { it.isReady = initialReadyState }
+ }
+
companion object {
private val logger = LoggerFactory.getLogger(LobbyController::class.java)
}
bgstack15