summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-12-12 18:24:00 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-12-12 18:24:00 +0100
commit65104411c1dbb3f9da1a10ee1aef76dbf2886b2c (patch)
treef2bbd995210fbe56bcc2ffe9659442a1736a62f5 /src/battle
parent0f32d059365e037405a71ecbd0f01b82b59cf7da (diff)
...
Diffstat (limited to 'src/battle')
-rw-r--r--src/battle/src/Struct/Battle.elm87
-rw-r--r--src/battle/src/Struct/Character.elm24
2 files changed, 71 insertions, 40 deletions
diff --git a/src/battle/src/Struct/Battle.elm b/src/battle/src/Struct/Battle.elm
index ae6e3fe..c7f5c0a 100644
--- a/src/battle/src/Struct/Battle.elm
+++ b/src/battle/src/Struct/Battle.elm
@@ -6,6 +6,7 @@ module Struct.Battle exposing
add_character,
get_character,
set_character,
+ refresh_character,
update_character,
get_characters,
set_characters,
@@ -74,54 +75,42 @@ type alias Type =
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
--- TODO: move this elsewhere, this is too complicated a function for a module
--- that's not solely focused on attacks of opportunity.
-regenerate_attack_of_opportunity_markers_of_char : (
+regenerate_attack_of_opportunity_tags_for_char : (
Int ->
Struct.Character.Type ->
Type ->
Type
)
-regenerate_attack_of_opportunity_markers_of_char char_ix char battle =
- if ((Struct.Character.get_player_index char) == battle.own_player_ix)
- then battle
- else
- let
- marker_name = ("matk_c" ++ (String.fromInt char_ix))
- map_without_this_marker =
- (BattleMap.Struct.Map.remove_marker marker_name battle.map)
- in
- case (Struct.Character.get_melee_attack_range char) of
- 0 -> {battle | map = map_without_this_marker}
- attack_range ->
- {battle |
- map =
- (BattleMap.Struct.Map.add_marker
- marker_name
- (BattleMap.Struct.Marker.new_melee_attack
- char_ix
- (BattleMap.Struct.Location.add_neighborhood_to_set
- (BattleMap.Struct.Map.get_width
- map_without_this_marker
- )
- (BattleMap.Struct.Map.get_height
- map_without_this_marker
- )
- attack_range
- (Struct.Character.get_location char)
- (Set.empty)
+regenerate_attack_of_opportunity_tags_for_char char_ix char battle =
+ let
+ tag_name = ("matk_c" ++ (String.fromInt char_ix))
+ map_without_this_tag =
+ (BattleMap.Struct.Map.remove_tag tag_name battle.map)
+ in
+ case (Struct.Character.get_melee_attack_range char) of
+ 0 -> {battle | map = map_without_this_tag}
+ attack_range ->
+ {battle |
+ map =
+ (BattleMap.Struct.Map.add_tag
+ tag_name
+ (BattleMap.Struct.Marker.new_melee_attack
+ char_ix
+ (BattleMap.Struct.Location.add_neighborhood_to_set
+ (BattleMap.Struct.Map.get_width
+ map_without_this_tag
)
+ (BattleMap.Struct.Map.get_height
+ map_without_this_tag
+ )
+ attack_range
+ (Struct.Character.get_location char)
+ (Set.empty)
)
- map_without_this_marker
)
- }
-
-regenerate_attack_of_opportunity_markers : Int -> Type -> Type
-regenerate_attack_of_opportunity_markers char_ix battle =
- case (Array.get char_ix battle.characters) of
- Nothing -> battle
- (Just char) ->
- (regenerate_attack_of_opportunity_markers_of_char char_ix char battle)
+ map_without_this_tag
+ )
+ }
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
@@ -172,6 +161,24 @@ get_characters battle = battle.characters
set_characters : (Array.Array Struct.Character.Type) -> Type -> Type
set_characters chars battle = {battle | characters = chars}
+refresh_character : BattleMap.Struct.DataSet.Type -> Int -> Type -> Type
+refresh_character map_dataset ix battle =
+ let
+ character = (get_character ix battle)
+ refreshed_character =
+ (Struct.Character.refresh_omnimods
+ (\loc ->
+ (BattleMap.Struct.Map.get_omnimods_at loc map_dataset battle.map)
+ )
+ character
+ )
+ in
+ (regenerate_attack_of_opportunity_tags_for_char
+ ix
+ refreshed_character
+ (set_character ix refreshed_character battle)
+ )
+
-----------------
---- Players ----
-----------------
diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm
index 327d23c..54a3a8c 100644
--- a/src/battle/src/Struct/Character.elm
+++ b/src/battle/src/Struct/Character.elm
@@ -20,6 +20,7 @@ module Struct.Character exposing
get_base_character,
set_base_character,
get_melee_attack_range,
+ refresh_omnimods,
decoder,
resolve
)
@@ -181,6 +182,29 @@ set_location location omnimods char =
dirty_set_location : BattleMap.Struct.Location.Type -> Type -> Type
dirty_set_location location char = { char | location = location }
+refresh_omnimods : (
+ (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) ->
+ Type ->
+ Type
+ )
+refresh_omnimods omnimods_fun character =
+ let
+ previous_max_health =
+ (Battle.Struct.Attributes.get_max_health
+ (BattleCharacters.Struct.Character.get_attributes char.base)
+ )
+ in
+ (fix_health
+ previous_max_health
+ {char |
+ base =
+ (BattleCharacters.Struct.Character.set_extra_omnimods
+ (omnimods_fun char.location)
+ char.base
+ )
+ }
+ )
+
get_base_character : Type -> BattleCharacters.Struct.Character.Type
get_base_character char = char.base