| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
3 files changed, 316 insertions, 216 deletions
| diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm index 12f63ba..868519d 100644 --- a/src/battle/src/Struct/Character.elm +++ b/src/battle/src/Struct/Character.elm @@ -2,33 +2,24 @@ module Struct.Character exposing     (        Type,        Rank(..), -      TypeAndEquipmentRef, +      Unresolved,        get_index,        get_player_ix, -      get_name,        get_rank, -      get_portrait, -      get_armor,        get_current_health, -      get_current_omnimods,        get_sane_current_health,        set_current_health,        get_location,        set_location, -      get_attributes, -      get_statistics,        is_enabled,        is_defeated,        is_alive,        set_enabled,        set_defeated, -      get_primary_weapon, -      get_secondary_weapon, -      toggle_is_using_primary, -      get_is_using_primary, +      get_base_character, +      set_base_character,        decoder, -      refresh_omnimods, -      fill_missing_equipment_and_omnimods +      resolve     )  -- Elm ------------------------------------------------------------------------- @@ -36,14 +27,10 @@ import Json.Decode  import Json.Decode.Pipeline  -- Battle ---------------------------------------------------------------------- -import Battle.Struct.Attributes  import Battle.Struct.Omnimods -import Battle.Struct.Statistics  -- Battle Characters ----------------------------------------------------------- -import BattleCharacters.Struct.Armor -import BattleCharacters.Struct.Portrait -import BattleCharacters.Struct.Weapon +import BattleCharacters.Struct.Character  -- Battle Map ------------------------------------------------------------------  import BattleMap.Struct.Location @@ -51,24 +38,6 @@ import BattleMap.Struct.Location  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -type alias PartiallyDecoded = -   { -      ix : Int, -      nam : String, -      rnk : String, -      prt : String, -      lc : BattleMap.Struct.Location.Type, -      hea : Int, -      pla : Int, -      ena : Bool, -      dea : Bool, -      awp : BattleCharacters.Struct.Weapon.Ref, -      swp : BattleCharacters.Struct.Weapon.Ref, -      ar : BattleCharacters.Struct.Armor.Ref, -      omni : Battle.Struct.Omnimods.Type -   } - -  type Rank =     Optional     | Target @@ -77,31 +46,25 @@ type Rank =  type alias Type =     {        ix : Int, -      name : String,        rank : Rank, -      portrait : BattleCharacters.Struct.Portrait.Type,        location : BattleMap.Struct.Location.Type,        health : Int,        player_ix : Int,        enabled : Bool,        defeated : Bool, -      attributes : Battle.Struct.Attributes.Type, -      statistics : Battle.Struct.Statistics.Type, -      primary_weapon : BattleCharacters.Struct.Weapon.Type, -      secondary_weapon : BattleCharacters.Struct.Weapon.Type, -      is_using_primary : Bool, -      armor : BattleCharacters.Struct.Armor.Type, -      current_omnimods : Battle.Struct.Omnimods.Type, -      permanent_omnimods : Battle.Struct.Omnimods.Type +      base : BattleCharacters.Struct.Character.Type     } -type alias TypeAndEquipmentRef = +type alias Unresolved =     { -      char : Type, -      main_weapon_ref : String, -      secondary_weapon_ref : String, -      armor_ref : String, -      portrait_ref : String +      ix : Int, +      rank : Rank, +      location : BattleMap.Struct.Location.Type, +      health : Int, +      player_ix : Int, +      enabled : Bool, +      defeated : Bool, +      base : BattleCharacters.Struct.Character.Unresolved     }  -------------------------------------------------------------------------------- @@ -114,39 +77,26 @@ str_to_rank str =        "c" -> Commander        _ -> Optional -finish_decoding : PartiallyDecoded -> TypeAndEquipmentRef -finish_decoding add_char = +fix_health : Int -> Type -> Type +fix_health previous_max_health char =     let -      armor = BattleCharacters.Struct.Armor.none -      portrait = BattleCharacters.Struct.Portrait.default -      default_attributes = (Battle.Struct.Attributes.default) -      almost_char = -         { -            ix = add_char.ix, -            name = add_char.nam, -            rank = (str_to_rank add_char.rnk), -            portrait = portrait, -            location = add_char.lc, -            health = add_char.hea, -            attributes = default_attributes, -            statistics = (Battle.Struct.Statistics.new_raw default_attributes), -            player_ix = add_char.pla, -            enabled = add_char.ena, -            defeated = add_char.dea, -            primary_weapon = BattleCharacters.Struct.Weapon.none, -            secondary_weapon = BattleCharacters.Struct.Weapon.none, -            is_using_primary = True, -            armor = armor, -            current_omnimods = (Battle.Struct.Omnimods.new [] [] [] []), -            permanent_omnimods = add_char.omni -         } +      new_max_health = +         (Battle.Struct.Statistics.get_max_health +            (BattleCharacters.Struct.Character.get_statistics char.base) +         )     in -      { -         char = almost_char, -         main_weapon_ref = add_char.awp, -         secondary_weapon_ref = add_char.swp, -         armor_ref = add_char.ar, -         portrait_ref = add_char.prt +      {char | +         health = +            (clamp +               1 +               new_max_health +               (round +                  ( +                     ((toFloat char.health) / (toFloat previous_max_health)) +                     * (toFloat new_max_health) +                  ) +               ) +            )        }  -------------------------------------------------------------------------------- @@ -155,9 +105,6 @@ finish_decoding add_char =  get_index : Type -> Int  get_index c = c.ix -get_name : Type -> String -get_name c = c.name -  get_rank : Type -> Rank  get_rank c = c.rank @@ -167,9 +114,6 @@ get_player_ix c = c.player_ix  get_current_health : Type -> Int  get_current_health c = c.health -get_current_omnimods : Type -> Battle.Struct.Omnimods.Type -get_current_omnimods c = c.current_omnimods -  get_sane_current_health : Type -> Int  get_sane_current_health c = (max 0 c.health) @@ -179,14 +123,42 @@ set_current_health health c = {c | health = health}  get_location : Type -> BattleMap.Struct.Location.Type  get_location t = t.location -set_location : BattleMap.Struct.Location.Type -> Type -> Type -set_location location char = {char | location = location} +set_location : ( +      BattleMap.Struct.Location.Type -> +      Battle.Struct.Omnimods.Type -> +      Type -> +      Type +set_location location omnimods char = +   let +      previous_max_health = +         (Battle.Struct.Statistics.get_max_health +            (BattleCharacters.Struct.Character.get_statistics char.base) +         ) +   in +      (fix_health +         previous_max_health +         {char | +            location = location, +            base = +               (BattleCharacters.Struct.Character.set_extra_omnimods omnimods) +         } +      ) -get_attributes : Type -> Battle.Struct.Attributes.Type -get_attributes char = char.attributes +get_base_character : Type -> BattleCharacters.Struct.Character.Type +get_base_character char = char.base -get_statistics : Type -> Battle.Struct.Statistics.Type -get_statistics char = char.statistics +set_base_character : BattleCharacters.Struct.Character.Type -> Type -> Type +set_base_character new_base char = +   let +      previous_max_health = +         (Battle.Struct.Statistics.get_max_health +            (BattleCharacters.Struct.Character.get_statistics char.base) +         ) +   in +      (fix_health +         previous_max_health +         {char | base = new_base} +      )  is_alive : Type -> Bool  is_alive char = ((char.health > 0) && (not char.defeated)) @@ -203,124 +175,54 @@ set_enabled enabled char = {char | enabled = enabled}  set_defeated : Bool -> Type -> Type  set_defeated defeated char = {char | defeated = defeated} -get_primary_weapon : Type -> BattleCharacters.Struct.Weapon.Type -get_primary_weapon char = char.primary_weapon - -get_secondary_weapon : Type -> BattleCharacters.Struct.Weapon.Type -get_secondary_weapon char = char.secondary_weapon - -get_is_using_primary : Type -> Bool -get_is_using_primary char = char.is_using_primary - -toggle_is_using_primary : Type -> Type -toggle_is_using_primary char = -   {char | is_using_primary = (not char.is_using_primary)} - -get_armor : Type -> BattleCharacters.Struct.Armor.Type -get_armor char = char.armor - -get_portrait : Type -> BattleCharacters.Struct.Portrait.Type -get_portrait char = char.portrait - -decoder : (Json.Decode.Decoder TypeAndEquipmentRef) +decoder : (Json.Decode.Decoder Unresolved)  decoder = -   (Json.Decode.map -      (finish_decoding) -      (Json.Decode.succeed -         PartiallyDecoded -         |> (Json.Decode.Pipeline.required "ix" Json.Decode.int) -         |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) -         |> (Json.Decode.Pipeline.required "rnk" Json.Decode.string) -         |> (Json.Decode.Pipeline.required "prt" Json.Decode.string) -         |> (Json.Decode.Pipeline.required "lc" BattleMap.Struct.Location.decoder) -         |> (Json.Decode.Pipeline.required "hea" Json.Decode.int) -         |> (Json.Decode.Pipeline.required "pla" Json.Decode.int) -         |> (Json.Decode.Pipeline.required "ena" Json.Decode.bool) -         |> (Json.Decode.Pipeline.required "dea" Json.Decode.bool) -         |> (Json.Decode.Pipeline.required "awp" Json.Decode.string) -         |> (Json.Decode.Pipeline.required "swp" Json.Decode.string) -         |> (Json.Decode.Pipeline.required "ar" Json.Decode.string) -         |> +   (Json.Decode.succeed +      Unresolved +      |> (Json.Decode.Pipeline.required "ix" Json.Decode.int) +      |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) +      |>           (Json.Decode.Pipeline.required -            "pomni" -            Battle.Struct.Omnimods.decoder -         ) -      ) -   ) - -refresh_omnimods : ( -      (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) -> -      Type -> -      Type -   ) -refresh_omnimods tile_omnimods_fun char = -   let -      previous_max_health = -         (Battle.Struct.Statistics.get_max_health char.statistics) -      current_omnimods = -         (Battle.Struct.Omnimods.merge -            (BattleCharacters.Struct.Weapon.get_omnimods -               ( -                  if (char.is_using_primary) -                  then char.primary_weapon -                  else char.secondary_weapon -               ) -            ) -            (Battle.Struct.Omnimods.merge -               (tile_omnimods_fun char.location) -               char.permanent_omnimods +            "rnk" +            (Json.Decode.map +               (str_to_rank) +               (Json.Decode.string)              )           ) -      current_attributes = -         (Battle.Struct.Omnimods.apply_to_attributes -            current_omnimods -            (Battle.Struct.Attributes.default) -         ) -      current_statistics = -         (Battle.Struct.Omnimods.apply_to_statistics -            current_omnimods -            (Battle.Struct.Statistics.new_raw current_attributes) +      |> (Json.Decode.Pipeline.required "lc" BattleMap.Struct.Location.decoder) +      |> (Json.Decode.Pipeline.required "hea" Json.Decode.int) +      |> (Json.Decode.Pipeline.required "pla" Json.Decode.int) +      |> (Json.Decode.Pipeline.required "ena" Json.Decode.bool) +      |> (Json.Decode.Pipeline.required "dea" Json.Decode.bool) +      |> +         (Json.Decode.Pipeline.required +            "bas" +            (BattleCharacters.Struct.Character.decoder)           ) -      new_max_health = -         (Battle.Struct.Statistics.get_max_health current_statistics) -   in -      {char | -         attributes = current_attributes, -         statistics = current_statistics, -         current_omnimods = current_omnimods, -         health = -            (clamp -               1 -               new_max_health -               (round -                  ( -                     ((toFloat char.health) / (toFloat previous_max_health)) -                     * (toFloat new_max_health) -                  ) -               ) -            ) -      } +   ) -fill_missing_equipment_and_omnimods : ( +resolve : (        (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) -> -      BattleCharacters.Struct.Portrait.Type -> -      BattleCharacters.Struct.Weapon.Type -> -      BattleCharacters.Struct.Weapon.Type -> -      BattleCharacters.Struct.Armor.Type -> -      Type -> +      ( +         BattleCharacters.Struct.Equipment.Unresolved -> +         BattleCharacters.Struct.Equipment.Type +      ) -> +      Unresolved ->        Type     ) -fill_missing_equipment_and_omnimods tile_omnimods_fun pt awp swp ar char = -   (set_current_health -      -- We just changed the omnimods, but already had the right health value -      char.health -      (refresh_omnimods -         (tile_omnimods_fun) -         {char | -            primary_weapon = awp, -            secondary_weapon = swp, -            armor = ar, -            portrait = pt -         } -      ) -   ) +resolve location_omnimod_resolver equipment_resolver ref = +   { +      ix = ref.ix, +      rank = ref.rank, +      location = ref.location, +      health = ref.location, +      player_ix = ref.player_ix, +      enabled = ref.enabled, +      defeated = ref.defeated, +      base = +         (BattleCharacters.Struct.Character.resolve +            (equipment_resolver) +            (location_omnimod_resolver ref.location) +            ref.base +         ) +   } diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Character.elm b/src/shared/battle-characters/BattleCharacters/Struct/Character.elm new file mode 100644 index 0000000..adf7ca7 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/Character.elm @@ -0,0 +1,196 @@ +module BattleCharacters.Struct.Character exposing +   ( +      Type, +      Unresolved, +      get_name, +      set_name, +      get_equipment, +      set_equipment, +      get_omnimods, +      set_extra_omnimods, +      get_attributes, +      get_statistics, +      get_active_weapon, +      get_inactive_weapon, +      switch_weapons, +      decoder, +      encode, +      resolve +   ) + +-- Elm ------------------------------------------------------------------------- + +-- Battle ---------------------------------------------------------------------- +import Battle.Struct.Omnimods +import Battle.Struct.Attributes +import Battle.Struct.Statistics + +-- Battle Characters ----------------------------------------------------------- +import BattleCharacters.Struct.Armor +import BattleCharacters.Struct.Equipment +import BattleCharacters.Struct.Weapon +import BattleCharacters.Struct.GlyphBoard + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = +   { +      name : String, +      equipment : BattleCharacters.Struct.Equipment, +      attributes : Battle.Struct.Attributes.Type, +      statistics : Battle.Struct.Statistics.Type, +      is_using_secondary : Bool, +      omnimods : Battle.Struct.Omnimods.Type, +      extra_omnimods : Battle.Struct.Omnimods.Type, +   } + +type alias Unresolved = +   { +      name : String, +      equipment : BattleCharacters.Struct.Unresolved, +      is_using_secondary : Bool +   } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +refresh_omnimods : Type -> Type +refresh_omnimods char = +   let +      equipment = char.equipment +      omnimods = +         (Battle.Struct.Omnimods.merge +            (Battle.Struct.Omnimods.merge +               (Battle.Struct.Omnimods.merge +                  char.extra_omnimods +                  (BattleCharacters.Struct.Weapon.get_omnimods +                     (get_active_weapon char) +                  ) +               ) +               (BattleCharacters.Struct.Armor.get_omnimods +                  (BattleCharacters.Struct.Equipment.get_armor equipment) +               ) +            ) +            (BattleCharacters.Struct.GlyphBoard.get_omnimods_with_glyphs +               (BattleCharacters.Struct.Equipment.get_glyphs equipment) +               (BattleCharacters.Struct.Equipment.get_glyph_board equipment) +            ) +         ) +      attributes = +         (Battle.Struct.Omnimods.apply_to_attributes +            omnimods +            (Battle.Struct.Attributes.default) +         ) +      statistics = +         (Battle.Struct.Omnimods.apply_to_statistics +            omnimods +            (Battle.Struct.Statistics.new_raw attributes) +         ) +   in +      {char | +         attributes = attributes, +         statistics = statistics, +         omnimods = omnimods +      } + + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_active_weapon : Type -> BattleCharacters.Struct.Weapon.Type +get_active_weapon char +   if (char.is_using_secondary) +   then (BattleCharacters.Struct.Equipment.get_secondary_weapon char.equipment) +   else (BattleCharacters.Struct.Equipment.get_primary_weapon char.equipment) + +get_inactive_weapon : Type -> BattleCharacters.Struct.Weapon.Type +get_inactive_weapon char = +   if (char.is_using_secondary) +   then (BattleCharacters.Struct.Equipment.get_primary_weapon char.equipment) +   then (BattleCharacters.Struct.Equipment.get_secondary_weapon char.equipment) + +get_name : Type -> String +get_name c = c.name + +set_name : String -> Type -> Type +set_name name char = {char | name = name} + +get_equipment : Type -> BattleCharacters.Struct.Equipment.Type +get_equipment c = c.equipment + +set_equipment : BattleCharacters.Struct.Equipment.Type -> Type -> Type +set_equipment equipment char = (refresh_omnimods {char | equipment = equipment}) + +get_omnimods : Type -> Battle.Struct.Omnimods.Type +get_omnimods c = c.current_omnimods + +set_extra_omnimods : Battle.Struct.Omnimods.Type -> Type -> Type +set_extra_omnimods om c = (refresh_omnimods {char | extra_omnimods = om}) + +get_attributes : Type -> Battle.Struct.Attributes.Type +get_attributes char = char.attributes + +get_statistics : Type -> Battle.Struct.Statistics.Type +get_statistics char = char.statistics + +switch_weapons : Type -> Type +switch_weapons char = +   (refresh_omnimods +      {char | is_using_secondary = (not char.is_using_secondary)} +   ) + +decoder : (Json.Decode.Decoder Unresolved) +decoder : +   (Json.Decode.succeed +      Unresolved +      |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) +      |> +         (Json.Decode.Pipeline.required +            "eq" +            BattleCharacters.Struct.Equipment.decoder +         ) +      |> (Json.Decode.Pipeline.required "sec" Json.Decode.bool) +   ) + +to_unresolved : Type -> Unresolved +to_unresolved char = +   { +      name = char.name, +      equipment = +         (BattleCharacters.Struct.Equipment.to_unresolved char.equipment), +      is_using_secondary = char.is_using_secondary +   } + +encode : Unresolved -> Json.Encode.Value +encode ref = +   (Json.Encode.object +      [ +         ("nam", (Json.Encode.string ref.name)), +         ("eq", (BattleCharacters.Struct.Equipment.encode ref.equipment)), +         ("sec", (Json.Encode.bool ref.is_using_secondary)) +      ] +   ) + +resolve : ( +      ( +         BattleCharacters.Struct.Equipment.Unresolved -> +         BattleCharacters.Struct.Equipment.Type +      ) -> +      Battle.Struct.Omnimods.Type -> +      Unresolved -> +      Type +   ) +resolve resolve_equipment extra_omnimods ref = +   let default_attributes = (Battle.Struct.Attributes.default) in +   (refresh_omnimods +      { +         name = ref.name, +         equipment = (resolve_equipment ref.equipment), +         attributes = default_attributes, +         statistics = (Battle.Struct.Statistics.new_raw default_attributes), +         is_using_secondary = ref.is_using_secondary, +         omnimods = (Battle.Struct.Omnimods.none), +         extra_omnimods = extra_omnimods +      } +   ) diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm b/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm index 8782397..2a3df55 100644 --- a/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm +++ b/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm @@ -1,5 +1,7 @@  module BattleCharacters.Struct.Equipment exposing     ( +      Type, +      Unresolved,        get_primary_weapon,        get_secondary_weapon,        get_armor, @@ -49,7 +51,7 @@ type alias Type =        glyphs : (Array.Array BattleCharacters.Struct.Glyph.Type)     } -type alias Ref = +type alias Unresolved =     {        primary : BattleCharacters.Struct.Weapon.Ref,        secondary : BattleCharacters.Struct.Weapon.Ref, @@ -114,10 +116,10 @@ set_glyph : Int -> BattleCharacters.Struct.Glyph.Type -> Type -> Type  set_glyph index glyph equipment =     { equipment | glyphs = (Array.set index glyph equipment.glyphs) } -ref_decoder : (Json.Decode.Decoder Type) -ref_decoder = +decoder : (Json.Decode.Decoder Unresolved) +decoder =     (Json.Decode.succeed -      Ref +      Unresolved        |> (Json.Decode.Pipeline.required "pr" Json.Decode.string)        |> (Json.Decode.Pipeline.required "sc" Json.Decode.string)        |> (Json.Decode.Pipeline.required "ar" Json.Decode.string) @@ -130,8 +132,8 @@ ref_decoder =           )     ) -ref_encoder : Ref -> Json.Encode.Value -ref_encoder ref = +encode : Unresolved -> Json.Encode.Value +encode ref =     (Json.Encode.object        [           ("pr", (Json.Encode.string ref.primary)), @@ -164,7 +166,7 @@ resolve : (           BattleCharacters.Struct.Glyph.Ref ->           BattleCharacters.Struct.Glyph.Type        ) -> -      Ref -> +      Unresolved ->        Type     )  resolve resolve_wp resolve_ar resolve_pt resolve_gb resolve_gl ref = @@ -177,8 +179,8 @@ resolve resolve_wp resolve_ar resolve_pt resolve_gb resolve_gl ref =        glyphs = (Array.map (resolve_gl) ref.glyphs)     } -to_ref : Type -> Ref -to_ref equipment = +to_unresolved : Type -> Unresolved +to_unresolved equipment =     {        primary = (BattleCharacters.Struct.Weapon.get_id equipment.primary),        secondary = (BattleCharacters.Struct.Weapon.get_id equipment.secondary), | 


