From 120b0b7f6df0c8978aac9a423cbf8364feac4779 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 10 Aug 2019 18:23:48 +0200 Subject: Statistics -> Attributes. --- src/shared/battle/Battle/Struct/Attributes.elm | 162 +++++++++++++++++++++++++ src/shared/battle/Battle/Struct/Omnimods.elm | 42 +++---- src/shared/battle/Battle/Struct/Statistics.elm | 162 ------------------------- 3 files changed, 183 insertions(+), 183 deletions(-) create mode 100644 src/shared/battle/Battle/Struct/Attributes.elm delete mode 100644 src/shared/battle/Battle/Struct/Statistics.elm (limited to 'src/shared/battle/Battle/Struct') diff --git a/src/shared/battle/Battle/Struct/Attributes.elm b/src/shared/battle/Battle/Struct/Attributes.elm new file mode 100644 index 0000000..159404e --- /dev/null +++ b/src/shared/battle/Battle/Struct/Attributes.elm @@ -0,0 +1,162 @@ +module Battle.Struct.Attributes exposing + ( + Type, + Category(..), + get_movement_points, + get_max_health, + get_dodges, + get_parries, + get_accuracy, + get_double_hits, + get_critical_hits, + get_damage_modifier, + get_damage_multiplier, + decode_category, + encode_category, + mod, + default, + is_percent + ) + +-- Elm ------------------------------------------------------------------------- +import List + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Category = + MovementPoints + | MaxHealth + | Dodges + | Parries + | Accuracy + | DoubleHits + | CriticalHits + | DamageModifier + +type alias Type = + { + movement_points : Int, + max_health : Int, + dodges : Int, + parries : Int, + accuracy : Int, + double_hits : Int, + critical_hits : Int, + damage_modifier : Int + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +mod_movement_points : Int -> Type -> Type +mod_movement_points v t = + {t | + movement_points = (t.movement_points + v) + } + +mod_max_health : Int -> Type -> Type +mod_max_health v t = + {t | + max_health = (t.max_health + v) + } + +mod_dodges : Int -> Type -> Type +mod_dodges v t = {t | dodges = (t.dodges + v)} + +mod_parries : Int -> Type -> Type +mod_parries v t = {t | parries = (t.parries + v)} + +mod_accuracy : Int -> Type -> Type +mod_accuracy v t = {t | accuracy = (t.accuracy + v)} + +mod_double_hits : Int -> Type -> Type +mod_double_hits v t = {t | double_hits = (t.double_hits + v)} + +mod_critical_hits : Int -> Type -> Type +mod_critical_hits v t = {t | critical_hits = (t.critical_hits + v)} + +mod_damage_modifier : Int -> Type -> Type +mod_damage_modifier v t = {t | damage_modifier = (t.damage_modifier + v)} + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_movement_points : Type -> Int +get_movement_points t = (max 0 t.movement_points) + +get_max_health : Type -> Int +get_max_health t = (max 1 t.max_health) + +get_dodges : Type -> Int +get_dodges t = (max 0 t.dodges) + +get_parries : Type -> Int +get_parries t = (max 0 t.parries) + +get_accuracy : Type -> Int +get_accuracy t = (max 0 t.accuracy) + +get_double_hits : Type -> Int +get_double_hits t = (max 0 t.double_hits) + +get_critical_hits : Type -> Int +get_critical_hits t = (max 0 t.critical_hits) + +get_damage_modifier : Type -> Int +get_damage_modifier t = (max 0 t.damage_modifier) + +get_damage_multiplier : Type -> Float +get_damage_multiplier t = ((toFloat (max 0 t.damage_modifier)) / 100.0) + +mod : Category -> Int -> Type -> Type +mod cat v t = + case cat of + MaxHealth -> (mod_max_health v t) + MovementPoints -> (mod_movement_points v t) + Dodges -> (mod_dodges v t) + Parries -> (mod_parries v t) + Accuracy -> (mod_accuracy v t) + DoubleHits -> (mod_double_hits v t) + CriticalHits -> (mod_critical_hits v t) + DamageModifier -> (mod_damage_modifier v t) + +default : Type +default = + { + movement_points = 0, + max_health = 1, + dodges = 0, + parries = 0, + accuracy = 0, + double_hits = 0, + critical_hits = 0, + damage_modifier = 100 + } + +decode_category : String -> Category +decode_category str = + case str of + "mheal" -> MaxHealth + "mpts" -> MovementPoints + "dodg" -> Dodges + "pary" -> Parries + "accu" -> Accuracy + "dhit" -> DoubleHits + "dmgm" -> DamageModifier + _ -> CriticalHits + +encode_category : Category -> String +encode_category cat = + case cat of + MaxHealth -> "mheal" + MovementPoints -> "mpts" + Dodges -> "dodg" + Parries -> "pary" + Accuracy -> "accu" + DoubleHits -> "dhit" + CriticalHits -> "crit" + DamageModifier -> "dmgm" + +is_percent : Category -> Bool +is_percent cat = ((cat /= MaxHealth) && (cat /= MovementPoints)) diff --git a/src/shared/battle/Battle/Struct/Omnimods.elm b/src/shared/battle/Battle/Struct/Omnimods.elm index 92bf636..7a61153 100644 --- a/src/shared/battle/Battle/Struct/Omnimods.elm +++ b/src/shared/battle/Battle/Struct/Omnimods.elm @@ -4,10 +4,10 @@ module Battle.Struct.Omnimods exposing new, merge, none, - apply_to_statistics, + apply_to_attributes, get_attack_damage, get_damage_sum, - get_statistics_mods, + get_attribute_mods, get_attack_mods, get_defense_mods, get_all_mods, @@ -22,7 +22,7 @@ import Json.Decode import Json.Decode.Pipeline -- Battle ---------------------------------------------------------------------- -import Battle.Struct.Statistics +import Battle.Struct.Attributes import Battle.Struct.DamageType -------------------------------------------------------------------------------- @@ -30,7 +30,7 @@ import Battle.Struct.DamageType -------------------------------------------------------------------------------- type alias Type = { - statistics : (Dict.Dict String Int), + attributes : (Dict.Dict String Int), attack : (Dict.Dict String Int), defense : (Dict.Dict String Int) } @@ -84,7 +84,7 @@ decoder : (Json.Decode.Decoder Type) decoder = (Json.Decode.succeed Type - |> (Json.Decode.Pipeline.required "stam" generic_mods_decoder) + |> (Json.Decode.Pipeline.required "attm" generic_mods_decoder) |> (Json.Decode.Pipeline.required "atkm" generic_mods_decoder) |> (Json.Decode.Pipeline.required "defm" generic_mods_decoder) ) @@ -95,9 +95,9 @@ new : ( (List (String, Int)) -> Type ) -new statistic_mods attack_mods defense_mods = +new attribute_mods attack_mods defense_mods = { - statistics = (Dict.fromList statistic_mods), + attributes = (Dict.fromList attribute_mods), attack = (Dict.fromList attack_mods), defense = (Dict.fromList defense_mods) } @@ -105,7 +105,7 @@ new statistic_mods attack_mods defense_mods = none : Type none = { - statistics = (Dict.empty), + attributes = (Dict.empty), attack = (Dict.empty), defense = (Dict.empty) } @@ -113,24 +113,24 @@ none = merge : Type -> Type -> Type merge omni_a omni_b = { - statistics = (merge_mods omni_a.statistics omni_b.statistics), + attributes = (merge_mods omni_a.attributes omni_b.attributes), attack = (merge_mods omni_a.attack omni_b.attack), defense = (merge_mods omni_a.defense omni_b.defense) } -apply_to_statistics : ( +apply_to_attributes : ( Type -> - Battle.Struct.Statistics.Type -> - Battle.Struct.Statistics.Type + Battle.Struct.Attributes.Type -> + Battle.Struct.Attributes.Type ) -apply_to_statistics omnimods statistics = +apply_to_attributes omnimods attributes = (Dict.foldl ( - (Battle.Struct.Statistics.decode_category) - >> (Battle.Struct.Statistics.mod) + (Battle.Struct.Attributes.decode_category) + >> (Battle.Struct.Attributes.mod) ) - statistics - omnimods.statistics + attributes + omnimods.attributes ) get_damage_sum : Type -> Int @@ -177,14 +177,14 @@ get_attack_damage dmg_modifier atk_omni def_omni = scale : Float -> Type -> Type scale multiplier omnimods = {omnimods | - statistics = (Dict.map (scale_dict_value multiplier) omnimods.statistics), + attributes = (Dict.map (scale_dict_value multiplier) omnimods.attributes), attack = (Dict.map (scale_dict_value multiplier) omnimods.attack), defense = (Dict.map (scale_dict_value multiplier) omnimods.defense) } -get_statistics_mods : Type -> (List (String, Int)) -get_statistics_mods omnimods = (Dict.toList omnimods.statistics) +get_attribute_mods : Type -> (List (String, Int)) +get_attribute_mods omnimods = (Dict.toList omnimods.attributes) get_attack_mods : Type -> (List (String, Int)) get_attack_mods omnimods = (Dict.toList omnimods.attack) @@ -195,7 +195,7 @@ get_defense_mods omnimods = (Dict.toList omnimods.defense) get_all_mods : Type -> (List (String, Int)) get_all_mods omnimods = ( - (get_statistics_mods omnimods) + (get_attribute_mods omnimods) ++ (get_attack_mods omnimods) ++ (get_defense_mods omnimods) ) diff --git a/src/shared/battle/Battle/Struct/Statistics.elm b/src/shared/battle/Battle/Struct/Statistics.elm deleted file mode 100644 index 8ed145a..0000000 --- a/src/shared/battle/Battle/Struct/Statistics.elm +++ /dev/null @@ -1,162 +0,0 @@ -module Battle.Struct.Statistics exposing - ( - Type, - Category(..), - get_movement_points, - get_max_health, - get_dodges, - get_parries, - get_accuracy, - get_double_hits, - get_critical_hits, - get_damage_modifier, - get_damage_multiplier, - decode_category, - encode_category, - mod, - default, - is_percent - ) - --- Elm ------------------------------------------------------------------------- -import List - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -type Category = - MovementPoints - | MaxHealth - | Dodges - | Parries - | Accuracy - | DoubleHits - | CriticalHits - | DamageModifier - -type alias Type = - { - movement_points : Int, - max_health : Int, - dodges : Int, - parries : Int, - accuracy : Int, - double_hits : Int, - critical_hits : Int, - damage_modifier : Int - } - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -mod_movement_points : Int -> Type -> Type -mod_movement_points v t = - {t | - movement_points = (t.movement_points + v) - } - -mod_max_health : Int -> Type -> Type -mod_max_health v t = - {t | - max_health = (t.max_health + v) - } - -mod_dodges : Int -> Type -> Type -mod_dodges v t = {t | dodges = (t.dodges + v)} - -mod_parries : Int -> Type -> Type -mod_parries v t = {t | parries = (t.parries + v)} - -mod_accuracy : Int -> Type -> Type -mod_accuracy v t = {t | accuracy = (t.accuracy + v)} - -mod_double_hits : Int -> Type -> Type -mod_double_hits v t = {t | double_hits = (t.double_hits + v)} - -mod_critical_hits : Int -> Type -> Type -mod_critical_hits v t = {t | critical_hits = (t.critical_hits + v)} - -mod_damage_modifier : Int -> Type -> Type -mod_damage_modifier v t = {t | damage_modifier = (t.damage_modifier + v)} - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_movement_points : Type -> Int -get_movement_points t = (max 0 t.movement_points) - -get_max_health : Type -> Int -get_max_health t = (max 1 t.max_health) - -get_dodges : Type -> Int -get_dodges t = (max 0 t.dodges) - -get_parries : Type -> Int -get_parries t = (max 0 t.parries) - -get_accuracy : Type -> Int -get_accuracy t = (max 0 t.accuracy) - -get_double_hits : Type -> Int -get_double_hits t = (max 0 t.double_hits) - -get_critical_hits : Type -> Int -get_critical_hits t = (max 0 t.critical_hits) - -get_damage_modifier : Type -> Int -get_damage_modifier t = (max 0 t.damage_modifier) - -get_damage_multiplier : Type -> Float -get_damage_multiplier t = ((toFloat (max 0 t.damage_modifier)) / 100.0) - -mod : Category -> Int -> Type -> Type -mod cat v t = - case cat of - MaxHealth -> (mod_max_health v t) - MovementPoints -> (mod_movement_points v t) - Dodges -> (mod_dodges v t) - Parries -> (mod_parries v t) - Accuracy -> (mod_accuracy v t) - DoubleHits -> (mod_double_hits v t) - CriticalHits -> (mod_critical_hits v t) - DamageModifier -> (mod_damage_modifier v t) - -default : Type -default = - { - movement_points = 0, - max_health = 1, - dodges = 0, - parries = 0, - accuracy = 0, - double_hits = 0, - critical_hits = 0, - damage_modifier = 100 - } - -decode_category : String -> Category -decode_category str = - case str of - "mheal" -> MaxHealth - "mpts" -> MovementPoints - "dodg" -> Dodges - "pary" -> Parries - "accu" -> Accuracy - "dhit" -> DoubleHits - "dmgm" -> DamageModifier - _ -> CriticalHits - -encode_category : Category -> String -encode_category cat = - case cat of - MaxHealth -> "mheal" - MovementPoints -> "mpts" - Dodges -> "dodg" - Parries -> "pary" - Accuracy -> "accu" - DoubleHits -> "dhit" - CriticalHits -> "crit" - DamageModifier -> "dmgm" - -is_percent : Category -> Bool -is_percent cat = ((cat /= MaxHealth) && (cat /= MovementPoints)) -- cgit v1.2.3-70-g09d2