summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-07-03 17:12:29 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-07-03 17:12:29 +0200
commitfcd22009099792d096942e5ee1d834d9e2c1af48 (patch)
tree59286d68647ba97d25cfed28215e79dc264ca5bb /src/battlemap
parentb985839577086b75a76d6e4647e806948af1fde8 (diff)
Properly removes defeated characters.
Diffstat (limited to 'src/battlemap')
-rw-r--r--src/battlemap/src/Struct/Character.elm14
-rw-r--r--src/battlemap/src/Struct/TurnResult.elm45
-rw-r--r--src/battlemap/src/View/Battlemap/Character.elm2
3 files changed, 52 insertions, 9 deletions
diff --git a/src/battlemap/src/Struct/Character.elm b/src/battlemap/src/Struct/Character.elm
index db84ce9..f361501 100644
--- a/src/battlemap/src/Struct/Character.elm
+++ b/src/battlemap/src/Struct/Character.elm
@@ -18,8 +18,10 @@ module Struct.Character exposing
get_attributes,
get_statistics,
is_enabled,
+ is_defeated,
is_alive,
set_enabled,
+ set_defeated,
get_weapons,
set_weapons,
decoder,
@@ -52,6 +54,7 @@ type alias PartiallyDecoded =
hea : Int,
pla : Int,
ena : Bool,
+ dea : Bool,
att : Struct.Attributes.Type,
awp : Int,
swp : Int,
@@ -74,6 +77,7 @@ type alias Type =
health : Int,
player_ix : Int,
enabled : Bool,
+ defeated : Bool,
attributes : Struct.Attributes.Type,
statistics : Struct.Statistics.Type,
weapons : Struct.WeaponSet.Type,
@@ -108,6 +112,7 @@ finish_decoding add_char =
statistics = (Struct.Statistics.new add_char.att weapon_set armor),
player_ix = add_char.pla,
enabled = add_char.ena,
+ defeated = add_char.dea,
weapons = weapon_set,
armor = armor
}
@@ -157,14 +162,20 @@ get_statistics : Type -> Struct.Statistics.Type
get_statistics char = char.statistics
is_alive : Type -> Bool
-is_alive char = (char.health > 0)
+is_alive char = ((char.health > 0) && (not char.defeated))
is_enabled : Type -> Bool
is_enabled char = char.enabled
+is_defeated : Type -> Bool
+is_defeated char = char.defeated
+
set_enabled : Bool -> Type -> Type
set_enabled enabled char = {char | enabled = enabled}
+set_defeated : Bool -> Type -> Type
+set_defeated defeated char = {char | defeated = defeated}
+
get_weapons : Type -> Struct.WeaponSet.Type
get_weapons char = char.weapons
@@ -201,6 +212,7 @@ decoder =
|> (Json.Decode.Pipeline.required "hea" Json.Decode.int)
|> (Json.Decode.Pipeline.required "pla" Json.Decode.int)
|> (Json.Decode.Pipeline.required "ena" Json.Decode.bool)
+ |> (Json.Decode.Pipeline.required "dea" Json.Decode.bool)
|> (Json.Decode.Pipeline.required "att" (Struct.Attributes.decoder))
|> (Json.Decode.Pipeline.required "awp" Json.Decode.int)
|> (Json.Decode.Pipeline.required "swp" Json.Decode.int)
diff --git a/src/battlemap/src/Struct/TurnResult.elm b/src/battlemap/src/Struct/TurnResult.elm
index f122e0b..af3930d 100644
--- a/src/battlemap/src/Struct/TurnResult.elm
+++ b/src/battlemap/src/Struct/TurnResult.elm
@@ -143,6 +143,40 @@ apply_attack_to_characters attack characters =
attack.sequence
)
+apply_player_defeat_to_characters : (
+ PlayerDefeat ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_player_defeat_to_characters pdefeat characters =
+ (Array.map
+ (\c ->
+ (
+ if ((Struct.Character.get_player_ix c) == pdefeat.player_index)
+ then (Struct.Character.set_defeated True c)
+ else c
+ )
+ )
+ characters
+ )
+
+apply_inverse_player_defeat_to_characters : (
+ PlayerDefeat ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_inverse_player_defeat_to_characters pdefeat characters =
+ (Array.map
+ (\c ->
+ (
+ if ((Struct.Character.get_player_ix c) == pdefeat.player_index)
+ then (Struct.Character.set_defeated False c)
+ else c
+ )
+ )
+ characters
+ )
+
apply_attack_step_to_characters : (
Attack ->
(Array.Array Struct.Character.Type) ->
@@ -344,8 +378,7 @@ apply_to_characters turn_result characters =
(PlayerWon pvict) -> characters
(PlayerLost pdefeat) ->
- -- TODO: Their characters are supposed to disappear.
- characters
+ (apply_player_defeat_to_characters pdefeat characters)
(PlayerTurnStarted pturns) -> characters
@@ -385,7 +418,8 @@ apply_step_to_characters turn_result characters =
(PlayerWon pvict) -> characters
- (PlayerLost pdefeat) -> characters
+ (PlayerLost pdefeat) ->
+ (apply_player_defeat_to_characters pdefeat characters)
(PlayerTurnStarted pturns) -> characters
@@ -426,10 +460,7 @@ apply_inverse_to_characters turn_result characters =
(PlayerWon pvict) -> characters
(PlayerLost pdefeat) ->
- -- TODO
- -- Their characters are supposed to have disappeared, so we have to
- -- make them visible again.
- characters
+ (apply_inverse_player_defeat_to_characters pdefeat characters)
(PlayerTurnStarted pturns) -> characters
diff --git a/src/battlemap/src/View/Battlemap/Character.elm b/src/battlemap/src/View/Battlemap/Character.elm
index e16325e..fa1bdc1 100644
--- a/src/battlemap/src/View/Battlemap/Character.elm
+++ b/src/battlemap/src/View/Battlemap/Character.elm
@@ -171,7 +171,7 @@ get_banner_html char =
]
)
- Struct.Character.Optional -> (Util.Html.nothing)
+ _ -> (Util.Html.nothing)
get_actual_html : (
Struct.Model.Type ->