summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-03-15 18:16:55 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-03-15 18:16:55 +0100
commit6678cfe464ed9ee595f4f3dd7398dec1416454c9 (patch)
tree2700668874e13a81ec7467dcf26a1d246caa23ff /src/shared
parent24efb898f526e0aa02a0e15b74436da8ba166cac (diff)
[Broken] Starting a code refactoring...
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm24
-rw-r--r--src/shared/battle-characters/BattleCharacters/Struct/Armor.elm74
-rw-r--r--src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm66
-rw-r--r--src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm99
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Direction.elm58
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Location.elm70
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Map.elm206
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Tile.elm77
-rw-r--r--src/shared/battle-map/BattleMap/Struct/TileInstance.elm249
-rw-r--r--src/shared/battle-map/BattleMap/View/Tile.elm242
-rw-r--r--src/shared/battle/Battle/Struct/Attributes.elm169
-rw-r--r--src/shared/battle/Battle/Struct/DamageType.elm55
-rw-r--r--src/shared/battle/Battle/Struct/Omnimods.elm180
-rw-r--r--src/shared/battle/Battle/Struct/Statistics.elm210
-rw-r--r--src/shared/battle/Battle/View/Omnimods.elm181
15 files changed, 1960 insertions, 0 deletions
diff --git a/src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm b/src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm
new file mode 100644
index 0000000..a9c848b
--- /dev/null
+++ b/src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm
@@ -0,0 +1,24 @@
+module Comm.AddPortrait exposing (decode)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- BattleCharacters ------------------------------------------------------------
+import Struct.Portrait
+import Struct.ServerReply
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+internal_decoder : Struct.Portrait.Type -> Struct.ServerReply.Type
+internal_decoder pt = (Struct.ServerReply.AddPortrait pt)
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+decode : (Json.Decode.Decoder Struct.ServerReply.Type)
+decode = (Json.Decode.map (internal_decoder) (Struct.Portrait.decoder))
diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Armor.elm b/src/shared/battle-characters/BattleCharacters/Struct/Armor.elm
new file mode 100644
index 0000000..5cb99d6
--- /dev/null
+++ b/src/shared/battle-characters/BattleCharacters/Struct/Armor.elm
@@ -0,0 +1,74 @@
+module BattleCharacters.Struct.Armor exposing
+ (
+ Type,
+ Ref,
+ new,
+ get_id,
+ get_name,
+ get_image_id,
+ get_omnimods,
+ decoder,
+ default,
+ none
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
+-- Battle ----------------------------------------------------------------------
+import Battle.Struct.Omnimods
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ id : String,
+ name : String,
+ omnimods : Battle.Struct.Omnimods.Type
+ }
+
+type alias Ref = String
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+new : String -> String -> Battle.Struct.Omnimods.Type -> Type
+new id name omnimods =
+ {
+ id = id,
+ name = name,
+ omnimods = omnimods
+ }
+
+get_id : Type -> Ref
+get_id ar = ar.id
+
+get_name : Type -> String
+get_name ar = ar.name
+
+get_image_id : Type -> String
+get_image_id ar = ar.id
+
+get_omnimods : Type -> Battle.Struct.Omnimods.Type
+get_omnimods ar = ar.omnimods
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder)
+ )
+
+none : Type
+none = (new "0" "None" (Battle.Struct.Omnimods.none))
+
+default : Type
+default = (none)
diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm b/src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm
new file mode 100644
index 0000000..35f5260
--- /dev/null
+++ b/src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm
@@ -0,0 +1,66 @@
+module BattleCharacters.Struct.Portrait exposing
+ (
+ Type,
+ Ref,
+ default,
+ get_id,
+ get_name,
+ get_body_id,
+ get_icon_id,
+ decoder
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ id : String,
+ name : String,
+ body_id : String,
+ icon_id : String
+ }
+
+type alias Ref = String
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+default : Type
+default =
+ {
+ id = "cat",
+ name = "Black Cat",
+ body_id = "mammal",
+ icon_id = "cat"
+ }
+
+get_id : Type -> String
+get_id p = p.id
+
+get_name : Type -> String
+get_name p = p.name
+
+get_body_id : Type -> String
+get_body_id p = p.body_id
+
+get_icon_id : Type -> String
+get_icon_id p = p.icon_id
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "bid" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "iid" Json.Decode.string)
+ )
diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm b/src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm
new file mode 100644
index 0000000..0aff932
--- /dev/null
+++ b/src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm
@@ -0,0 +1,99 @@
+module BattleCharacters.Struct.Weapon exposing
+ (
+ Type,
+ Ref,
+ get_id,
+ get_name,
+ get_is_primary,
+ get_attack_range,
+ get_defense_range,
+ get_omnimods,
+ get_damage_sum,
+ decoder,
+ default,
+ none
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
+-- Battle ----------------------------------------------------------------------
+import Battle.Struct.Omnimods
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ id : String,
+ name : String,
+ is_primary : Bool,
+ def_range : Int,
+ atk_range : Int,
+ omnimods : Battle.Struct.Omnimods.Type,
+ damage_sum : Int
+ }
+
+type alias Ref = String
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_id : Type -> String
+get_id wp = wp.id
+
+get_name : Type -> String
+get_name wp = wp.name
+
+get_is_primary : Type -> Bool
+get_is_primary wp = wp.is_primary
+
+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_omnimods : Type -> Battle.Struct.Omnimods.Type
+get_omnimods wp = wp.omnimods
+
+get_damage_sum : Type -> Int
+get_damage_sum wp = wp.damage_sum
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.map
+ (\e ->
+ {e | damage_sum = (Battle.Struct.Omnimods.get_damage_sum e.omnimods)}
+ )
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "pri" Json.Decode.bool)
+ |> (Json.Decode.Pipeline.required "rmi" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "rma" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder)
+ |> (Json.Decode.Pipeline.hardcoded 0)
+ )
+ )
+
+none : Type
+none =
+ {
+ id = "",
+ name = "None",
+ is_primary = False,
+ def_range = 0,
+ atk_range = 0,
+ omnimods = (Battle.Struct.Omnimods.none),
+ damage_sum = 0
+ }
+
+default : Type
+default = (none)
diff --git a/src/shared/battle-map/BattleMap/Struct/Direction.elm b/src/shared/battle-map/BattleMap/Struct/Direction.elm
new file mode 100644
index 0000000..4620e29
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/Direction.elm
@@ -0,0 +1,58 @@
+module BattleMap.Struct.Direction exposing
+(
+ Type(..),
+ opposite_of,
+ to_string,
+ decoder
+)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Battle Map ------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type Type =
+ None
+ | Left
+ | Right
+ | Up
+ | Down
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+from_string : String -> Type
+from_string str =
+ case str of
+ "R" -> Right
+ "L" -> Left
+ "U" -> Up
+ "D" -> Down
+ _ -> None
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+opposite_of : Type -> Type
+opposite_of d =
+ case d of
+ Left -> Right
+ Right -> Left
+ Up -> Down
+ Down -> Up
+ None -> None
+
+to_string : Type -> String
+to_string dir =
+ case dir of
+ Right -> "R"
+ Left -> "L"
+ Up -> "U"
+ Down -> "D"
+ None -> "N"
+
+decoder : (Json.Decode.Decoder Type)
+decoder = (Json.Decode.map (from_string) Json.Decode.string)
diff --git a/src/shared/battle-map/BattleMap/Struct/Location.elm b/src/shared/battle-map/BattleMap/Struct/Location.elm
new file mode 100644
index 0000000..3443150
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/Location.elm
@@ -0,0 +1,70 @@
+module BattleMap.Struct.Location exposing (..)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
+import Json.Encode
+
+-- Battle Map ------------------------------------------------------------------
+import BattleMap.Struct.Direction
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ x : Int,
+ y : Int
+ }
+
+type alias Ref = (Int, Int)
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+neighbor : BattleMap.Struct.Direction.Type -> Type -> Type
+neighbor dir loc =
+ case dir of
+ BattleMap.Struct.Direction.Right -> {loc | x = (loc.x + 1)}
+ BattleMap.Struct.Direction.Left -> {loc | x = (loc.x - 1)}
+ BattleMap.Struct.Direction.Up -> {loc | y = (loc.y - 1)}
+ BattleMap.Struct.Direction.Down -> {loc | y = (loc.y + 1)}
+ BattleMap.Struct.Direction.None -> loc
+
+get_ref : Type -> Ref
+get_ref l =
+ (l.x, l.y)
+
+from_ref : Ref -> Type
+from_ref (x, y) =
+ {x = x, y = y}
+
+dist : Type -> Type -> Int
+dist loc_a loc_b =
+ (
+ (abs (loc_a.x - loc_b.x))
+ +
+ (abs (loc_a.y - loc_b.y))
+ )
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.required "x" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "y" Json.Decode.int)
+ )
+
+encode : Type -> Json.Encode.Value
+encode loc =
+ (Json.Encode.object
+ [
+ ( "x", (Json.Encode.int loc.x) ),
+ ( "y", (Json.Encode.int loc.y) )
+ ]
+ )
diff --git a/src/shared/battle-map/BattleMap/Struct/Map.elm b/src/shared/battle-map/BattleMap/Struct/Map.elm
new file mode 100644
index 0000000..aa166d4
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/Map.elm
@@ -0,0 +1,206 @@
+module BattleMap.Struct.Map exposing
+ (
+ Type,
+ decoder,
+ empty,
+ get_height,
+ get_markers,
+ get_movement_cost_function,
+ get_omnimods_at,
+ get_tiles,
+ get_width,
+ new,
+ set_tile_to,
+ solve_tiles,
+ try_getting_tile_at
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Array
+
+import Dict
+
+import Json.Decode
+
+-- Battle ----------------------------------------------------------------------
+import Battle.Struct.Omnimods
+
+-- Battle Map ------------------------------------------------------------------
+import BattleMap.Struct.Location
+import BattleMap.Struct.MapMarker
+import BattleMap.Struct.Tile
+import BattleMap.Struct.TileInstance
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ width : Int,
+ height : Int,
+ content : (Array.Array BattleMap.Struct.TileInstance.Type),
+ markers : (Dict.Dict String BattleMap.Struct.MapMarker.Type)
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+location_to_index : BattleMap.Struct.Location.Type -> Type -> Int
+location_to_index loc map =
+ ((loc.y * map.width) + loc.x)
+
+has_location : BattleMap.Struct.Location.Type -> Type -> Bool
+has_location loc map =
+ (
+ (loc.x >= 0)
+ && (loc.y >= 0)
+ && (loc.x < map.width)
+ && (loc.y < map.height)
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_width : Type -> Int
+get_width map = map.width
+
+get_height : Type -> Int
+get_height map = map.height
+
+get_tiles : Type -> (Array.Array BattleMap.Struct.TileInstance.Type)
+get_tiles map = map.content
+
+get_markers : Type -> (Dict.Dict String BattleMap.Struct.MapMarker.Type)
+get_markers map = map.markers
+
+set_tile_to : BattleMap.Struct.Location.Type -> BattleMap.Struct.TileInstance.Type -> Type -> Type
+set_tile_to loc tile_inst map =
+ {map |
+ content = (Array.set (location_to_index loc map) tile_inst map.content)
+ }
+
+empty : Type
+empty =
+ {
+ width = 0,
+ height = 0,
+ content = (Array.empty),
+ markers = (Dict.empty)
+ }
+
+new : Int -> Int -> (List BattleMap.Struct.TileInstance.Type) -> Type
+new width height tiles =
+ {
+ width = width,
+ height = height,
+ content = (Array.fromList tiles),
+ markers = (Dict.empty)
+ }
+
+try_getting_tile_at : (
+ BattleMap.Struct.Location.Type ->
+ Type ->
+ (Maybe BattleMap.Struct.TileInstance.Type)
+ )
+try_getting_tile_at loc map =
+ if (has_location loc map)
+ then (Array.get (location_to_index loc map) map.content)
+ else Nothing
+
+solve_tiles : (
+ (Dict.Dict BattleMap.Struct.Tile.Ref BattleMap.Struct.Tile.Type) ->
+ Type ->
+ Type
+ )
+solve_tiles tiles map =
+ {map |
+ content =
+ (Array.map
+ (BattleMap.Struct.TileInstance.solve tiles) map.content
+ )
+ }
+
+get_omnimods_at : (
+ BattleMap.Struct.Location.Type ->
+ (Dict.Dict BattleMap.Struct.Tile.Ref BattleMap.Struct.Tile.Type) ->
+ Type ->
+ Battle.Struct.Omnimods.Type
+ )
+get_omnimods_at loc tiles_solver map =
+ case (try_getting_tile_at loc map) of
+ Nothing -> (Battle.Struct.Omnimods.none)
+ (Just tile_inst) ->
+ case
+ (Dict.get
+ (BattleMap.Struct.TileInstance.get_class_id tile_inst)
+ tiles_solver
+ )
+ of
+ Nothing -> (Battle.Struct.Omnimods.none)
+ (Just tile) -> (BattleMap.Struct.Tile.get_omnimods tile)
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.andThen
+ (\width ->
+ (Json.Decode.map4
+ Type
+ (Json.Decode.field "w" Json.Decode.int)
+ (Json.Decode.field "h" Json.Decode.int)
+ (Json.Decode.field
+ "t"
+ (Json.Decode.map
+ (Array.indexedMap
+ (BattleMap.Struct.TileInstance.set_location_from_index
+ width
+ )
+ )
+ (Json.Decode.array (BattleMap.Struct.TileInstance.decoder))
+ )
+ )
+ (Json.Decode.field
+ "m"
+ (Json.Decode.map
+ (Dict.fromList)
+ (Json.Decode.keyValuePairs
+ (BattleMap.Struct.MapMarker.decoder)
+ )
+ )
+ )
+ )
+ )
+ (Json.Decode.field "w" Json.Decode.int)
+ )
+
+get_movement_cost_function : (
+ Type ->
+ BattleMap.Struct.Location.Type ->
+ (List BattleMap.Struct.Character.Type) ->
+ BattleMap.Struct.Location.Type ->
+ Int
+ )
+get_movement_cost_function bmap start_loc char_list loc =
+ if (has_location loc bmap)
+ then
+ case (Array.get (location_to_index loc bmap) bmap.content) of
+ (Just tile) ->
+ if
+ (List.any
+ (
+ \c ->
+ (
+ ((BattleMap.Struct.Character.get_location c) == loc)
+ && (loc /= start_loc)
+ && (BattleMap.Struct.Character.is_alive c)
+ )
+ )
+ char_list
+ )
+ then
+ Constants.Movement.cost_when_occupied_tile
+ else
+ (BattleMap.Struct.TileInstance.get_cost tile)
+
+ Nothing -> Constants.Movement.cost_when_out_of_bounds
+ else
+ Constants.Movement.cost_when_out_of_bounds
diff --git a/src/shared/battle-map/BattleMap/Struct/Tile.elm b/src/shared/battle-map/BattleMap/Struct/Tile.elm
new file mode 100644
index 0000000..9145b44
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/Tile.elm
@@ -0,0 +1,77 @@
+module BattleMap.Struct.Tile exposing
+ (
+ Ref,
+ VariantID,
+ FamilyID,
+ Type,
+ get_id,
+ get_name,
+ get_cost,
+ get_omnimods,
+ get_family,
+ decoder
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Dict
+
+import Json.Decode
+import Json.Decode.Pipeline
+
+-- Battle ----------------------------------------------------------------------
+import Battle.Struct.Omnimods
+
+-- Local Module ----------------------------------------------------------------
+import Constants.UI
+import Constants.Movement
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Ref = String
+type alias VariantID = String
+type alias FamilyID = String
+
+type alias Type =
+ {
+ id : Ref,
+ name : String,
+ crossing_cost : Int,
+ family : FamilyID,
+ depth : Int,
+ omnimods : Battle.Struct.Omnimods.Type
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_id : Type -> Ref
+get_id tile = tile.id
+
+get_cost : Type -> Int
+get_cost tile = tile.crossing_cost
+
+get_name : Type -> String
+get_name tile = tile.name
+
+get_family : Type -> FamilyID
+get_family tile = tile.family
+
+get_omnimods : Type -> Battle.Struct.Omnimods.Type
+get_omnimods t = t.omnimods
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "ct" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "fa" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "de" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder)
+ )
diff --git a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm
new file mode 100644
index 0000000..8c39371
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm
@@ -0,0 +1,249 @@
+module BattleMap.Struct.TileInstance exposing
+ (
+ Type,
+ Border,
+ clone,
+ get_location,
+ get_class_id,
+ get_family,
+ get_cost,
+ default,
+ set_borders,
+ get_borders,
+ new_border,
+ get_variant_id,
+ get_border_variant_id,
+ get_border_class_id,
+ get_local_variant_ix,
+ error,
+ solve,
+ set_location_from_index,
+ decoder,
+ encode
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Dict
+
+import Json.Encode
+
+import Json.Decode
+import Json.Decode.Pipeline
+
+-- Battle Map ------------------------------------------------------------------
+import BattleMap.Struct.Tile
+import BattleMap.Struct.Location
+
+-- Local -----------------------------------------------------------------------
+import Constants.UI
+import Constants.Movement
+
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ location : BattleMap.Struct.Location.Type,
+ crossing_cost : Int,
+ family : BattleMap.Struct.Tile.FamilyID,
+ class_id : BattleMap.Struct.Tile.Ref,
+ variant_id : BattleMap.Struct.Tile.VariantID,
+ triggers : (List String),
+ borders : (List Border)
+ }
+
+type alias Border =
+ {
+ class_id : BattleMap.Struct.Tile.Ref,
+ variant_id : BattleMap.Struct.Tile.VariantID
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+noise_function : Int -> Int -> Int -> Int
+noise_function a b c =
+ (round (radians (toFloat ((a + 1) * 2 + (b + 1) * 3 + c))))
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+clone : BattleMap.Struct.Location.Type -> Type -> Type
+clone loc inst = {inst | location = loc}
+
+new_border : BattleMap.Struct.Tile.Ref -> BattleMap.Struct.Tile.VariantID -> Border
+new_border class_id variant_id =
+ {
+ class_id = class_id,
+ variant_id = variant_id
+ }
+
+default : BattleMap.Struct.Tile.Type -> Type
+default tile =
+ {
+ location = {x = 0, y = 0},
+ class_id = (Struct.Tile.get_id tile),
+ variant_id = "0",
+ crossing_cost = (Struct.Tile.get_cost tile),
+ family = (Struct.Tile.get_family tile),
+ triggers = [],
+ borders = []
+ }
+
+error : Int -> Int -> Type
+error x y =
+ {
+ location = {x = x, y = y},
+ class_id = "0",
+ variant_id = "0",
+ family = "0",
+ crossing_cost = Constants.Movement.cost_when_out_of_bounds,
+ triggers = [],
+ borders = []
+ }
+
+get_class_id : Type -> BattleMap.Struct.Tile.Ref
+get_class_id inst = inst.class_id
+
+get_cost : Type -> Int
+get_cost inst = inst.crossing_cost
+
+get_location : Type -> BattleMap.Struct.Location.Type
+get_location inst = inst.location
+
+get_family : Type -> BattleMap.Struct.Tile.FamilyID
+get_family inst = inst.family
+
+set_borders : (List Border) -> Type -> Type
+set_borders borders tile_inst = {tile_inst | borders = borders}
+
+get_borders : Type -> (List Border)
+get_borders tile_inst = tile_inst.borders
+
+get_variant_id : Type -> BattleMap.Struct.Tile.VariantID
+get_variant_id tile_inst = tile_inst.variant_id
+
+get_border_variant_id : Border -> BattleMap.Struct.Tile.VariantID
+get_border_variant_id tile_border = tile_border.variant_id
+
+get_local_variant_ix : Type -> Int
+get_local_variant_ix tile_inst =
+ (modBy
+ Constants.UI.local_variants_per_tile
+ (noise_function
+ tile_inst.location.x
+ tile_inst.location.y
+ tile_inst.crossing_cost
+ )
+ )
+
+solve : (
+ (Dict.Dict BattleMap.Struct.Tile.Ref BattleMap.Struct.Tile.Type) ->
+ Type ->
+ Type
+ )
+solve tiles tile_inst =
+ case (Dict.get tile_inst.class_id tiles) of
+ (Just tile) ->
+ {tile_inst |
+ crossing_cost = (Struct.Tile.get_cost tile),
+ family = (Struct.Tile.get_family tile)
+ }
+
+ Nothing ->
+ {tile_inst |
+ crossing_cost = -1,
+ family = "-1"
+ }
+
+
+list_to_borders : (
+ (List String) ->
+ (List Border) ->
+ (List Border)
+ )
+list_to_borders list borders =
+ case list of
+ (a :: (b :: c)) ->
+ (list_to_borders
+ c
+ ({ class_id = a, variant_id = b } :: borders)
+ )
+ _ -> (List.reverse borders)
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.andThen
+ (\tile_data ->
+ case tile_data of
+ (tile_id :: (variant_id :: borders)) ->
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.hardcoded {x = 0, y = 0}) -- Location
+ |> (Json.Decode.Pipeline.hardcoded 0) -- Crossing Cost
+ |> (Json.Decode.Pipeline.hardcoded "") -- Family
+ |> (Json.Decode.Pipeline.hardcoded tile_id)
+ |> (Json.Decode.Pipeline.hardcoded variant_id)
+ |>
+ (Json.Decode.Pipeline.required
+ "t"
+ (Json.Decode.list (Json.Decode.string))
+ )
+ |>
+ (Json.Decode.Pipeline.hardcoded
+ (list_to_borders borders [])
+ )
+ )
+ _ -> (Json.Decode.succeed (error 0 0))
+ )
+ (Json.Decode.field "b" (Json.Decode.list (Json.Decode.string)))
+ )
+
+get_border_class_id : Border -> BattleMap.Struct.Tile.Ref
+get_border_class_id tile_border = tile_border.class_id
+
+set_location_from_index : Int -> Int -> Type -> Type
+set_location_from_index map_width index tile_inst =
+ {tile_inst |
+ location =
+ {
+ x = (modBy map_width index),
+ y = (index // map_width)
+ }
+ }
+
+encode : Type -> Json.Encode.Value
+encode tile_inst =
+ (Json.Encode.object
+ [
+ (
+ "b",
+ (Json.Encode.list
+ (Json.Encode.string)
+ (
+ tile_inst.class_id
+ ::
+ (
+ tile_inst.variant_id
+ ::
+ (List.concatMap
+ (\border ->
+ [
+ border.class_id,
+ border.variant_id
+ ]
+ )
+ tile_inst.borders
+ )
+ )
+ )
+ )
+ ),
+ (
+ "t",
+ (Json.Encode.list (Json.Encode.string) tile_inst.triggers)
+ )
+ ]
+ )
+
diff --git a/src/shared/battle-map/BattleMap/View/Tile.elm b/src/shared/battle-map/BattleMap/View/Tile.elm
new file mode 100644
index 0000000..6039ff4
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/View/Tile.elm
@@ -0,0 +1,242 @@
+module BattleMap.View.Tile exposing (get_html, get_html_extra, get_content_html)
+
+-- Elm -------------------------------------------------------------------------
+import Html
+import Html.Attributes
+import Html.Events
+
+-- Battle Map ------------------------------------------------------------------
+import Constants.UI
+import Constants.IO
+
+import BattleMap.Struct.Location
+import BattleMap.Struct.TileInstance
+
+-- Local -----------------------------------------------------------------------
+import Struct.Event
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_layer_html : (
+ Int ->
+ BattleMap.Struct.TileInstance.Border ->
+ (Html.Html Struct.Event.Type)
+ )
+get_layer_html index border =
+ (Html.div
+ [
+ (Html.Attributes.class ("tile-icon-f-" ++ (String.fromInt index))),
+ (Html.Attributes.style
+ "background-image"
+ (
+ "url("
+ ++ Constants.IO.tile_assets_url
+ ++ (BattleMap.Struct.TileInstance.get_border_class_id border)
+ ++ "-f-"
+ ++ (BattleMap.Struct.TileInstance.get_border_variant_id border)
+ ++ ".svg)"
+ )
+ )
+ ]
+ []
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_content_html : (
+ BattleMap.Struct.TileInstance.Type ->
+ (List (Html.Html Struct.Event.Type))
+ )
+get_content_html tile =
+ (
+ (Html.div
+ [
+ (Html.Attributes.class "tile-icon-bg"),
+ (Html.Attributes.style
+ "background-image"
+ (
+ "url("
+ ++ Constants.IO.tile_assets_url
+ ++ (BattleMap.Struct.TileInstance.get_class_id tile)
+ ++ "-bg.svg)"
+ )
+ )
+ ]
+ []
+ )
+ (Html.div
+ [
+ (Html.Attributes.class "tile-icon-bg"),
+ (Html.Attributes.style
+ "background-image"
+ (
+ "url("
+ ++ Constants.IO.tile_assets_url
+ ++ (BattleMap.Struct.TileInstance.get_class_id tile)
+ ++ "-bg.svg)"
+ )
+ )
+ ]
+ []
+ )
+ ::
+ (
+ (Html.div
+ [
+ (Html.Attributes.class "tile-icon-dt"),
+ (Html.Attributes.style
+ "background-image"
+ (
+ "url("
+ ++ Constants.IO.tile_assets_url
+ ++ (BattleMap.Struct.TileInstance.get_class_id tile)
+ ++ "-v-"
+ ++ (BattleMap.Struct.TileInstance.get_variant_id tile)
+ ++ ".svg)"
+ )
+ )
+ ]
+ []
+ )
+ ::
+ (List.indexedMap
+ (get_layer_html)
+ (BattleMap.Struct.TileInstance.get_borders tile)
+ )
+ )
+ )
+
+get_html : (
+ Bool ->
+ BattleMap.Struct.TileInstance.Type ->
+ (Html.Html Struct.Event.Type)
+ )
+get_html display_cost tile =
+ let tile_loc = (BattleMap.Struct.TileInstance.get_location tile) in
+ (Html.div
+ [
+ (Html.Attributes.class "tile-icon"),
+ (Html.Attributes.class "tiled"),
+ (Html.Attributes.class
+ (
+ "tile-variant-"
+ ++
+ (String.fromInt
+ (BattleMap.Struct.TileInstance.get_local_variant_ix tile)
+ )
+ )
+ ),
+ (Html.Attributes.class "clickable"),
+ (Html.Events.onClick
+ (Struct.Event.TileSelected
+ (BattleMap.Struct.Location.get_ref tile_loc)
+ )
+ ),
+ (Html.Attributes.style
+ "top"
+ (
+ (String.fromInt (tile_loc.y * Constants.UI.tile_size))
+ ++ "px"
+ )
+ ),
+ (Html.Attributes.style
+ "left"
+ (
+ (String.fromInt (tile_loc.x * Constants.UI.tile_size))
+ ++ "px"
+ )
+ )
+ ]
+ (
+ if (display_cost)
+ then
+ (
+ (Html.div
+ [
+ (Html.Attributes.class "tile-icon-cost")
+ ]
+ [
+ (Html.text
+ (String.fromInt
+ (BattleMap.Struct.TileInstance.get_cost tile)
+ )
+ )
+ ]
+ )
+ :: (get_content_html tile)
+ )
+ else (get_content_html tile)
+ )
+ )
+
+get_html_with_extra : (
+ Bool ->
+ (List Html.Attributes.Attribute) ->
+ BattleMap.Struct.TileInstance.Type ->
+ (Html.Html Struct.Event.Type)
+ )
+get_html_with_extra display_cost extra_classes tile =
+ let tile_loc = (BattleMap.Struct.TileInstance.get_location tile) in
+ (Html.div
+ (
+ extra_classes
+ ++
+ [
+ (Html.Attributes.class "tile-icon"),
+ (Html.Attributes.class "tiled"),
+ (Html.Attributes.class
+ (
+ "tile-variant-"
+ ++
+ (String.fromInt
+ (BattleMap.Struct.TileInstance.get_local_variant_ix
+ tile
+ )
+ )
+ )
+ ),
+ (Html.Attributes.class "clickable"),
+ (Html.Events.onClick
+ (Struct.Event.TileSelected
+ (BattleMap.Struct.Location.get_ref tile_loc)
+ )
+ ),
+ (Html.Attributes.style
+ "top"
+ (
+ (String.fromInt (tile_loc.y * Constants.UI.tile_size))
+ ++ "px"
+ )
+ ),
+ (Html.Attributes.style
+ "left"
+ (
+ (String.fromInt (tile_loc.x * Constants.UI.tile_size))
+ ++ "px"
+ )
+ )
+ ]
+ )
+ (
+ if (display_cost)
+ then
+ (
+ (Html.div
+ [
+ (Html.Attributes.class "tile-icon-cost")
+ ]
+ [
+ (Html.text
+ (String.fromInt
+ (BattleMap.Struct.TileInstance.get_cost tile)
+ )
+ )
+ ]
+ )
+ :: (get_content_html tile)
+ )
+ else (get_content_html tile)
+ )
+ )
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)
+ )
+ )
+ ]
+ )