summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-29 20:53:59 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-29 20:53:59 +0200 |
commit | bf2f7f1489ad3ebac815ede253cf7be9242df3a3 (patch) | |
tree | 009c5b29816c8d19068e0b72925e7470794d5ce6 | |
parent | 236ab8b21b9daa751a25c140609ea5bb253bf87e (diff) |
Still working on it...
Turns out enumerables are not considered to be "comparable". That might
make the code a bit more ugly...
-rw-r--r-- | src/battle/src/Struct/Attributes.elm | 22 | ||||
-rw-r--r-- | src/battle/src/Struct/DamageType.elm | 4 | ||||
-rw-r--r-- | src/battle/src/Struct/Omnimods.elm | 147 | ||||
-rw-r--r-- | src/battle/src/Struct/Statistics.elm | 36 | ||||
-rw-r--r-- | src/battle/src/Struct/Weapon.elm | 203 |
5 files changed, 192 insertions, 220 deletions
diff --git a/src/battle/src/Struct/Attributes.elm b/src/battle/src/Struct/Attributes.elm index 89fd1f1..ce871dd 100644 --- a/src/battle/src/Struct/Attributes.elm +++ b/src/battle/src/Struct/Attributes.elm @@ -22,10 +22,8 @@ module Struct.Attributes exposing ) -- Elm ------------------------------------------------------------------------- -import Json.Decode -import Json.Decode.Pipeline --- Map ------------------------------------------------------------------- +-- Battle ---------------------------------------------------------------------- -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -124,15 +122,15 @@ mod cat i t = Speed -> (mod_speed i t) Strength -> (mod_strength i t) -get : Category -> Int -> Type -> Type -get cat i t = +get : Category -> Type -> Int +get cat t = case cat of - Constitution -> (get_constitution i t) - Dexterity -> (get_dexterity i t) - Intelligence -> (get_intelligence i t) - Mind -> (get_mind i t) - Speed -> (get_speed i t) - Strength -> (get_strength i t) + 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 @@ -164,7 +162,7 @@ default = strength = 50 } -decode_category : String -> Type +decode_category : String -> Category decode_category str = case str of "con" -> Constitution diff --git a/src/battle/src/Struct/DamageType.elm b/src/battle/src/Struct/DamageType.elm index 2b16e75..b7bced7 100644 --- a/src/battle/src/Struct/DamageType.elm +++ b/src/battle/src/Struct/DamageType.elm @@ -38,7 +38,7 @@ decode str = encode : Type -> String encode t = - case str of + case t of Base -> "bse" Slash -> "slh" Pierce -> "pie" @@ -47,7 +47,7 @@ encode t = to_string : Type -> String to_string t = - case str of + case t of Base -> "Base" Slash -> "Slash" Pierce -> "Piercing" diff --git a/src/battle/src/Struct/Omnimods.elm b/src/battle/src/Struct/Omnimods.elm index 5c7085a..2b8088f 100644 --- a/src/battle/src/Struct/Omnimods.elm +++ b/src/battle/src/Struct/Omnimods.elm @@ -6,10 +6,12 @@ module Struct.Omnimods exposing apply_to_attributes, apply_to_statistics, get_attack_damage, - decode + decoder ) -- Elm ------------------------------------------------------------------------- +import Dict + import Json.Decode import Json.Decode.Pipeline @@ -29,22 +31,147 @@ type alias Type = defense : (Dict.Dict Struct.DamageType.Type Int) } +type alias GenericMod = + { + t : String, + v : Int + } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +generic_mod_decoder : (Json.Decode.Decoder GenericMod) +generic_mod_decoder = + (Json.Decode.Pipeline.decode + GenericMod + |> (Json.Decode.Pipeline.required "t" Json.Decode.string) + |> (Json.Decode.Pipeline.required "v" Json.Decode.int) + ) + +generic_mod_to_attribute_mod : GenericMod -> (Struct.Attributes.Category, Int) +generic_mod_to_attribute_mod genm = + ((Struct.Attributes.decode_category genm.t), genm.v) + +attribute_mods_decoder : ( + (Json.Decode.Decoder (Dict.Dict Struct.Attributes.Category Int)) + ) +attribute_mods_decoder = + (Json.Decode.map + (Dict.fromList) + (Json.Decode.list + (Json.Decode.map (generic_mod_to_attribute_mod) generic_mod_decoder) + ) + ) + +generic_mod_to_statistic_mod : GenericMod -> (Struct.Attributes.Category, Int) +generic_mod_to_statistic_mod genm = + ((Struct.Statistics.decode_category genm.t), genm.v) + +statistic_mods_decoder : ( + (Json.Decode.Decoder (Dict.Dict Struct.Statistics.Category Int)) + ) +statistic_mods_decoder = + (Json.Decode.map + (Dict.fromList) + (Json.Decode.list + (Json.Decode.map (generic_mod_to_statistic_mod) generic_mod_decoder) + ) + ) + +generic_mod_to_damage_mod : GenericMod -> (Struct.DamageType.Type, Int) +generic_mod_to_damage_mod genm = + ((Struct.DamageType.decode genm.t), genm.v) + +damage_mods_decoder : ( + (Json.Decode.Decoder (Dict.Dict Struct.DamageType.Type Int)) + ) +damage_mods_decoder = + (Json.Decode.map + (Dict.fromList) + (Json.Decode.list + (Json.Decode.map (generic_mod_to_damage_mod) generic_mod_decoder) + ) + ) + +merge_mods : (Dict.Dict a Int) -> (Dict.Dict a Int) -> (Dict.Dict a Int) +merge_mods a_mods b_mods = + (Dict.merge + (Dict.insert) + (\t -> \v_a -> \v_b -> (Dict.insert t (v_a + v_b))) + (Dict.insert) + a_mods + b_mods + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- decoder : (Json.Decode.Decoder Type) decoder = - (Json.Decode.map - (finish_decoding) - (Json.Decode.Pipeline.decode - PartiallyDecoded - |> (Json.Decode.Pipeline.required "id" Json.Decode.int) - |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) - |> (Json.Decode.Pipeline.required "ct" Json.Decode.string) - |> (Json.Decode.Pipeline.required "cf" Json.Decode.float) - ) + (Json.Decode.Pipeline.decode + Type + |> (Json.Decode.Pipeline.required "attm" attribute_mods_decoder) + |> (Json.Decode.Pipeline.required "stam" statistic_mods_decoder) + |> (Json.Decode.Pipeline.required "atkm" damage_mods_decoder) + |> (Json.Decode.Pipeline.required "defm" damage_mods_decoder) + ) + +new : ( + (List (Struct.Attributes.Category, Int)) -> + (List (Struct.Statistics.Category, Int)) -> + (List (Struct.DamageType.Type, Int)) -> + (List (Struct.DamageType.Type, 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 -> Struct.Attributes.Type -> Struct.Attributes.Type +apply_to_attributes omnimods attributes = + (Dict.foldl (Struct.Attributes.mod) attributes omnimods.attributes) + +apply_to_statistics : Type -> Struct.Statistics.Type -> Struct.Statistics.Type +apply_to_statistics omnimods statistics = + (Dict.foldl (Struct.Statistics.mod) statistics omnimods.statistics) + +get_attack_damage : Int -> Type -> Type -> Int +get_attack_damage dmg_modifier atk_omni def_omni = + let + base_def = + ( + case (Dict.get 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) + ) + atk_omni.attack + ) diff --git a/src/battle/src/Struct/Statistics.elm b/src/battle/src/Struct/Statistics.elm index 834cb31..064d806 100644 --- a/src/battle/src/Struct/Statistics.elm +++ b/src/battle/src/Struct/Statistics.elm @@ -11,7 +11,8 @@ module Struct.Statistics exposing get_critical_hits, get_damage_modifier, decode_category, - new + mod, + new_raw ) -- Elm ------------------------------------------------------------------------- @@ -75,23 +76,23 @@ sudden_exp_growth_f f = (float_to_int (4.0^(f/25.0))) damage_base_mod : Float -> Float damage_base_mod str = (((str^1.8)/2000.0) - 0.75) -make_movement_points_safe : Int -> Int -make_movement_points_safe val -> (clamp 0 200 val) +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_max_health_safe val = (max 1 val) make_dodges_safe : Int -> Int -make_dodges_safe val -> (clamp 0 100 val) +make_dodges_safe val = (clamp 0 100 val) make_parries_safe : Int -> Int -make_parries_safe val -> (clamp 0 75 val) +make_parries_safe val = (clamp 0 75 val) make_accuracy_safe : Int -> Int -make_accuracy_safe val -> (clamp 0 100 val) +make_accuracy_safe val = (clamp 0 100 val) make_double_hits_safe : Int -> Int -make_double_hits_safe val -> (clamp 0 100 val) +make_double_hits_safe val = (clamp 0 100 val) make_critical_hits_safe : Int -> Int make_critical_hits_safe val = (clamp 0 100 val) @@ -144,12 +145,6 @@ get_dodges t = t.dodges get_parries : Type -> Int get_parries t = t.parries -get_damage_min : Type -> Int -get_damage_min t = t.damage_min - -get_damage_max : Type -> Int -get_damage_max t = t.damage_max - get_accuracy : Type -> Int get_accuracy t = t.accuracy @@ -162,6 +157,17 @@ 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 : (Struct.Attributes.Type -> Type) new_raw att = let @@ -192,7 +198,7 @@ new_raw att = damage_modifier = (damage_base_mod (toFloat strength)) } -decode_category : String -> Type +decode_category : String -> Category decode_category str = case str of "mheal" -> MaxHealth diff --git a/src/battle/src/Struct/Weapon.elm b/src/battle/src/Struct/Weapon.elm index d572ed6..7f9a049 100644 --- a/src/battle/src/Struct/Weapon.elm +++ b/src/battle/src/Struct/Weapon.elm @@ -2,24 +2,14 @@ module Struct.Weapon exposing ( Type, Ref, - RangeType(..), - RangeModifier(..), - DamageType(..), - DamageModifier(..), new, get_id, get_name, - get_range_type, - get_range_modifier, - get_damage_type, - get_damage_modifier, get_attack_range, get_defense_range, - get_max_damage, - get_min_damage, + get_omnimods, decoder, - none, - apply_to_attributes + none ) -- Elm ------------------------------------------------------------------------- @@ -27,7 +17,7 @@ import Json.Decode import Json.Decode.Pipeline -- Map ------------------------------------------------------------------- -import Struct.Attributes +import Struct.Omnimods -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -36,96 +26,37 @@ type alias PartiallyDecoded = { id : Int, nam : String, - rt : String, - rm : String, - dt : String, - dm : String, - cf : Float + rmi : Int, + rma : Int, + omni : String } type alias Type = { id : Int, name : String, - coef : Float, - range_type : RangeType, - range_mod : RangeModifier, - dmg_type : DamageType, - dmg_mod : DamageModifier, def_range : Int, atk_range : Int, - dmg_min : Int, - dmg_max : Int + omnimods : Struct.Omnimods.Type } type alias Ref = Int -type RangeType = Ranged | Melee -type RangeModifier = Long | Short --- Having multiple types at the same time, like Warframe does, would be nice. -type DamageType = Slash | Blunt | Pierce -type DamageModifier = Heavy | Light - -type alias WeaponType = - { - range : RangeType, - range_mod : RangeModifier, - dmg_type : DamageType - } - -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_ranges : RangeType -> RangeModifier -> (Int, Int) -get_ranges rt rm = - case (rt, rm) of - (Ranged, Long) -> (2, 6) - (Ranged, Short) -> (1, 4) - (Melee, Long) -> (0, 2) - (Melee, Short) -> (0, 1) - -get_damages : Float -> RangeType -> DamageModifier -> (Int, Int) -get_damages coef rt dm = - case (rt, dm) of - (Ranged, Heavy) -> ((ceiling (15.0 * coef)), (ceiling (30.0 * coef))) - (Ranged, Light) -> ((ceiling (10.0 * coef)), (ceiling (25.0 * coef))) - (Melee, Heavy) -> ((ceiling (20.0 * coef)), (ceiling (35.0 * coef))) - (Melee, Light) -> ((ceiling (15.0 * coef)), (ceiling (30.0 * coef))) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -new : ( - Int -> - String -> - Float -> - RangeType -> - RangeModifier -> - DamageType -> - DamageModifier -> - Type - ) -new - id name coef - range_type range_mod - dmg_type dmg_mod - = - let - (def_range, atk_range) = (get_ranges range_type range_mod) - (dmg_min, dmg_max) = (get_damages coef range_type dmg_mod) - in +new : Int -> String -> Int -> Int -> Struct.Omnimods.Type -> Type +new id name range_min range_max omnimods = { id = id, name = name, - coef = coef, - range_type = range_type, - range_mod = range_mod, - dmg_type = dmg_type, - dmg_mod = dmg_mod, - def_range = def_range, - atk_range = atk_range, - dmg_min = dmg_min, - dmg_max = dmg_max + def_range = range_min, + atk_range = range_max, + omnimods = omnimods } get_id : Type -> Int @@ -134,115 +65,25 @@ get_id wp = wp.id get_name : Type -> String get_name wp = wp.name -get_range_type : Type -> RangeType -get_range_type wp = wp.range_type - -get_range_modifier : Type -> RangeModifier -get_range_modifier wp = wp.range_mod - -get_damage_type : Type -> DamageType -get_damage_type wp = wp.dmg_type - -get_damage_modifier : Type -> DamageModifier -get_damage_modifier wp = wp.dmg_mod - get_attack_range : Type -> Int get_attack_range wp = wp.atk_range get_defense_range : Type -> Int get_defense_range wp = wp.def_range -get_max_damage : Type -> Int -get_max_damage wp = wp.dmg_max - -get_min_damage : Type -> Int -get_min_damage wp = wp.dmg_min - -apply_to_attributes : Type -> Struct.Attributes.Type -> Struct.Attributes.Type -apply_to_attributes wp atts = - let - impact = (20.0 * wp.coef) - full_impact = (-1 * (ceiling impact)) - quarter_impact = (-1 * (ceiling (impact / 4.0))) - in - case (wp.range_mod, wp.dmg_mod) of - (Long, Heavy) -> - (Struct.Attributes.mod_dexterity - full_impact - (Struct.Attributes.mod_speed full_impact atts) - ) - - (Long, Light) -> - (Struct.Attributes.mod_dexterity - full_impact - (Struct.Attributes.mod_speed quarter_impact atts) - ) - - (Short, Heavy) -> - (Struct.Attributes.mod_dexterity - quarter_impact - (Struct.Attributes.mod_speed full_impact atts) - ) - - (Short, Light) -> - (Struct.Attributes.mod_dexterity - quarter_impact - (Struct.Attributes.mod_speed quarter_impact atts) - ) - -finish_decoding : PartiallyDecoded -> Type -finish_decoding add_weapon = - (new - add_weapon.id - add_weapon.nam - add_weapon.cf - ( - case add_weapon.rt of - "m" -> Melee - _ -> Ranged - ) - ( - case add_weapon.rm of - "l" -> Long - _ -> Short - ) - ( - case add_weapon.dt of - "s" -> Slash - "p" -> Pierce - _ -> Blunt - ) - ( - case add_weapon.dm of - "l" -> Light - _ -> Heavy - ) - ) +get_omnimods : Type -> Struct.Omnimods.Type +get_omnimods wp = wp.omnimods decoder : (Json.Decode.Decoder Type) decoder = - (Json.Decode.map - (finish_decoding) - (Json.Decode.Pipeline.decode - PartiallyDecoded - |> (Json.Decode.Pipeline.required "id" Json.Decode.int) - |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) - |> (Json.Decode.Pipeline.required "rt" Json.Decode.string) - |> (Json.Decode.Pipeline.required "rm" Json.Decode.string) - |> (Json.Decode.Pipeline.required "dt" Json.Decode.string) - |> (Json.Decode.Pipeline.required "dm" Json.Decode.string) - |> (Json.Decode.Pipeline.required "cf" Json.Decode.float) - ) + (Json.Decode.Pipeline.decode + Type + |> (Json.Decode.Pipeline.required "id" Json.Decode.int) + |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) + |> (Json.Decode.Pipeline.required "rmi" Json.Decode.int) + |> (Json.Decode.Pipeline.required "rma" Json.Decode.int) + |> (Json.Decode.Pipeline.required "omni" Struct.Omnimods.decoder) ) none : Type -none = - (new - 0 - "None" - 0.0 - Melee - Short - Blunt - Light - ) +none = (new 0 "None" 0 0 (Struct.Omnimods.new [] [] [] [])) |