summaryrefslogtreecommitdiff
path: root/sw-common-model/src/commonMain/kotlin/org
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-28 20:26:29 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-31 11:16:00 +0200
commit36103b92ce4b6cd00925d861f4fb5e381cdc4833 (patch)
tree4c2bfced8317526b24da23fcef9febe6368c736e /sw-common-model/src/commonMain/kotlin/org
parentAttempt at fixing race conditions with bot subscriptions (diff)
downloadseven-wonders-36103b92ce4b6cd00925d861f4fb5e381cdc4833.tar.gz
seven-wonders-36103b92ce4b6cd00925d861f4fb5e381cdc4833.tar.bz2
seven-wonders-36103b92ce4b6cd00925d861f4fb5e381cdc4833.zip
Simplify settings and allow choosing wonders
Diffstat (limited to 'sw-common-model/src/commonMain/kotlin/org')
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt47
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt18
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt (renamed from sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt)26
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt28
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt21
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt2
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt31
7 files changed, 97 insertions, 76 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt
deleted file mode 100644
index 86a11bc1..00000000
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/CustomizableSettings.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.luxons.sevenwonders.model
-
-import kotlinx.serialization.Serializable
-import kotlin.random.Random
-
-@Serializable
-data class CustomizableSettings(
- val randomSeedForTests: Long? = null,
- val timeLimitInSeconds: Int = 45,
- val wonderSidePickMethod: WonderSidePickMethod = WonderSidePickMethod.EACH_RANDOM,
- val initialGold: Int = 3,
- val discardedCardGold: Int = 3,
- val defaultTradingCost: Int = 2,
- val pointsPer3Gold: Int = 1,
- val lostPointsPerDefeat: Int = 1,
- val wonPointsPerVictoryPerAge: Map<Int, Int> = mapOf(1 to 1, 2 to 3, 3 to 5)
-)
-
-enum class WonderSide {
- A,
- B
-}
-
-enum class WonderSidePickMethod {
- ALL_A {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return WonderSide.A
- }
- },
- ALL_B {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return WonderSide.B
- }
- },
- EACH_RANDOM {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return if (random.nextBoolean()) WonderSide.A else WonderSide.B
- }
- },
- SAME_RANDOM_FOR_ALL {
- override fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide {
- return lastPickedSide ?: if (random.nextBoolean()) WonderSide.A else WonderSide.B
- }
- };
-
- abstract fun pickSide(random: Random, lastPickedSide: WonderSide?): WonderSide
-}
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt
new file mode 100644
index 00000000..21be1c1b
--- /dev/null
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Settings.kt
@@ -0,0 +1,18 @@
+package org.luxons.sevenwonders.model
+
+import kotlinx.serialization.Serializable
+import kotlin.random.Random
+
+@Serializable
+data class Settings(
+ val randomSeedForTests: Long? = null,
+ val timeLimitInSeconds: Int = 45,
+ val initialGold: Int = 3,
+ val discardedCardGold: Int = 3,
+ val defaultTradingCost: Int = 2,
+ val pointsPer3Gold: Int = 1,
+ val lostPointsPerDefeat: Int = 1,
+ val wonPointsPerVictoryPerAge: Map<Int, Int> = mapOf(1 to 1, 2 to 3, 3 to 5)
+) {
+ val random: Random by lazy { randomSeedForTests?.let { Random(it) } ?: Random }
+}
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt
index d22a350a..1438600a 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt
@@ -1,7 +1,7 @@
package org.luxons.sevenwonders.model.api
import kotlinx.serialization.Serializable
-import org.luxons.sevenwonders.model.api.actions.Icon
+import org.luxons.sevenwonders.model.wonders.PreGameWonder
const val SEVEN_WONDERS_WS_ENDPOINT = "/seven-wonders-websocket"
@@ -15,6 +15,7 @@ data class LobbyDTO(
val name: String,
val owner: String,
val players: List<PlayerDTO>,
+ val allWonders: List<PreGameWonder>,
val state: State,
val hasEnoughPlayers: Boolean,
val maxPlayersReached: Boolean
@@ -43,26 +44,3 @@ data class Actionability(
val canDo: Boolean,
val tooltip: String
)
-
-interface BasicPlayerInfo {
- val username: String
- val displayName: String
- val icon: Icon?
-}
-
-@Serializable
-data class ConnectedPlayer(
- override val username: String,
- override val displayName: String,
- override val icon: Icon?
-) : BasicPlayerInfo
-
-@Serializable
-data class PlayerDTO(
- override val username: String,
- override val displayName: String,
- override val icon: Icon?,
- val index: Int,
- val isGameOwner: Boolean,
- val isReady: Boolean
-) : BasicPlayerInfo
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt
new file mode 100644
index 00000000..7161b53d
--- /dev/null
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Player.kt
@@ -0,0 +1,28 @@
+package org.luxons.sevenwonders.model.api
+
+import kotlinx.serialization.Serializable
+import org.luxons.sevenwonders.model.api.actions.Icon
+import org.luxons.sevenwonders.model.wonders.AssignedWonder
+
+interface BasicPlayerInfo {
+ val username: String
+ val displayName: String
+ val icon: Icon?
+}
+
+@Serializable
+data class ConnectedPlayer(
+ override val username: String,
+ override val displayName: String,
+ override val icon: Icon?
+) : BasicPlayerInfo
+
+@Serializable
+data class PlayerDTO(
+ override val username: String,
+ override val displayName: String,
+ override val icon: Icon?,
+ val wonder: AssignedWonder,
+ val isGameOwner: Boolean,
+ val isReady: Boolean
+) : BasicPlayerInfo
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt
index 0687e968..4a721a94 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/actions/Actions.kt
@@ -1,7 +1,8 @@
package org.luxons.sevenwonders.model.api.actions
import kotlinx.serialization.Serializable
-import org.luxons.sevenwonders.model.CustomizableSettings
+import org.luxons.sevenwonders.model.wonders.AssignedWonder
+import org.luxons.sevenwonders.model.Settings
import org.luxons.sevenwonders.model.PlayerMove
/**
@@ -58,8 +59,8 @@ class PrepareMoveAction(
)
/**
- * The action to update the order of the players around the table. Can only be called in the lobby by the owner of the
- * game.
+ * The action to update the order of the players around the table.
+ * Can only be called in the lobby by the owner of the game.
*/
@Serializable
class ReorderPlayersAction(
@@ -70,6 +71,18 @@ class ReorderPlayersAction(
)
/**
+ * The action to update the wonders assigned to each player.
+ * Can only be called in the lobby by the owner of the game.
+ */
+@Serializable
+class ReassignWondersAction(
+ /**
+ * The list of wonders assigned to each player, in the players' order.
+ */
+ val assignedWonders: List<AssignedWonder>
+)
+
+/**
* The action to update the settings of the game. Can only be called in the lobby by the owner of the game.
*/
@Serializable
@@ -77,7 +90,7 @@ class UpdateSettingsAction(
/**
* The new values for the settings.
*/
- val settings: CustomizableSettings
+ val settings: Settings
)
/**
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt
index 96027612..b0e73ed5 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt
@@ -46,7 +46,7 @@ data class HandCard(
@Serializable
data class PreparedCard(
- val player: PlayerDTO,
+ val username: String,
val cardBack: CardBack?
)
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt
index 9e9a5b38..888e1c47 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt
@@ -6,6 +6,37 @@ import org.luxons.sevenwonders.model.cards.CardBack
import org.luxons.sevenwonders.model.cards.PlayabilityLevel
import org.luxons.sevenwonders.model.resources.ResourceTransactions
import org.luxons.sevenwonders.model.resources.ResourceType
+import kotlin.random.Random
+
+typealias WonderName = String
+
+@Serializable
+data class PreGameWonder(
+ val name: WonderName,
+ val images: Map<WonderSide, String>
+)
+
+@Serializable
+data class AssignedWonder(
+ val name: WonderName,
+ val side: WonderSide,
+ val image: String
+)
+
+@Serializable
+enum class WonderSide {
+ A,
+ B
+}
+
+fun List<PreGameWonder>.deal(nbPlayers: Int, random: Random = Random): List<AssignedWonder> =
+ shuffled(random).take(nbPlayers).map { it.withRandomSide(random) }
+
+fun PreGameWonder.withRandomSide(random: Random = Random): AssignedWonder {
+ val side = WonderSide.values().random(random)
+ val sideImage = images.getValue(side)
+ return AssignedWonder(name, side, sideImage)
+}
@Serializable
data class ApiWonder(
bgstack15