From 9ffa08c3aad8e4f40b7f7d1e7845e5153f9c34ab Mon Sep 17 00:00:00 2001 From: nsensfel Date: Wed, 29 Aug 2018 16:24:10 +0200 Subject: Still working on it... --- src/battle/struct/btl_character_current_data.erl | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/battle/struct/btl_character_current_data.erl (limited to 'src/battle/struct/btl_character_current_data.erl') diff --git a/src/battle/struct/btl_character_current_data.erl b/src/battle/struct/btl_character_current_data.erl new file mode 100644 index 0000000..60bfdbc --- /dev/null +++ b/src/battle/struct/btl_character_current_data.erl @@ -0,0 +1,113 @@ +-module(btl_character_current_data). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + character_current_data, + { + attributes :: shr_attributes:type(), + statistics :: shr_statistics:type(), + omnimods :: shr_omnimods:type() + } +). + +-opaque type() :: #character_current_data{}. + +-export_type([type/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_attributes/1, + get_statistics/1, + get_omnimods/1 + ] +). + +-export +( + [ + new/2 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec location_to_omnimods + ( + {non_neg_integer(), non_neg_integer()}, + btl_map:type() + ) + -> shr_omnimods:type(). +location_to_omnimods (Location, Map) -> + TileInstance = btl_map:get_tile_instance(Location, Map), + TileClassID = shr_tile:extract_main_class_id(TileInstance), + Tile = shr_tile:from_class_id(TileClassID), + + shr_tile:get_omnimods(Tile). + +-spec weapon_id_to_omnimods (shr_weapon:id()) -> shr_omnimods:type(). +weapon_id_to_omnimods (WeaponID) -> + Weapon = shr_weapon:from_id(WeaponID), + + shr_weapon:get_omnimods(Weapon). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-spec get_omnimods (type()) -> shr_omnimods:type(). +get_omnimods (Char) -> Char#character_current_data.omnimods. + +-spec get_attributes (type()) -> shr_attributes:type(). +get_attributes (Char) -> Char#character_current_data.attributes. + +-spec get_statistics (type()) -> shr_statistics:type(). +get_statistics (Char) -> Char#character_current_data.statistics. + +%%%% Utils +-spec new (btl_character:type(), btl_map:type()) -> type(). +new (Character, Map) -> + PermanentOmnimods = btl_character:get_permanent_omnimods(Character), + + {WeaponID, _} = btl_character:get_weapon_ids(Character), + WeaponOmnimods = weapon_id_to_omnimods(WeaponID), + + Location = btl_character:get_location(Character), + TileOmnimods = location_to_omnimods(Location, Map), + + CurrentOmnimods = + shr_omnimods:merge + ( + shr_omnimods:merge(WeaponOmnimods, TileOmnimods), + PermanentOmnimods + ), + + CurrentAttributes = + shr_omnimods:apply_to_attributes + ( + CurrentOmnimods, + shr_attributes:default() + ), + + CurrentStatistics = + shr_omnimods:apply_to_statistics + ( + CurrentOmnimods, + shr_statistics:new_raw(CurrentAttributes) + ), + + #character_current_data + { + attributes = CurrentAttributes, + statistics = CurrentStatistics, + omnimods = CurrentOmnimods + }. + -- cgit v1.2.3-70-g09d2