From 57052af28185d73256f4b8e96214584f3d51cf0d Mon Sep 17 00:00:00 2001 From: smelc Date: Mon, 2 Mar 2020 19:12:55 +0100 Subject: [PATCH] Add moral --- ai/src/Lib.hs | 5 ++++- .../commonMain/kotlin/com/hgames/pcw/creatures.kt | 5 +++-- .../src/commonMain/kotlin/com/hgames/pcw/skill.kt | 3 ++- cardgen/src/commonMain/resources/data.json | 14 +++++++------- shell.nix | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ai/src/Lib.hs b/ai/src/Lib.hs index 409c753..fac2219 100644 --- a/ai/src/Lib.hs +++ b/ai/src/Lib.hs @@ -20,7 +20,9 @@ instance FromJSON Team data Skill = HitFromBack + | Leader | Ranged + | Unique deriving (Generic, Show) instance ToJSON Skill @@ -43,6 +45,7 @@ data Creature creatureName :: String, hp :: Int, attack :: Int, + moral :: Maybe Int, victoryPoints :: Int, skills :: Maybe [Skill] } @@ -91,7 +94,7 @@ someFunc = do print decoding2 print allDecoding where - creature :: Creature = Creature Human "archer" 1 1 2 Nothing + creature :: Creature = Creature Human "archer" 1 1 (Just 2) 2 Nothing creatureJSON = "{ \"team\":\"Human\", \"name\":\"spearman\", \"hp\":2, \"attack\":1, \"victory_points\":2, \"skills\":[\"HitFromBack\"]}" creature2JSON = "{ \"team\":\"Human\", \"foobar\":\"ignore\", \"name\":\"spearman\", \"hp\":2, \"attack\":1, \"victory_points\":2}" decoding :: Either String Creature = eitherDecode creatureJSON diff --git a/cardgen/src/commonMain/kotlin/com/hgames/pcw/creatures.kt b/cardgen/src/commonMain/kotlin/com/hgames/pcw/creatures.kt index 830c2be..6d9b2ad 100644 --- a/cardgen/src/commonMain/kotlin/com/hgames/pcw/creatures.kt +++ b/cardgen/src/commonMain/kotlin/com/hgames/pcw/creatures.kt @@ -21,7 +21,7 @@ private fun findTeam(s: String?): Team? { return Team.values().firstOrNull { it.name.equals(s, true) } } -data class Creature(val name: String, val team: Team, var hps: Int, val attack: Int, val victoryPoints: Int, val skills: List) { +data class Creature(val name: String, val team: Team, var hps: Int, val attack: Int, val moral: Int?, val victoryPoints: Int, val skills: List) { companion object { @@ -46,6 +46,7 @@ data class Creature(val name: String, val team: Team, var hps: Int, val attack: val team: Team = findTeam(teamString) ?: throw IllegalStateException("No such team: $teamString") val hp: Int = map["hp"] as? Int ?: throw IllegalStateException(genErrMsg("hp")) val attack: Int = map["attack"] as? Int ?: throw IllegalStateException(genErrMsg("attack")) + val moral: Int? = map["moral"] as? Int ?: null val victoryPoints: Int = map["victory_points"] as? Int ?: throw IllegalStateException(genErrMsg("victory_points")) val skills: List = readSkill(map["skills"]) @@ -56,7 +57,7 @@ data class Creature(val name: String, val team: Team, var hps: Int, val attack: val h: Int = map["h"] as? Int ?: 72 // default val rect = RectangleInt(x, y, w, h) - return Pair(Creature(name, team, hp, attack, victoryPoints, skills), rect) + return Pair(Creature(name, team, hp, attack, moral, victoryPoints, skills), rect) } private fun readSkill(input: Any?): List { diff --git a/cardgen/src/commonMain/kotlin/com/hgames/pcw/skill.kt b/cardgen/src/commonMain/kotlin/com/hgames/pcw/skill.kt index 3846f6d..89df502 100644 --- a/cardgen/src/commonMain/kotlin/com/hgames/pcw/skill.kt +++ b/cardgen/src/commonMain/kotlin/com/hgames/pcw/skill.kt @@ -7,7 +7,8 @@ enum class Skill { HitFromBack, Flammable, Leader, - Ranged; + Ranged, + Unique; companion object { diff --git a/cardgen/src/commonMain/resources/data.json b/cardgen/src/commonMain/resources/data.json index fb9f661..e854ad6 100644 --- a/cardgen/src/commonMain/resources/data.json +++ b/cardgen/src/commonMain/resources/data.json @@ -1,13 +1,13 @@ { "creatures": [ - { "team":"Human", "name":"spearman", "hp":2, "attack":1, "victory_points":2, "skills":["HitFromBack"], "x":72, "y":0 }, - { "team":"Human", "name":"swordsman", "hp":2, "attack":1, "victory_points":2, "x":0, "y":0 }, - { "team":"Human", "name":"archer", "hp":2, "attack":1, "victory_points":2, "skills":["Ranged"], "x":144, "y":0 }, - { "team":"Human", "name":"general", "hp":3, "attack":3, "victory_points":5, "skills":["Leader"], "x":216, "y":0 }, + { "team":"Human", "name":"spearman", "hp":2, "attack":1, "moral":3, "victory_points":2, "x":72, "y":0, "skills":["HitFromBack"] }, + { "team":"Human", "name":"swordsman", "hp":2, "attack":1, "moral":3, "victory_points":2, "x":0, "y":0 }, + { "team":"Human", "name":"archer", "hp":2, "attack":1, "moral":3, "victory_points":2, "x":144, "y":0, "skills":["Ranged"] }, + { "team":"Human", "name":"general", "hp":3, "attack":3, "moral":5, "victory_points":5, "x":216, "y":0, "skills":["Leader", "Unique"] }, { "team":"Undead", "name":"skeleton", "hp":1, "attack":1, "victory_points":1, "x":0, "y":72 }, - { "team":"Undead", "name":"vampire", "hp":3, "attack":3, "victory_points":5, "x":72, "y":72 }, - { "team":"Undead", "name":"archer", "hp":1, "attack":1, "victory_points":1, "skills":["Ranged"], "x":144, "y":72 }, - { "team":"Undead", "name":"mummy", "hp":5, "attack":2, "victory_points":2,"skills":["Flammable"], "x":216, "y":72 } + { "team":"Undead", "name":"vampire", "hp":3, "attack":3, "victory_points":5, "x":72, "y":72 }, + { "team":"Undead", "name":"archer", "hp":1, "attack":1, "victory_points":1, "x":144, "y":72, "skills":["Ranged"]}, + { "team":"Undead", "name":"mummy", "hp":5, "attack":2, "victory_points":2, "x":216, "y":72, "skills":["Flammable"]} ], "neutral": [ { "name": "health" ,"tile":"red_potion", "text": "Heals 1 HP" }, diff --git a/shell.nix b/shell.nix index 23c6cab..0689792 100644 --- a/shell.nix +++ b/shell.nix @@ -2,7 +2,7 @@ pkgs.mkShell { buildInputs = with pkgs; [ - ormolu gmp + ormolu # gmp ]; }