summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-29 22:11:49 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-29 22:11:49 +0200 |
commit | fd7e20510bec8d53911af8e23c95e8e5c046390d (patch) | |
tree | 3c71767ce95ec479e422079ecc3170f991825c44 | |
parent | 3f8148306a6feace626669170d3c4223beb655c4 (diff) |
Adds the omnimods to the tiles & chars.
-rw-r--r-- | src/battle/src/Struct/Character.elm | 64 | ||||
-rw-r--r-- | src/battle/src/Struct/Map.elm | 26 | ||||
-rw-r--r-- | src/battle/src/Struct/Tile.elm | 46 | ||||
-rw-r--r-- | src/battle/src/Update/HandleServerReply.elm | 14 |
4 files changed, 101 insertions, 49 deletions
diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm index 30001e5..6a3cdc1 100644 --- a/src/battle/src/Struct/Character.elm +++ b/src/battle/src/Struct/Character.elm @@ -25,7 +25,8 @@ module Struct.Character exposing get_weapons, set_weapons, decoder, - fill_missing_equipment + refresh_omnimods, + fill_missing_equipment_and_omnimods ) -- Elm ------------------------------------------------------------------------- @@ -83,6 +84,7 @@ type alias Type = statistics : Struct.Statistics.Type, weapons : Struct.WeaponSet.Type, armor : Struct.Armor.Type, + current_omnimods : Struct.Omnimods.Type, permanent_omnimods : Struct.Omnimods.Type } @@ -101,6 +103,7 @@ finish_decoding add_char = let weapon_set = (Struct.WeaponSet.new Struct.Weapon.none Struct.Weapon.none) armor = Struct.Armor.none + default_attributes = (Struct.Attributes.default) almost_char = { ix = add_char.ix, @@ -110,13 +113,15 @@ finish_decoding add_char = portrait = add_char.prt, location = add_char.lc, health = add_char.hea, - attributes = add_char.att, - statistics = (Struct.Statistics.new add_char.att weapon_set armor), + attributes = default_attributes, + statistics = (Struct.Statistics.new_raw default_attributes), player_ix = add_char.pla, enabled = add_char.ena, defeated = add_char.dea, weapons = weapon_set, - armor = armor + armor = armor, + current_omnimods = (Struct.Omnimods.new [] [] [] []), + permanent_omnimods = add_char.omni } in (almost_char, add_char.awp, add_char.swp, add_char.ar) @@ -195,8 +200,7 @@ get_armor_variation char = set_weapons : Struct.WeaponSet.Type -> Type -> Type set_weapons weapons char = {char | - weapons = weapons, - statistics = (Struct.Statistics.new char.attributes weapons char.armor) + weapons = weapons } decoder : (Json.Decode.Decoder (Type, Int, Int, Int)) @@ -210,31 +214,61 @@ decoder = |> (Json.Decode.Pipeline.required "rnk" Json.Decode.string) |> (Json.Decode.Pipeline.required "ico" Json.Decode.string) |> (Json.Decode.Pipeline.required "prt" Json.Decode.string) - |> (Json.Decode.Pipeline.required "lc" (Struct.Location.decoder)) + |> (Json.Decode.Pipeline.required "lc" 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 "att" (Struct.Attributes.decoder)) |> (Json.Decode.Pipeline.required "awp" Json.Decode.int) |> (Json.Decode.Pipeline.required "swp" Json.Decode.int) |> (Json.Decode.Pipeline.required "ar" Json.Decode.int) + |> (Json.Decode.Pipeline.required "omni" Struct.Omnimods.decoder) ) ) -fill_missing_equipment : ( +refresh_omnimods : Struct.Omnimods.Type -> Type -> Type +refresh_omnimods tile_omnimods char = + let + current_omnimods = + (Struct.Omnimods.merge + (Struct.Weapon.get_omnimods + (Struct.WeaponSet.get_active_weapon char.weapons) + ) + (Struct.Omnimods.merge + tile_omnimods + char.permanent_omnimods + ) + ) + current_attributes = + (Struct.Omnimods.apply_to_attributes + current_omnimods + (Struct.Attributes.default) + ) + current_statistics = + (Struct.Omnimods.apply_to_statistics + current_omnimods + (Struct.Statistics.new_raw current_attributes) + ) + in + {char | + attributes = current_attributes, + statistics = current_statistics, + current_omnimods = current_omnimods + } + +fill_missing_equipment_and_omnimods : ( + Struct.Omnimods.Type -> Struct.Weapon.Type -> Struct.Weapon.Type -> Struct.Armor.Type -> Type -> Type ) -fill_missing_equipment awp swp ar char = - let - weapon_set = (Struct.WeaponSet.new awp swp) - in +fill_missing_equipment_and_omnimods tile_omnimods awp swp ar char = + (refresh_omnimods + tile_omnimods {char | - statistics = (Struct.Statistics.new char.attributes weapon_set ar), - weapons = weapon_set, + weapons = (Struct.WeaponSet.new awp swp), armor = ar } + ) diff --git a/src/battle/src/Struct/Map.elm b/src/battle/src/Struct/Map.elm index a2ddeb3..5f87f1f 100644 --- a/src/battle/src/Struct/Map.elm +++ b/src/battle/src/Struct/Map.elm @@ -8,7 +8,8 @@ module Struct.Map exposing get_tiles, get_movement_cost_function, solve_tiles, - try_getting_tile_at + try_getting_tile_at, + get_omnimods_at ) -- Elm ------------------------------------------------------------------------- @@ -16,12 +17,13 @@ import Array import Dict --- Map ------------------------------------------------------------------- +-- Battle ---------------------------------------------------------------------- +import Constants.Movement + import Struct.Character -import Struct.Tile import Struct.Location - -import Constants.Movement +import Struct.Omnimods +import Struct.Tile -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -123,3 +125,17 @@ solve_tiles tiles bmap = {bmap | content = (Array.map (Struct.Tile.solve_tile_instance tiles) bmap.content) } + +get_omnimods_at : ( + Struct.Location.Type -> + (Dict.Dict Int Struct.Tile.Type) -> + Type -> + Struct.Omnimods.Type + ) +get_omnimods_at loc tiles_solver map = + case (try_getting_tile_at loc map) of + Nothing -> (Struct.Omnimods.new [] [] [] []) + (Just tile_inst) -> + case (Dict.get (Struct.Tile.get_type_id tile_inst) tiles_solver) of + Nothing -> (Struct.Omnimods.new [] [] [] []) + (Just tile) -> (Struct.Tile.get_omnimods tile) diff --git a/src/battle/src/Struct/Tile.elm b/src/battle/src/Struct/Tile.elm index 9783672..c7c0d52 100644 --- a/src/battle/src/Struct/Tile.elm +++ b/src/battle/src/Struct/Tile.elm @@ -19,6 +19,7 @@ module Struct.Tile exposing get_type_id, get_variant_ix, get_local_variant_ix, + get_omnimods, solve_tile_instance, decoder ) @@ -29,29 +30,24 @@ import Dict import Json.Decode import Json.Decode.Pipeline --- Map ------------------------------------------------------------------- +-- Battle ---------------------------------------------------------------------- import Constants.UI import Constants.Movement import Struct.Location +import Struct.Omnimods -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type alias Ref = Int -type alias PartiallyDecoded = - { - id : Int, - nam : String, - ct : Int - } - type alias Type = { id : Int, name : String, - crossing_cost : Int + crossing_cost : Int, + omnimods : Struct.Omnimods.Type } type alias Border = @@ -76,23 +72,16 @@ noise_function : Int -> Int -> Int -> Int noise_function a b c = (round (radians (toFloat ((a + 1) * 2 + (b + 1) * 3 + c)))) -finish_decoding : PartiallyDecoded -> Type -finish_decoding add_tile = - { - id = add_tile.id, - name = add_tile.nam, - crossing_cost = add_tile.ct - } - -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -new : Int -> String -> Int -> Type -new id name crossing_cost = +new : Int -> String -> Int -> Struct.Omnimods.Type -> Type +new id name crossing_cost omnimods = { id = id, name = name, - crossing_cost = crossing_cost + crossing_cost = crossing_cost, + omnimods = omnimods } new_border : Int -> Int -> Border @@ -170,6 +159,9 @@ get_local_variant_ix tile_inst = % Constants.UI.local_variants_per_tile ) +get_omnimods : Type -> Struct.Omnimods.Type +get_omnimods t = t.omnimods + solve_tile_instance : (Dict.Dict Int Type) -> Instance -> Instance solve_tile_instance tiles tile_instance = case (Dict.get tile_instance.type_id tiles) of @@ -184,12 +176,10 @@ solve_tile_instance tiles tile_instance = 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.int) - ) + (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 "ct" Json.Decode.int) + |> (Json.Decode.Pipeline.required "omni" Struct.Omnimods.decoder) ) diff --git a/src/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm index ff6cc67..3b90800 100644 --- a/src/battle/src/Update/HandleServerReply.elm +++ b/src/battle/src/Update/HandleServerReply.elm @@ -87,13 +87,25 @@ add_character char_and_refs current_state = (model, _) -> let (char, awp_ref, swp_ref, ar_ref) = char_and_refs + tile_omnimods = + (Struct.Map.get_omnimods_at + (Struct.Character.get_location char) + model.tiles + model.map + ) awp = (weapon_getter model awp_ref) swp = (weapon_getter model swp_ref) ar = (armor_getter model ar_ref) in ( (Struct.Model.add_character - (Struct.Character.fill_missing_equipment awp swp ar char) + (Struct.Character.fill_missing_equipment_and_omnimods + tile_omnimods + awp + swp + ar + char + ) model ), Nothing |