summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/battlemap/src/ElmModule/Update.elm4
-rw-r--r--src/battlemap/src/Struct/Animation.elm45
-rw-r--r--src/battlemap/src/Struct/Attack.elm31
-rw-r--r--src/battlemap/src/Struct/Character.elm6
-rw-r--r--src/battlemap/src/Struct/Event.elm1
-rw-r--r--src/battlemap/src/Struct/TurnResult.elm167
-rw-r--r--src/battlemap/src/Update/HandleAnimationEnded.elm20
-rw-r--r--src/battlemap/src/View/Controlled/CharacterCard.elm2
-rw-r--r--src/battlemap/src/View/Controlled/Targets.elm2
9 files changed, 274 insertions, 4 deletions
diff --git a/src/battlemap/src/ElmModule/Update.elm b/src/battlemap/src/ElmModule/Update.elm
index 7a81439..fda47f6 100644
--- a/src/battlemap/src/ElmModule/Update.elm
+++ b/src/battlemap/src/ElmModule/Update.elm
@@ -11,6 +11,7 @@ import Update.AttackWithoutMoving
import Update.ChangeScale
import Update.DisplayCharacterInfo
import Update.EndTurn
+import Update.HandleAnimationEnded
import Update.HandleServerReply
import Update.LookForCharacter
import Update.RequestDirection
@@ -51,6 +52,9 @@ update event model =
Struct.Event.AttackWithoutMovingRequest ->
(Update.AttackWithoutMoving.apply_to new_model)
+ Struct.Event.AnimationEnded ->
+ (Update.HandleAnimationEnded.apply_to model)
+
(Struct.Event.DirectionRequested d) ->
(Update.RequestDirection.apply_to new_model d)
diff --git a/src/battlemap/src/Struct/Animation.elm b/src/battlemap/src/Struct/Animation.elm
new file mode 100644
index 0000000..7b7e4d1
--- /dev/null
+++ b/src/battlemap/src/Struct/Animation.elm
@@ -0,0 +1,45 @@
+module Struct.Animation exposing
+ (
+ Type
+ )
+
+-- Elm -------------------------------------------------------------------------
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.Direction
+import Struct.Weapon
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias CharMoves =
+ {
+ char_ix : Int,
+ dir : Struct.Direction.Type
+ }
+
+type alias CharSwitchesWeapon =
+ {
+ char_ix : Int
+ new_weapon_id : Struct.Weapon.Ref
+ }
+
+type alias CharAttacks =
+ {
+ char_ix : Int,
+ target_ix : Int,
+ sequence : (List Struct.Attack.Type)
+ }
+
+type Type =
+ CharacterMoves CharMoves
+ | CharacterSwitchesWeapon CharSwitchesWeapon
+ | CharacterAttacks CharAttacks
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
diff --git a/src/battlemap/src/Struct/Attack.elm b/src/battlemap/src/Struct/Attack.elm
index e3199cd..91844c4 100644
--- a/src/battlemap/src/Struct/Attack.elm
+++ b/src/battlemap/src/Struct/Attack.elm
@@ -4,6 +4,7 @@ module Struct.Attack exposing
Order(..),
Precision(..),
apply_to_characters,
+ apply_inverse_to_characters,
decoder
)
@@ -115,3 +116,33 @@ apply_to_characters attacker_ix defender_ix attack characters =
)
Nothing -> characters
+
+apply_inverse_to_characters : (
+ Int ->
+ Int ->
+ Type ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_inverse_to_characters attacker_ix defender_ix attack characters =
+ if ((attack.order == Counter) == attack.parried)
+ then
+ case (Array.get defender_ix characters) of
+ (Just char) ->
+ (Array.set
+ defender_ix
+ (apply_damage_to_character (-1 * attack.damage) char)
+ characters
+ )
+
+ Nothing -> characters
+ else
+ case (Array.get attacker_ix characters) of
+ (Just char) ->
+ (Array.set
+ attacker_ix
+ (apply_damage_to_character (-1 * attack.damage) char)
+ characters
+ )
+
+ Nothing -> characters
diff --git a/src/battlemap/src/Struct/Character.elm b/src/battlemap/src/Struct/Character.elm
index 2ae0273..bb6d850 100644
--- a/src/battlemap/src/Struct/Character.elm
+++ b/src/battlemap/src/Struct/Character.elm
@@ -9,6 +9,7 @@ module Struct.Character exposing
get_armor,
get_armor_variation,
get_current_health,
+ get_sane_current_health,
set_current_health,
get_location,
set_location,
@@ -117,8 +118,11 @@ get_portrait_id c = c.portrait
get_current_health : Type -> Int
get_current_health c = c.health
+get_sane_current_health : Type -> Int
+get_sane_current_health c = (max 0 c.health)
+
set_current_health : Int -> Type -> Type
-set_current_health health c = {c | health = (max 0 health)}
+set_current_health health c = {c | health = health}
get_location : Type -> Struct.Location.Type
get_location t = t.location
diff --git a/src/battlemap/src/Struct/Event.elm b/src/battlemap/src/Struct/Event.elm
index fbcdf1f..8355d52 100644
--- a/src/battlemap/src/Struct/Event.elm
+++ b/src/battlemap/src/Struct/Event.elm
@@ -15,6 +15,7 @@ import Struct.UI
--------------------------------------------------------------------------------
type Type =
AbortTurnRequest
+ | AnimationEnded
| AttackWithoutMovingRequest
| CharacterInfoRequested Int
| CharacterSelected Int
diff --git a/src/battlemap/src/Struct/TurnResult.elm b/src/battlemap/src/Struct/TurnResult.elm
index 23fdf1d..59a004a 100644
--- a/src/battlemap/src/Struct/TurnResult.elm
+++ b/src/battlemap/src/Struct/TurnResult.elm
@@ -5,6 +5,9 @@ module Struct.TurnResult exposing
Movement,
WeaponSwitch,
apply_to_characters,
+ apply_inverse_to_characters,
+ apply_step_to_characters,
+ maybe_remove_step,
decoder
)
@@ -58,6 +61,36 @@ apply_movement_to_character : (
apply_movement_to_character movement char =
(Struct.Character.set_location movement.destination char)
+apply_movement_step_to_character : (
+ Movement ->
+ Struct.Character.Type ->
+ Struct.Character.Type
+ )
+apply_movement_step_to_character movement char =
+ case (List.head movement.path) of
+ (Just dir) ->
+ (Struct.Character.set_location
+ (Struct.Location.neighbor dir (Struct.Character.get_location char))
+ char
+ )
+
+ Nothing -> char
+
+apply_inverse_movement_to_character : (
+ Movement ->
+ Struct.Character.Type ->
+ Struct.Character.Type
+ )
+apply_inverse_movement_to_character movement char =
+ (Struct.Character.set_location
+ (List.foldr
+ (Struct.Location.neighbor)
+ (movement.destination)
+ (List.map (Struct.Direction.opposite_of) movement.path)
+ )
+ char
+ )
+
apply_weapon_switch_to_character : (
Struct.Character.Type ->
Struct.Character.Type
@@ -85,6 +118,38 @@ apply_attack_to_characters attack characters =
attack.sequence
)
+apply_attack_step_to_characters : (
+ Attack ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_attack_step_to_characters attack characters =
+ case (List.head attack.sequence) of
+ (Just attack_step) ->
+ (Struct.Attack.apply_to_characters
+ attack.attacker_index
+ attack.defender_index
+ attack_step
+ characters
+ )
+
+ Nothing -> characters
+
+apply_inverse_attack_to_characters : (
+ Attack ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_inverse_attack_to_characters attack characters =
+ (List.foldr
+ (Struct.Attack.apply_inverse_to_characters
+ attack.attacker_index
+ attack.defender_index
+ )
+ characters
+ attack.sequence
+ )
+
movement_decoder : (Json.Decode.Decoder Movement)
movement_decoder =
(Json.Decode.map3
@@ -119,7 +184,6 @@ weapon_switch_decoder =
(Json.Decode.field "ix" Json.Decode.int)
)
-
internal_decoder : String -> (Json.Decode.Decoder Type)
internal_decoder kind =
case kind of
@@ -150,6 +214,32 @@ internal_decoder kind =
)
)
+maybe_remove_movement_step : Movement -> (Maybe Type)
+maybe_remove_movement_step movement =
+ case (List.tail movement.path) of
+ Nothing -> Nothing
+ (Just path_tail) ->
+ (Just
+ (Moved
+ {movement |
+ path = path_tail
+ }
+ )
+ )
+
+maybe_remove_attack_step : Attack -> (Maybe Type)
+maybe_remove_attack_step attack =
+ case (List.tail attack.sequence) of
+ Nothing -> Nothing
+ (Just sequence_tail) ->
+ (Just
+ (Attacked
+ {attack |
+ sequence = sequence_tail
+ }
+ )
+ )
+
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -187,7 +277,82 @@ apply_to_characters turn_result characters =
(Attacked attack) ->
(apply_attack_to_characters attack characters)
+apply_step_to_characters : (
+ Type ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_step_to_characters turn_result characters =
+ case turn_result of
+ (Moved movement) ->
+ case (Array.get movement.character_index characters) of
+ (Just char) ->
+ (Array.set
+ movement.character_index
+ (apply_movement_step_to_character movement char)
+ characters
+ )
+
+ Nothing ->
+ characters
+
+ (SwitchedWeapon weapon_switch) ->
+ case (Array.get weapon_switch.character_index characters) of
+ (Just char) ->
+ (Array.set
+ weapon_switch.character_index
+ (apply_weapon_switch_to_character char)
+ characters
+ )
+
+ Nothing ->
+ characters
+
+ (Attacked attack) ->
+ (apply_attack_step_to_characters attack characters)
+
+apply_inverse_to_characters : (
+ Type ->
+ (Array.Array Struct.Character.Type) ->
+ (Array.Array Struct.Character.Type)
+ )
+apply_inverse_to_characters turn_result characters =
+ case turn_result of
+ (Moved movement) ->
+ case (Array.get movement.character_index characters) of
+ (Just char) ->
+ (Array.set
+ movement.character_index
+ (apply_inverse_movement_to_character movement char)
+ characters
+ )
+
+ Nothing ->
+ characters
+
+ (SwitchedWeapon weapon_switch) ->
+ case (Array.get weapon_switch.character_index characters) of
+ (Just char) ->
+ (Array.set
+ weapon_switch.character_index
+ (apply_weapon_switch_to_character char)
+ characters
+ )
+
+ Nothing ->
+ characters
+
+ (Attacked attack) ->
+ (apply_inverse_attack_to_characters attack characters)
+
decoder : (Json.Decode.Decoder Type)
decoder =
(Json.Decode.field "t" Json.Decode.string)
|> (Json.Decode.andThen internal_decoder)
+
+maybe_remove_step : Type -> (Maybe Type)
+maybe_remove_step turn_result =
+ case turn_result of
+ (Moved movement) -> (maybe_remove_movement_step movement)
+ (SwitchedWeapon _) -> Nothing
+ (Attacked attack) -> (maybe_remove_attack_step attack)
diff --git a/src/battlemap/src/Update/HandleAnimationEnded.elm b/src/battlemap/src/Update/HandleAnimationEnded.elm
new file mode 100644
index 0000000..0d9adc9
--- /dev/null
+++ b/src/battlemap/src/Update/HandleAnimationEnded.elm
@@ -0,0 +1,20 @@
+module Update.HandleAnimationEnded exposing (apply_to)
+
+-- Elm -------------------------------------------------------------------------
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.Event
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+apply_to model = (model, Cmd.none)
diff --git a/src/battlemap/src/View/Controlled/CharacterCard.elm b/src/battlemap/src/View/Controlled/CharacterCard.elm
index 7079fc9..28a507f 100644
--- a/src/battlemap/src/View/Controlled/CharacterCard.elm
+++ b/src/battlemap/src/View/Controlled/CharacterCard.elm
@@ -46,7 +46,7 @@ get_health_bar : (
)
get_health_bar char =
let
- current = (Struct.Character.get_current_health char)
+ current = (Struct.Character.get_sane_current_health char)
max =
(Struct.Statistics.get_max_health
(Struct.Character.get_statistics char)
diff --git a/src/battlemap/src/View/Controlled/Targets.elm b/src/battlemap/src/View/Controlled/Targets.elm
index 7bb4c36..b851555 100644
--- a/src/battlemap/src/View/Controlled/Targets.elm
+++ b/src/battlemap/src/View/Controlled/Targets.elm
@@ -41,7 +41,7 @@ get_target_info_html model char_ref =
++ " movement points; "
++ "???"
++ " attack range. Health: "
- ++ (toString (Struct.Character.get_current_health char))
+ ++ (toString (Struct.Character.get_sane_current_health char))
++ "/"
++
(toString