From 6a294ff0ed9c69be2c49aa18a1589ef0a4be83f6 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Wed, 11 Sep 2019 17:07:23 +0200 Subject: ... --- src/battle/src/View/Controlled/CharacterCard.elm | 64 +++++-- src/shared/battle/Battle/Struct/Attributes.elm | 196 --------------------- src/shared/battle/Battle/Struct/Attributes.elm.m4 | 198 ++++++++++++++++++++++ src/shared/battle/Battle/Struct/Omnimods.elm | 18 ++ 4 files changed, 265 insertions(+), 211 deletions(-) delete mode 100644 src/shared/battle/Battle/Struct/Attributes.elm create mode 100644 src/shared/battle/Battle/Struct/Attributes.elm.m4 diff --git a/src/battle/src/View/Controlled/CharacterCard.elm b/src/battle/src/View/Controlled/CharacterCard.elm index 8857fbf..a48c631 100644 --- a/src/battle/src/View/Controlled/CharacterCard.elm +++ b/src/battle/src/View/Controlled/CharacterCard.elm @@ -282,28 +282,60 @@ get_weapon_field_header is_active weapon = ) get_weapon_details : ( + Battle.Struct.Omnimods.Type -> Battle.Struct.Omnimods.Type -> BattleCharacters.Struct.Weapon.Type -> (Html.Html Struct.Event.Type) ) -get_weapon_details other_wp_omnimods weapon = - (Html.div - [ - (Html.Attributes.class "character-card-weapon") - ] - [ - (get_weapon_field_header False weapon), - (Battle.View.Omnimods.get_html - (Battle.Struct.Omnimods.merge - (Battle.Struct.Omnimods.scale - -1 - other_wp_omnimods +get_weapon_details omnimods other_wp_omnimods weapon = + let + other_wp_omnimods_scaled = + (Battle.Struct.Omnimods.scale + -1 + (Battle.Struct.Omnimods.apply_damage_modifier + (Battle.Struct.Omnimods.get_attribute_mod + (Battle.Struct.Attributes.encode_category + Battle.Struct.Attributes.DamageModifier + ) + omnimods ) - (BattleCharacters.Struct.Weapon.get_omnimods weapon) + other_wp_omnimods ) ) - ] - ) + omnimods_without_other_wp = + (Battle.Struct.Omnimods.merge + (Battle.Struct.Omnimods.scale -1 other_wp_omnimods) + omnimods + ) + this_wp_omnimods = (BattleCharacters.Struct.Weapon.get_omnimods weapon) + omnimods_with_this_wp = + (Battle.Struct.Omnimods.merge + omnimods_without_other_wp + this_wp_omnimods + ) + in + (Html.div + [ + (Html.Attributes.class "character-card-weapon") + ] + [ + (get_weapon_field_header False weapon), + (Battle.View.Omnimods.get_html + (Battle.Struct.Omnimods.merge + other_wp_omnimods_scaled + (Battle.Struct.Omnimods.apply_damage_modifier + (Battle.Struct.Omnimods.get_attribute_mod + (Battle.Struct.Attributes.encode_category + Battle.Struct.Attributes.DamageModifier + ) + omnimods_with_this_wp + ) + this_wp_omnimods + ) + ) + ) + ] + ) get_weapon_summary : ( BattleCharacters.Struct.Weapon.Type -> @@ -410,6 +442,7 @@ get_summary_html char_turn player_ix char = ), (get_weapon_summary active_weapon), (get_weapon_details + omnimods (BattleCharacters.Struct.Weapon.get_omnimods active_weapon) (BattleCharacters.Struct.Character.get_inactive_weapon base_char @@ -472,6 +505,7 @@ get_full_html player_ix char = ) ), (get_weapon_details + omnimods (BattleCharacters.Struct.Weapon.get_omnimods active_weapon) (BattleCharacters.Struct.Character.get_inactive_weapon base_char diff --git a/src/shared/battle/Battle/Struct/Attributes.elm b/src/shared/battle/Battle/Struct/Attributes.elm deleted file mode 100644 index bb6c06e..0000000 --- a/src/shared/battle/Battle/Struct/Attributes.elm +++ /dev/null @@ -1,196 +0,0 @@ -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, - get_true_movement_points, - get_true_max_health, - get_true_dodges, - get_true_parries, - get_true_accuracy, - get_true_double_hits, - get_true_critical_hits, - get_true_damage_modifier, - 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) - -get_true_movement_points : Type -> Int -get_true_movement_points t = t.movement_points - -get_true_max_health : Type -> Int -get_true_max_health t = t.max_health - -get_true_dodges : Type -> Int -get_true_dodges t = t.dodges - -get_true_parries : Type -> Int -get_true_parries t = t.parries - -get_true_accuracy : Type -> Int -get_true_accuracy t = t.accuracy - -get_true_double_hits : Type -> Int -get_true_double_hits t = t.double_hits - -get_true_critical_hits : Type -> Int -get_true_critical_hits t = t.critical_hits - -get_true_damage_modifier : Type -> Int -get_true_damage_modifier t = t.damage_modifier - - -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) - --- TODO: Link this to the server using tacticians-data. -default : Type -default = - { - movement_points = 8, - max_health = 1, - dodges = 0, - parries = 0, - accuracy = 0, - double_hits = 0, - critical_hits = 0, - damage_modifier = 0 - } - -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/Attributes.elm.m4 b/src/shared/battle/Battle/Struct/Attributes.elm.m4 new file mode 100644 index 0000000..d008618 --- /dev/null +++ b/src/shared/battle/Battle/Struct/Attributes.elm.m4 @@ -0,0 +1,198 @@ +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, + get_true_movement_points, + get_true_max_health, + get_true_dodges, + get_true_parries, + get_true_accuracy, + get_true_double_hits, + get_true_critical_hits, + get_true_damage_modifier, + 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) + +get_true_movement_points : Type -> Int +get_true_movement_points t = t.movement_points + +get_true_max_health : Type -> Int +get_true_max_health t = t.max_health + +get_true_dodges : Type -> Int +get_true_dodges t = t.dodges + +get_true_parries : Type -> Int +get_true_parries t = t.parries + +get_true_accuracy : Type -> Int +get_true_accuracy t = t.accuracy + +get_true_double_hits : Type -> Int +get_true_double_hits t = t.double_hits + +get_true_critical_hits : Type -> Int +get_true_critical_hits t = t.critical_hits + +get_true_damage_modifier : Type -> Int +get_true_damage_modifier t = t.damage_modifier + + +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) + +-- TODO: Link this to the server using tacticians-data. +default : Type +default = + { + movement_points = 8, + max_health = 1, + dodges = 0, + parries = 0, + accuracy = 0, + double_hits = 0, + critical_hits = 0, + damage_modifier = 0 + } + +m4_include(__MAKEFILE_DATA_DIR/names.m4.conf) + +decode_category : String -> Category +decode_category str = + case str of + "__SN_MAX_HEALTH" -> MaxHealth + "__SN_MOVEMENT_POINTS" -> MovementPoints + "__SN_DODGE" -> Dodges + "__SN_PARRY" -> Parries + "__SN_ACCURACY" -> Accuracy + "__SN_DOUBLE_HITS" -> DoubleHits + "__SN_DAMAGE_MODIFIER" -> DamageModifier + _ -> CriticalHits + +encode_category : Category -> String +encode_category cat = + case cat of + MaxHealth -> "__SN_MAX_HEALTH" + MovementPoints -> "__SN_MOVEMENT_POINTS" + Dodges -> "__SN_DODGE" + Parries -> "__SN_PARRY" + Accuracy -> "__SN_ACCURACY" + DoubleHits -> "__SN_DOUBLE_HITS" + CriticalHits -> "__SN_CRITICAL_HIT" + DamageModifier -> "__SN_DAMAGE_MODIFIER" + +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 7a61153..2b3c011 100644 --- a/src/shared/battle/Battle/Struct/Omnimods.elm +++ b/src/shared/battle/Battle/Struct/Omnimods.elm @@ -8,9 +8,11 @@ module Battle.Struct.Omnimods exposing get_attack_damage, get_damage_sum, get_attribute_mods, + get_attribute_mod, get_attack_mods, get_defense_mods, get_all_mods, + apply_damage_modifier, scale, decoder ) @@ -174,6 +176,16 @@ get_attack_damage dmg_modifier atk_omni def_omni = atk_omni.attack ) +apply_damage_modifier : Int -> Type -> Type +apply_damage_modifier damage_modifier omnimods = + {omnimods | + attack = + (Dict.map + (scale_dict_value ((toFloat damage_modifier) / 100.0)) + omnimods.attack + ) + } + scale : Float -> Type -> Type scale multiplier omnimods = {omnimods | @@ -183,6 +195,12 @@ scale multiplier omnimods = (Dict.map (scale_dict_value multiplier) omnimods.defense) } +get_attribute_mod : String -> Type -> Int +get_attribute_mod att_name omnimods = + case (Dict.get att_name omnimods.attributes) of + (Just e) -> e + Nothing -> 0 + get_attribute_mods : Type -> (List (String, Int)) get_attribute_mods omnimods = (Dict.toList omnimods.attributes) -- cgit v1.2.3-70-g09d2