summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/shared/battle')
-rw-r--r-- | src/shared/battle/Battle/Struct/Attributes.elm | 169 | ||||
-rw-r--r-- | src/shared/battle/Battle/Struct/DamageType.elm | 55 | ||||
-rw-r--r-- | src/shared/battle/Battle/Struct/Omnimods.elm | 180 | ||||
-rw-r--r-- | src/shared/battle/Battle/Struct/Statistics.elm | 210 | ||||
-rw-r--r-- | src/shared/battle/Battle/View/Omnimods.elm | 181 |
5 files changed, 795 insertions, 0 deletions
diff --git a/src/shared/battle/Battle/Struct/Attributes.elm b/src/shared/battle/Battle/Struct/Attributes.elm new file mode 100644 index 0000000..ee12dbd --- /dev/null +++ b/src/shared/battle/Battle/Struct/Attributes.elm @@ -0,0 +1,169 @@ +module Battle.Struct.Attributes exposing + ( + Type, + Category(..), + get_constitution, + get_dexterity, + get_intelligence, + get_mind, + get_speed, + get_strength, + mod_constitution, + mod_dexterity, + mod_intelligence, + mod_mind, + mod_speed, + mod_strength, + mod, + get, + new, + decode_category, + default + ) + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Category = + Constitution + | Dexterity + | Intelligence + | Mind + | Speed + | Strength + +type alias Type = + { + constitution : Int, + dexterity : Int, + intelligence : Int, + mind : Int, + speed : Int, + strength : Int + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_within_range : Int -> Int -> Int -> Int +get_within_range vmin vmax v = (min vmax (max vmin v)) + +get_within_att_range : Int -> Int +get_within_att_range v = (get_within_range 0 100 v) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_constitution : Type -> Int +get_constitution t = t.constitution + +get_dexterity : Type -> Int +get_dexterity t = t.dexterity + +get_intelligence : Type -> Int +get_intelligence t = t.intelligence + +get_mind : Type -> Int +get_mind t = t.mind + +get_speed : Type -> Int +get_speed t = t.speed + +get_strength : Type -> Int +get_strength t = t.strength + +mod_constitution : Int -> Type -> Type +mod_constitution i t = + {t | + constitution = (get_within_att_range (i + t.constitution)) + } + +mod_dexterity : Int -> Type -> Type +mod_dexterity i t = + {t | + dexterity = (get_within_att_range (i + t.dexterity)) + } + +mod_intelligence : Int -> Type -> Type +mod_intelligence i t = + {t | + intelligence = (get_within_att_range (i + t.intelligence)) + } + +mod_mind : Int -> Type -> Type +mod_mind i t = + {t | + mind = (get_within_att_range (i + t.mind)) + } + +mod_speed : Int -> Type -> Type +mod_speed i t = + {t | + speed = (get_within_att_range (i + t.speed)) + } + +mod_strength : Int -> Type -> Type +mod_strength i t = + {t | + strength = (get_within_att_range (i + t.strength)) + } + +mod : Category -> Int -> Type -> Type +mod cat i t = + case cat of + Constitution -> (mod_constitution i t) + Dexterity -> (mod_dexterity i t) + Intelligence -> (mod_intelligence i t) + Mind -> (mod_mind i t) + Speed -> (mod_speed i t) + Strength -> (mod_strength i t) + +get : Category -> Type -> Int +get cat t = + case cat of + Constitution -> (get_constitution t) + Dexterity -> (get_dexterity t) + Intelligence -> (get_intelligence t) + Mind -> (get_mind t) + Speed -> (get_speed t) + Strength -> (get_strength t) + +new : ( + Int -> -- constitution + Int -> -- dexterity + Int -> -- intelligence + Int -> -- mind + Int -> -- speed + Int -> -- strength + Type + ) +new con dex int min spe str = + { + constitution = con, + dexterity = dex, + intelligence = int, + mind = min, + speed = spe, + strength = str + } + +default : Type +default = + { + constitution = 50, + dexterity = 50, + intelligence = 50, + mind = 50, + speed = 50, + strength = 50 + } + +decode_category : String -> Category +decode_category str = + case str of + "con" -> Constitution + "dex" -> Dexterity + "int" -> Intelligence + "min" -> Mind + "spe" -> Speed + _ -> Strength diff --git a/src/shared/battle/Battle/Struct/DamageType.elm b/src/shared/battle/Battle/Struct/DamageType.elm new file mode 100644 index 0000000..59ab19e --- /dev/null +++ b/src/shared/battle/Battle/Struct/DamageType.elm @@ -0,0 +1,55 @@ +module Battle.Struct.DamageType exposing + ( + Type(..), + encode, + decode, + to_string + ) + +-- Elm ------------------------------------------------------------------------- + +-- Battle ---------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Type = + Base + | Slash + | Blunt + | Pierce + | None + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +decode : String -> Type +decode str = + case str of + "bse" -> Base + "slh" -> Slash + "pie" -> Pierce + "blu" -> Blunt + _ -> None + +encode : Type -> String +encode t = + case t of + Base -> "bse" + Slash -> "slh" + Pierce -> "pie" + Blunt -> "blu" + None -> "non" + +to_string : Type -> String +to_string t = + case t of + Base -> "Base" + Slash -> "Slash" + Pierce -> "Piercing" + Blunt -> "Bludgeoning" + None -> "ERROR" diff --git a/src/shared/battle/Battle/Struct/Omnimods.elm b/src/shared/battle/Battle/Struct/Omnimods.elm new file mode 100644 index 0000000..46843b2 --- /dev/null +++ b/src/shared/battle/Battle/Struct/Omnimods.elm @@ -0,0 +1,180 @@ +module Battle.Struct.Omnimods exposing + ( + Type, + new, + merge, + apply_to_attributes, + apply_to_statistics, + get_attack_damage, + get_damage_sum, + get_attributes_mods, + get_statistics_mods, + get_attack_mods, + get_defense_mods, + decoder + ) + +-- Elm ------------------------------------------------------------------------- +import Dict + +import Json.Decode +import Json.Decode.Pipeline + +-- Battle ---------------------------------------------------------------------- +import Battle.Struct.Attributes +import Battle.Struct.Statistics +import Battle.Struct.DamageType + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + attributes : (Dict.Dict String Int), + statistics : (Dict.Dict String Int), + attack : (Dict.Dict String Int), + defense : (Dict.Dict String Int) + } + +type alias GenericMod = + { + t : String, + v : Int + } +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +generic_mods_decoder : (Json.Decode.Decoder (Dict.Dict String Int)) +generic_mods_decoder = + (Json.Decode.map + (Dict.fromList) + (Json.Decode.list + (Json.Decode.map + (\gm -> (gm.t, gm.v)) + (Json.Decode.succeed + GenericMod + |> (Json.Decode.Pipeline.required "t" Json.Decode.string) + |> (Json.Decode.Pipeline.required "v" Json.Decode.int) + ) + ) + ) + ) + +merge_mods : ( + (Dict.Dict String Int) -> + (Dict.Dict String Int) -> + (Dict.Dict String Int) + ) +merge_mods a_mods b_mods = + (Dict.merge + (Dict.insert) + (\t -> \v_a -> \v_b -> \r -> (Dict.insert t (v_a + v_b) r)) + (Dict.insert) + a_mods + b_mods + (Dict.empty) + ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +decoder : (Json.Decode.Decoder Type) +decoder = + (Json.Decode.succeed + Type + |> (Json.Decode.Pipeline.required "attm" generic_mods_decoder) + |> (Json.Decode.Pipeline.required "stam" generic_mods_decoder) + |> (Json.Decode.Pipeline.required "atkm" generic_mods_decoder) + |> (Json.Decode.Pipeline.required "defm" generic_mods_decoder) + ) + +new : ( + (List (String, Int)) -> + (List (String, Int)) -> + (List (String, Int)) -> + (List (String, Int)) -> + Type + ) +new attribute_mods statistic_mods attack_mods defense_mods = + { + attributes = (Dict.fromList attribute_mods), + statistics = (Dict.fromList statistic_mods), + attack = (Dict.fromList attack_mods), + defense = (Dict.fromList defense_mods) + } + +merge : Type -> Type -> Type +merge omni_a omni_b = + { + attributes = (merge_mods omni_a.attributes omni_b.attributes), + statistics = (merge_mods omni_a.statistics omni_b.statistics), + attack = (merge_mods omni_a.attack omni_b.attack), + defense = (merge_mods omni_a.defense omni_b.defense) + } + +apply_to_attributes : Type -> Battle.Struct.Attributes.Type -> Battle.Struct.Attributes.Type +apply_to_attributes omnimods attributes = + (Dict.foldl + ((Battle.Struct.Attributes.decode_category) >> (Battle.Struct.Attributes.mod)) + attributes + omnimods.attributes + ) + +apply_to_statistics : Type -> Battle.Struct.Statistics.Type -> Battle.Struct.Statistics.Type +apply_to_statistics omnimods statistics = + (Dict.foldl + ((Battle.Struct.Statistics.decode_category) >> (Battle.Struct.Statistics.mod)) + statistics + omnimods.statistics + ) + +get_damage_sum : Type -> Int +get_damage_sum omni = + (Dict.foldl (\t -> \v -> \result -> (result + v)) 0 omni.attack) + +get_attack_damage : Float -> Type -> Type -> Int +get_attack_damage dmg_modifier atk_omni def_omni = + let + base_def = + ( + case + (Dict.get + (Battle.Struct.DamageType.encode Battle.Struct.DamageType.Base) + def_omni.defense + ) + of + (Just v) -> v + Nothing -> 0 + ) + in + (Dict.foldl + (\t -> \v -> \result -> + let + actual_atk = + (max + 0 + ( + (ceiling ((toFloat v) * dmg_modifier)) + - base_def + ) + ) + in + case (Dict.get t def_omni.defense) of + (Just def_v) -> (result + (max 0 (actual_atk - def_v))) + Nothing -> (result + actual_atk) + ) + 0 + atk_omni.attack + ) + +get_attributes_mods : Type -> (List (String, Int)) +get_attributes_mods omnimods = (Dict.toList omnimods.attributes) + +get_statistics_mods : Type -> (List (String, Int)) +get_statistics_mods omnimods = (Dict.toList omnimods.statistics) + +get_attack_mods : Type -> (List (String, Int)) +get_attack_mods omnimods = (Dict.toList omnimods.attack) + +get_defense_mods : Type -> (List (String, Int)) +get_defense_mods omnimods = (Dict.toList omnimods.defense) diff --git a/src/shared/battle/Battle/Struct/Statistics.elm b/src/shared/battle/Battle/Struct/Statistics.elm new file mode 100644 index 0000000..e21b4f6 --- /dev/null +++ b/src/shared/battle/Battle/Struct/Statistics.elm @@ -0,0 +1,210 @@ +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, + decode_category, + mod, + new_raw + ) + +-- Elm ------------------------------------------------------------------------- +import List + +-- Battle ---------------------------------------------------------------------- +import Battle.Struct.Attributes + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Category = + MovementPoints + | MaxHealth + | Dodges + | Parries + | Accuracy + | DoubleHits + | CriticalHits + +type alias Type = + { + movement_points : Int, + max_health : Int, + dodges : Int, + parries : Int, + accuracy : Int, + double_hits : Int, + critical_hits : Int, + damage_modifier : Float + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +average : (List Int) -> Float +average l = ((toFloat (List.sum l)) / (toFloat (List.length l))) + +float_to_int : Float -> Int +float_to_int f = + (ceiling f) + +gentle_squared_growth : Int -> Int +gentle_squared_growth v = (float_to_int (((toFloat v)^1.8)/20.0)) + +gentle_squared_growth_f : Float -> Int +gentle_squared_growth_f v = (float_to_int ((v^1.8)/20.0)) + +sudden_squared_growth : Int -> Int +sudden_squared_growth v = (float_to_int (((toFloat v)^2.5)/1000.0)) + +sudden_squared_growth_f : Float -> Int +sudden_squared_growth_f v = (float_to_int ((v^2.5)/1000.0)) + +sudden_exp_growth : Int -> Int +sudden_exp_growth v = (float_to_int (4.0^((toFloat v)/25.0))) + +sudden_exp_growth_f : Float -> Int +sudden_exp_growth_f f = (float_to_int (4.0^(f/25.0))) + +damage_base_mod : Float -> Float +damage_base_mod str = ((((str + 10) * 4)^1.5)/3000.0) + +make_movement_points_safe : Int -> Int +make_movement_points_safe val = (clamp 0 200 val) + +make_max_health_safe : Int -> Int +make_max_health_safe val = (max 1 val) + +make_dodges_safe : Int -> Int +make_dodges_safe val = (clamp 0 100 val) + +make_parries_safe : Int -> Int +make_parries_safe val = (clamp 0 75 val) + +make_accuracy_safe : Int -> Int +make_accuracy_safe val = (clamp 0 100 val) + +make_double_hits_safe : Int -> Int +make_double_hits_safe val = (clamp 0 100 val) + +make_critical_hits_safe : Int -> Int +make_critical_hits_safe val = (clamp 0 100 val) + +mod_movement_points : Int -> Type -> Type +mod_movement_points v t = + {t | + movement_points = (make_movement_points_safe (t.movement_points + v)) + } + +mod_max_health : Int -> Type -> Type +mod_max_health v t = + {t | + max_health = (make_max_health_safe (t.max_health + v)) + } + +mod_dodges : Int -> Type -> Type +mod_dodges v t = {t | dodges = (make_dodges_safe (t.dodges + v))} + +mod_parries : Int -> Type -> Type +mod_parries v t = {t | parries = (make_parries_safe (t.parries + v))} + +mod_accuracy : Int -> Type -> Type +mod_accuracy v t = {t | accuracy = (make_accuracy_safe (t.accuracy + v))} + +mod_double_hits : Int -> Type -> Type +mod_double_hits v t = + {t | + double_hits = (make_double_hits_safe (t.double_hits + v)) + } + +mod_critical_hits : Int -> Type -> Type +mod_critical_hits v t = + {t | + critical_hits = (make_critical_hits_safe (t.critical_hits + v)) + } + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_movement_points : Type -> Int +get_movement_points t = t.movement_points + +get_max_health : Type -> Int +get_max_health t = t.max_health + +get_dodges : Type -> Int +get_dodges t = t.dodges + +get_parries : Type -> Int +get_parries t = t.parries + +get_accuracy : Type -> Int +get_accuracy t = t.accuracy + +get_double_hits : Type -> Int +get_double_hits t = t.double_hits + +get_critical_hits : Type -> Int +get_critical_hits t = t.critical_hits + +get_damage_modifier : Type -> Float +get_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) + +new_raw : (Battle.Struct.Attributes.Type -> Type) +new_raw att = + let + constitution = (Battle.Struct.Attributes.get_constitution att) + dexterity = (Battle.Struct.Attributes.get_dexterity att) + intelligence = (Battle.Struct.Attributes.get_intelligence att) + mind = (Battle.Struct.Attributes.get_mind att) + speed = (Battle.Struct.Attributes.get_speed att) + strength = (Battle.Struct.Attributes.get_strength att) + in + { + movement_points = + (gentle_squared_growth_f + (average [mind, constitution, constitution, speed, speed, speed]) + ), + max_health = + (gentle_squared_growth_f + (average [constitution, constitution, constitution, mind]) + ), + dodges = (sudden_exp_growth_f (average [dexterity, mind, speed])), + parries = + (sudden_exp_growth_f + (average [dexterity, intelligence, speed, strength]) + ), + accuracy = (sudden_squared_growth dexterity), + double_hits = (sudden_squared_growth_f (average [mind, speed])), + critical_hits = (sudden_squared_growth intelligence), + damage_modifier = (damage_base_mod (toFloat strength)) + } + +decode_category : String -> Category +decode_category str = + case str of + "mheal" -> MaxHealth + "mpts" -> MovementPoints + "dodg" -> Dodges + "pary" -> Parries + "accu" -> Accuracy + "dhit" -> DoubleHits + _ -> CriticalHits diff --git a/src/shared/battle/Battle/View/Omnimods.elm b/src/shared/battle/Battle/View/Omnimods.elm new file mode 100644 index 0000000..a946c35 --- /dev/null +++ b/src/shared/battle/Battle/View/Omnimods.elm @@ -0,0 +1,181 @@ +module Battle.View.Omnimods exposing + ( + get_html_with_modifier, + get_html + ) + +-- Elm ------------------------------------------------------------------------- +import List + +import Html +import Html.Attributes +import Html.Events + +-- Battle ---------------------------------------------------------------------- +import Battle.Struct.Omnimods + +-- Local Module ---------------------------------------------------------------- +import Struct.Event + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_mod_html : (String, Int) -> (Html.Html Struct.Event.Type) +get_mod_html mod = + let + (category, value) = mod + in + (Html.div + [ + (Html.Attributes.class "info-card-mod") + ] + [ + (Html.div + [ + (Html.Attributes.class "omnimod-icon"), + (Html.Attributes.class ("omnimod-icon-" ++ category)), + ( + if (value < 0) + then (Html.Attributes.class "omnimod-icon-negative") + else (Html.Attributes.class "omnimod-icon-positive") + ) + ] + [ + ] + ), + (Html.text (String.fromInt value)) + ] + ) + +get_multiplied_mod_html : Float -> (String, Int) -> (Html.Html Struct.Event.Type) +get_multiplied_mod_html multiplier mod = + let + (category, value) = mod + in + (Html.div + [ + (Html.Attributes.class "character-card-mod") + ] + [ + (Html.div + [ + (Html.Attributes.class "omnimod-icon"), + (Html.Attributes.class ("omnimod-icon-" ++ category)), + ( + if (value < 0) + then (Html.Attributes.class "omnimod-icon-negative") + else (Html.Attributes.class "omnimod-icon-positive") + ) + ] + [ + ] + ), + (Html.text + ( + (String.fromInt value) + ++ " (" + ++(String.fromInt (ceiling ((toFloat value) * multiplier))) + ++ ")" + ) + ) + ] + ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html_with_modifier : ( + Float -> + Battle.Struct.Omnimods.Type -> + (Html.Html Struct.Event.Type) + ) +get_html_with_modifier attack_multiplier omnimods = + (Html.div + [ + (Html.Attributes.class "omnimod-listing") + ] + [ + (Html.div + [ + (Html.Attributes.class "omnimod-attack-mods") + ] + (List.map + (get_multiplied_mod_html attack_multiplier) + (Battle.Struct.Omnimods.get_attack_mods omnimods) + ) + ), + (Html.div + [ + (Html.Attributes.class "omnimod-defense-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_defense_mods omnimods) + ) + ), + (Html.div + [ + (Html.Attributes.class "omnimod-attribute-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_attributes_mods omnimods) + ) + ), + (Html.div + [ + (Html.Attributes.class "omnimod-statistics-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_statistics_mods omnimods) + ) + ) + ] + ) + +get_html : Battle.Struct.Omnimods.Type -> (Html.Html Struct.Event.Type) +get_html omnimods = + (Html.div + [ + (Html.Attributes.class "omnimod-listing") + ] + [ + (Html.div + [ + (Html.Attributes.class "omnimod-attack-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_attack_mods omnimods) + ) + ), + (Html.div + [ + (Html.Attributes.class "omnimod-defense-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_defense_mods omnimods) + ) + ), + (Html.div + [ + (Html.Attributes.class "omnimod-attribute-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_attributes_mods omnimods) + ) + ), + (Html.div + [ + (Html.Attributes.class "omnimod-statistics-mods") + ] + (List.map + (get_mod_html) + (Battle.Struct.Omnimods.get_statistics_mods omnimods) + ) + ) + ] + ) |