From 2ed5b1f48f7784411bcb0983b3490b7c79032eb7 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Fri, 19 Apr 2019 17:58:56 +0200 Subject: [Broken] Starting to add ataxia_set functions... --- src/battle/query/btl_load.erl | 21 +++ src/battle/reply/btl_add_armor.erl | 28 --- src/battle/reply/btl_add_portrait.erl | 29 ---- src/battle/reply/btl_add_weapon.erl | 30 ---- src/battle/struct/btl_battle.erl | 91 +++------- src/battle/struct/btl_character.erl | 39 ++++- src/battle/struct/btl_character_turn_data.erl | 58 +++---- src/shared/reply/shr_add_armor.erl | 28 +++ src/shared/reply/shr_add_portrait.erl | 29 ++++ src/shared/reply/shr_add_weapon.erl | 30 ++++ src/shared/struct/inventory/shr_equipment.erl | 201 +++++++++++++++++++++- src/shared/struct/inventory/shr_inventory.erl | 237 ++++++++++++++++++++++++-- 12 files changed, 611 insertions(+), 210 deletions(-) delete mode 100644 src/battle/reply/btl_add_armor.erl delete mode 100644 src/battle/reply/btl_add_portrait.erl delete mode 100644 src/battle/reply/btl_add_weapon.erl create mode 100644 src/shared/reply/shr_add_armor.erl create mode 100644 src/shared/reply/shr_add_portrait.erl create mode 100644 src/shared/reply/shr_add_weapon.erl (limited to 'src') diff --git a/src/battle/query/btl_load.erl b/src/battle/query/btl_load.erl index 107419f..dae6fbe 100644 --- a/src/battle/query/btl_load.erl +++ b/src/battle/query/btl_load.erl @@ -35,6 +35,7 @@ -spec parse_input (shr_query:type()) -> input(). parse_input (Query) -> JSONReqMap = shr_query:get_params(Query), + PlayerID = maps:get(<<"pid">>, JSONReqMap), SessionToken = maps:get(<<"stk">>, JSONReqMap), BattleID = maps:get(<<"bid">>, JSONReqMap), @@ -154,6 +155,24 @@ generate_reply (QueryState, Input) -> ordsets:to_list(btl_battle:get_used_armor_ids(Battle)) ), + AddGlyphList = + lists:map + ( + fun (GlyphID) -> + btl_add_glyph:generate(shr_glyph:from_id(GlyphID)) + end, + ordsets:to_list(btl_battle:get_used_glyph_ids(Battle)) + ), + + AddGlyphBoardList = + lists:map + ( + fun (GlyphBoardID) -> + btl_add_glyph_board:generate(shr_glyph_board:from_id(GlyphBoardID)) + end, + ordsets:to_list(btl_battle:get_used_glyph_board_ids(Battle)) + ), + AddTileList = lists:map ( @@ -168,6 +187,8 @@ generate_reply (QueryState, Input) -> AddTileList ++ [SetTimeline, SetMap | AddWeaponList] ++ AddPortraitList + ++ AddGlyphList + ++ AddGlyphBoardList ++ AddArmorList ++ AddPlayerList ++ AddCharList diff --git a/src/battle/reply/btl_add_armor.erl b/src/battle/reply/btl_add_armor.erl deleted file mode 100644 index d78edc5..0000000 --- a/src/battle/reply/btl_add_armor.erl +++ /dev/null @@ -1,28 +0,0 @@ --module(btl_add_armor). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (shr_armor:type()) -> {list(any())}. -generate (Armor) -> - { - [ - {<<"msg">>, <<"add_armor">>}, - {<<"id">>, shr_armor:get_id(Armor)}, - {<<"nam">>, shr_armor:get_name(Armor)}, - {<<"omni">>, shr_omnimods:encode(shr_armor:get_omnimods(Armor))} - ] - }. diff --git a/src/battle/reply/btl_add_portrait.erl b/src/battle/reply/btl_add_portrait.erl deleted file mode 100644 index a634a04..0000000 --- a/src/battle/reply/btl_add_portrait.erl +++ /dev/null @@ -1,29 +0,0 @@ --module(btl_add_portrait). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (shr_portrait:type()) -> {list(any())}. -generate (Portrait) -> - { - [ - {<<"msg">>, <<"add_portrait">>}, - {<<"id">>, shr_portrait:get_id(Portrait)}, - {<<"nam">>, shr_portrait:get_name(Portrait)}, - {<<"bid">>, shr_portrait:get_body_id(Portrait)}, - {<<"iid">>, shr_portrait:get_icon_id(Portrait)} - ] - }. diff --git a/src/battle/reply/btl_add_weapon.erl b/src/battle/reply/btl_add_weapon.erl deleted file mode 100644 index 964c6ef..0000000 --- a/src/battle/reply/btl_add_weapon.erl +++ /dev/null @@ -1,30 +0,0 @@ --module(btl_add_weapon). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (shr_weapon:type()) -> {list(any())}. -generate (Weapon) -> - { - [ - {<<"msg">>, <<"add_weapon">>}, - {<<"id">>, shr_weapon:get_id(Weapon)}, - {<<"nam">>, shr_weapon:get_name(Weapon)}, - {<<"rmi">>, shr_weapon:get_minimum_range(Weapon)}, - {<<"rma">>, shr_weapon:get_maximum_range(Weapon)}, - {<<"omni">>, shr_omnimods:encode(shr_weapon:get_omnimods(Weapon))} - ] - }. diff --git a/src/battle/struct/btl_battle.erl b/src/battle/struct/btl_battle.erl index 2a09244..a5b5a06 100644 --- a/src/battle/struct/btl_battle.erl +++ b/src/battle/struct/btl_battle.erl @@ -9,10 +9,8 @@ ( battle, { - used_armor_ids :: ordsets:ordset(shr_armor:id()), - used_weapon_ids :: ordsets:ordset(shr_weapon:id()), - used_portrait_ids :: ordsets:ordset(shr_portrait:id()), - used_tile_ids :: ordsets:ordset(shr_tile:id()), + related_inventory :: shr_inventory:type(), + related_tile_ids :: ordsets:ordset(shr_tile:id()), map :: shr_map:type(), characters :: orddict:orddict(non_neg_integer(), btl_character:type()), players :: orddict:orddict(non_neg_integer(), btl_player:type()), @@ -31,10 +29,8 @@ -export ( [ - get_used_portrait_ids/1, - get_used_weapon_ids/1, - get_used_armor_ids/1, - get_used_tile_ids/1, + get_related_inventory/1, + get_related_tile_ids/1, get_map/1, get_characters/1, get_character/2, @@ -44,20 +40,17 @@ get_encoded_last_turns_effects/1, set_map/2, - set_used_portrait_ids/2, - set_used_weapon_ids/2, - set_used_armor_ids/2, + set_related_inventory/2, set_characters/2, set_character/3, set_players/2, set_player/3, set_current_player_turn/2, - get_used_armor_ids_field/0, - get_used_weapon_ids_field/0, - get_used_portrait_ids_field/0, get_characters_field/0, get_players_field/0, + get_related_inventory_field/0, + get_related_tile_ids_field/0, get_current_player_turn_field/0 ] ). @@ -90,17 +83,11 @@ get_all_timelines (Result, CurrentIndex, EndPoint, ArraySize, Players) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_used_portrait_ids (type()) -> ordsets:ordset(shr_portrait:id()). -get_used_portrait_ids (Battle) -> Battle#battle.used_portrait_ids. +-spec get_related_inventory (type()) -> shr_inventory:type(). +get_related_inventory (Battle) -> Battle#battle.related_inventory. --spec get_used_weapon_ids (type()) -> ordsets:ordset(shr_weapon:id()). -get_used_weapon_ids (Battle) -> Battle#battle.used_weapon_ids. - --spec get_used_armor_ids (type()) -> ordsets:ordset(shr_armor:id()). -get_used_armor_ids (Battle) -> Battle#battle.used_armor_ids. - --spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:id()). -get_used_tile_ids (Battle) -> Battle#battle.used_tile_ids. +-spec get_related_tile_ids (type()) -> ordsets:ordset(shr_tile:id()). +get_related_tile_ids (Battle) -> Battle#battle.related_tile_ids. -spec get_map (type()) -> shr_map:type(). get_map (Battle) -> Battle#battle.map. @@ -146,7 +133,8 @@ get_encoded_last_turns_effects (Battle) -> set_map (Map, Battle) -> Battle#battle { - map = Map + map = Map, + related_tile_ids = shr_map:get_related_tile_ids(Map) }. -spec set_characters @@ -180,40 +168,11 @@ set_players (Players, Battle) -> players = Players }. --spec set_used_portrait_ids - ( - ordsets:ordset(shr_portrait:id()), - type() - ) - -> type(). -set_used_portrait_ids (UPIDs, Battle) -> - Battle#battle - { - used_portrait_ids = UPIDs - }. - --spec set_used_weapon_ids - ( - ordsets:ordset(shr_weapon:id()), - type() - ) - -> type(). -set_used_weapon_ids (UPIDs, Battle) -> - Battle#battle - { - used_weapon_ids = UPIDs - }. - --spec set_used_armor_ids - ( - ordsets:ordset(shr_armor:id()), - type() - ) - -> type(). -set_used_armor_ids (UPIDs, Battle) -> +-spec set_related_inventory ( shr_inventory:type(), type()) -> type(). +set_related_inventory (Inv, Battle) -> Battle#battle { - used_armor_ids = UPIDs + related_inventory = Inv }. -spec set_player (non_neg_integer(), btl_player:type(), type()) -> type(). @@ -232,15 +191,12 @@ set_current_player_turn (PlayerTurn, Battle) -> -spec new (shr_map:type()) -> type(). new (Map) -> - EmptySet = ordsets:new(), EmptyDict = orddict:new(), #battle { - used_portrait_ids = EmptySet, - used_weapon_ids = EmptySet, - used_armor_ids = EmptySet, - used_tile_ids = shr_map:get_used_tile_ids(Map), + related_inventory = shr_inventory:default(), + related_tile_ids = shr_map:get_related_tile_ids(Map), map = Map, characters = EmptyDict, players = EmptyDict, @@ -250,14 +206,11 @@ new (Map) -> -spec get_characters_field () -> non_neg_integer(). get_characters_field () -> #battle.characters. --spec get_used_portrait_ids_field () -> non_neg_integer(). -get_used_portrait_ids_field () -> #battle.used_portrait_ids. - --spec get_used_weapon_ids_field () -> non_neg_integer(). -get_used_weapon_ids_field () -> #battle.used_weapon_ids. +-spec get_related_inventory_field () -> non_neg_integer(). +get_related_inventory_field () -> #battle.related_inventory. --spec get_used_armor_ids_field () -> non_neg_integer(). -get_used_armor_ids_field () -> #battle.used_armor_ids. +-spec get_related_tile_ids_field () -> non_neg_integer(). +get_related_tile_ids_field () -> #battle.related_tile_ids. -spec get_players_field () -> non_neg_integer(). get_players_field () -> #battle.players. diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 9194380..1136c8f 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -1,5 +1,13 @@ -module(btl_character). +-define(PLAYER_IX_FIELD, <<"pla">>). +-define(RANK_FIELD, <<"rnk">>). +-define(LOCATION_FIELD, <<"lc">>). +-define(CURRENT_HEALTH_FIELD, <<"he">>). +-define(IS_ACTIVE_FIELD, <<"ena">>). +-define(IS_DEFEATED_FIELD, <<"dea">>). +-define(BASE_CHAR_FIELD, <<"bas">>). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -75,7 +83,9 @@ [ new/4, resolve/2, - to_unresolved/1 + to_unresolved/1, + decode/1, + encode/1 ] ). @@ -247,3 +257,30 @@ get_is_active_field () -> #btl_char_ref.is_active. get_is_defeated_field () -> #btl_char_ref.is_defeated. -spec get_base_character_field() -> non_neg_integer(). get_base_character_field () -> #btl_char_ref.base. + +-spec decode (map()) -> unresolved(). +decode (Map) -> + #btl_char_ref + { + player_ix = maps:get(?PLAYER_IX_FIELD, Map), + rank = maps:get(?RANK_FIELD, Map), + location = shr_location:decode(maps:get(?LOCATION_FIELD, Map)), + current_health = maps:get(?CURRENT_HEALTH_FIELD, Map), + is_active = maps:get(?IS_ACTIVE_FIELD, Map), + is_defeated = maps:get(?IS_DEFEATED_FIELD, Map), + base = shr_character:decode(maps:get(?BASE_CHAR_FIELD, Map)) + }. + +-spec encode (unresolved()) -> unresolved(). +encode (CharRef) -> + { + [ + {?PLAYER_IX_FIELD, CharRef#btl_char_ref.player_ix}, + {?RANK_FIELD, CharRef#btl_char_ref.rank}, + {?LOCATION_FIELD, shr_location:encode(CharRef#btl_char_ref.location)}, + {?CURRENT_HEALTH_FIELD, CharRef#btl_char_ref.current_health}, + {?IS_ACTIVE_FIELD, CharRef#btl_char_ref.is_active}, + {?IS_DEFEATED_FIELD, CharRef#btl_char_ref.is_defeated}, + {?BASE_CHAR_FIELD, shr_character:encode(CharRef#btl_char_ref.base)} + ] + }. diff --git a/src/battle/struct/btl_character_turn_data.erl b/src/battle/struct/btl_character_turn_data.erl index 6742d1c..5f44f8a 100644 --- a/src/battle/struct/btl_character_turn_data.erl +++ b/src/battle/struct/btl_character_turn_data.erl @@ -10,7 +10,6 @@ dirty :: boolean(), battle :: btl_battle:type(), character :: btl_character:type(), - character_current_data :: btl_character_current_data:type(), character_ix :: non_neg_integer() } ). @@ -30,12 +29,10 @@ get_battle_is_dirty/1, get_battle/1, get_character/1, - get_character_current_data/1, get_character_ix/1, set_battle/2, - set_character/2, - refresh_character_current_data/1 + set_character/2 ] ). @@ -43,29 +40,43 @@ ( [ clean_battle/1, - refreshr_character/1 + refresh_character/1 ] ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec resolve_character_at + ( + btl_battle:type(), + non_neg_integer() + ) -> btl_charater:type(). +resolve_character_at (Battle, CharacterIX) -> + CharacterRef = btl_battle:get_character(CharacterIX, Battle), + Location = btl_character:get_location(CharacterRef), + Map = btl_battle:get_map(Battle), + + TileInstance = shr_map:get_tile_instance(Location, Map), + TileClassID = shr_tile_instance:get_tile_id(TileInstance), + Tile = shr_tile:from_id(TileClassID), + TileOmnimods = shr_tile:get_omnimods(Tile), + + Character = btl_character:resolve(TileOmnimods, CharacterRef), + + Character. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec new (btl_battle:type(), non_neg_integer()) -> type(). new (Battle, CharacterIX) -> - Character = btl_battle:get_character(CharacterIX, Battle), - Map = btl_battle:get_map(Battle), - CharacterCurrentData = btl_character_current_data:new(Character, Map), #type { dirty = false, battle = Battle, - character = Character, - character_current_data = CharacterCurrentData, + character = resolve_character_at(Battle, CharacterIX), character_ix = CharacterIX }. @@ -78,9 +89,6 @@ get_battle (Data) -> Data#type.battle. -spec get_character (type()) -> btl_character:type(). get_character (Data) -> Data#type.character. --spec get_character_current_data (type()) -> btl_character_current_data:type(). -get_character_current_data (Data) -> Data#type.character_current_data. - -spec get_character_ix (type()) -> non_neg_integer(). get_character_ix (Data) -> Data#type.character_ix. @@ -96,19 +104,6 @@ set_character (Character, Data) -> character = Character }. --spec refresh_character_current_data (type()) -> type(). -refresh_character_current_data (Data) -> - Battle = Data#type.battle, - Character = Data#type.character, - Map = btl_battle:get_map(Battle), - CharacterCurrentData = btl_character_current_data:new(Character, Map), - - Data#type - { - character_current_data = CharacterCurrentData - }. - - -spec clean_battle (type()) -> type(). clean_battle (Data) -> Data#type @@ -123,15 +118,10 @@ clean_battle (Data) -> ) }. --spec refreshr_character (type()) -> type(). -refreshr_character (Data) -> +-spec refresh_character (type()) -> type(). +refresh_character (Data) -> Data#type { dirty = false, - character = - btl_battle:get_character - ( - Data#type.character_ix, - Data#type.battle - ) + character = resolve_character_at(Data#type.battle, Data#type.character_ix) }. diff --git a/src/shared/reply/shr_add_armor.erl b/src/shared/reply/shr_add_armor.erl new file mode 100644 index 0000000..e4a97b0 --- /dev/null +++ b/src/shared/reply/shr_add_armor.erl @@ -0,0 +1,28 @@ +-module(shr_add_armor). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export([generate/1]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate (shr_armor:type()) -> {list(any())}. +generate (Armor) -> + { + [ + {<<"msg">>, <<"add_armor">>}, + {<<"id">>, shr_armor:get_id(Armor)}, + {<<"nam">>, shr_armor:get_name(Armor)}, + {<<"omni">>, shr_omnimods:encode(shr_armor:get_omnimods(Armor))} + ] + }. diff --git a/src/shared/reply/shr_add_portrait.erl b/src/shared/reply/shr_add_portrait.erl new file mode 100644 index 0000000..7c031b4 --- /dev/null +++ b/src/shared/reply/shr_add_portrait.erl @@ -0,0 +1,29 @@ +-module(shr_add_portrait). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export([generate/1]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate (shr_portrait:type()) -> {list(any())}. +generate (Portrait) -> + { + [ + {<<"msg">>, <<"add_portrait">>}, + {<<"id">>, shr_portrait:get_id(Portrait)}, + {<<"nam">>, shr_portrait:get_name(Portrait)}, + {<<"bid">>, shr_portrait:get_body_id(Portrait)}, + {<<"iid">>, shr_portrait:get_icon_id(Portrait)} + ] + }. diff --git a/src/shared/reply/shr_add_weapon.erl b/src/shared/reply/shr_add_weapon.erl new file mode 100644 index 0000000..44a83dd --- /dev/null +++ b/src/shared/reply/shr_add_weapon.erl @@ -0,0 +1,30 @@ +-module(shr_add_weapon). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export([generate/1]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate (shr_weapon:type()) -> {list(any())}. +generate (Weapon) -> + { + [ + {<<"msg">>, <<"add_weapon">>}, + {<<"id">>, shr_weapon:get_id(Weapon)}, + {<<"nam">>, shr_weapon:get_name(Weapon)}, + {<<"rmi">>, shr_weapon:get_minimum_range(Weapon)}, + {<<"rma">>, shr_weapon:get_maximum_range(Weapon)}, + {<<"omni">>, shr_omnimods:encode(shr_weapon:get_omnimods(Weapon))} + ] + }. diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl index f5eba8f..e505d91 100644 --- a/src/shared/struct/inventory/shr_equipment.erl +++ b/src/shared/struct/inventory/shr_equipment.erl @@ -56,6 +56,13 @@ set_glyph_board/2, set_glyphs/2, + ataxia_set_primary_weapon/2, + ataxia_set_secondary_weapon/2, + ataxia_set_armor/2, + ataxia_set_portrait/2, + ataxia_set_glyph_board/2, + ataxia_set_glyphs/2, + get_primary_weapon_id/1, get_secondary_weapon_id/1, get_armor_id/1, @@ -68,16 +75,30 @@ set_armor_id/2, set_portrait_id/2, set_glyph_board_id/2, - set_glyph_ids/2 + set_glyph_ids/2, + + ataxia_set_primary_weapon_id/2, + ataxia_set_secondary_weapon_id/2, + ataxia_set_armor_id/2, + ataxia_set_portrait_id/2, + ataxia_set_glyph_board_id/2, + ataxia_set_glyph_ids/2 ] ). -%%%% Accessors +%%%% -export ( [ default/0, - default_unresolved/0 + default_unresolved/0, + + get_primary_weapon_field/0, + get_secondary_weapon_field/0, + get_armor_field/0, + get_portrait_field/0, + get_glyph_board_field/0, + get_glyphs_field/0 ] ). @@ -144,6 +165,19 @@ set_primary_weapon (V, Eq) when is_record(Eq, shr_eq) -> set_primary_weapon (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ primary = shr_weapon:get_id(V) }. +-spec ataxia_set_primary_weapon + (shr_weapon:type(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_primary_weapon (V, Eq) -> + { + set_primary_weapon(V, Eq), + ataxic:update_field + ( + get_primary_weapon_field(), + ataxic:constant(shr_weapon:get_id(V)) + ) + }. + -spec set_secondary_weapon (shr_weapon:type(), type()) -> type(); (shr_weapon:type(), unresolved()) -> unresolved(). @@ -152,6 +186,19 @@ set_secondary_weapon (V, Eq) when is_record(Eq, shr_eq) -> set_secondary_weapon (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ secondary = shr_weapon:get_id(V) }. +-spec ataxia_set_secondary_weapon + (shr_weapon:type(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_secondary_weapon (V, Eq) -> + { + set_secondary_weapon(V, Eq), + ataxic:update_field + ( + get_secondary_weapon_field(), + ataxic:constant(shr_weapon:get_id(V)) + ) + }. + -spec set_armor (shr_armor:type(), type()) -> type(); (shr_armor:type(), unresolved()) -> unresolved(). @@ -160,6 +207,19 @@ set_armor (V, Eq) when is_record(Eq, shr_eq) -> set_armor (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ armor = shr_armor:get_id(V) }. +-spec ataxia_set_armor + (shr_armor:type(), type()) -> {type(), ataxic:basic()}; + (shr_armor:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_armor (V, Eq) -> + { + set_armor(V, Eq), + ataxic:update_field + ( + get_armor_field(), + ataxic:constant(shr_armor:get_id(V)) + ) + }. + -spec set_portrait (shr_portrait:type(), type()) -> type(); (shr_portrait:type(), unresolved()) -> unresolved(). @@ -168,6 +228,19 @@ set_portrait (V, Eq) when is_record(Eq, shr_eq) -> set_portrait (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ portrait = shr_portrait:get_id(V) }. +-spec ataxia_set_portrait + (shr_portrait:type(), type()) -> {type(), ataxic:basic()}; + (shr_portrait:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_portrait (V, Eq) -> + { + set_portrait(V, Eq), + ataxic:update_field + ( + get_portrait_field(), + ataxic:constant(shr_portrait:get_id(V)) + ) + }. + -spec set_glyph_board (shr_glyph_board:type(), type()) -> type(); (shr_glyph_board:type(), unresolved()) -> unresolved(). @@ -176,6 +249,19 @@ set_glyph_board (V, Eq) when is_record(Eq, shr_eq) -> set_glyph_board (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ glyph_board = shr_glyph_board:get_id(V) }. +-spec ataxia_set_glyph_board + (shr_glyph_board:type(), type()) -> {type(), ataxic:basic()}; + (shr_glyph_board:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyph_board (V, Eq) -> + { + set_glyph_board(V, Eq), + ataxic:update_field + ( + get_glyph_board_field(), + ataxic:constant(shr_glyph_board:get_id(V)) + ) + }. + -spec set_glyphs (list(shr_glyph:type()), type()) -> type(); (list(shr_glyph:type()), unresolved()) -> unresolved(). @@ -184,6 +270,19 @@ set_glyphs (V, Eq) when is_record(Eq, shr_eq) -> set_glyphs (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ glyphs = lists:map(fun shr_glyph:get_id/1, V) }. +-spec ataxia_set_glyphs + (shr_glyph:type(), type()) -> {type(), ataxic:basic()}; + (shr_glyph:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyphs (V, Eq) -> + { + set_glyphs(V, Eq), + ataxic:update_field + ( + get_glyphs_field(), + ataxic:constant(shr_glyph:get_id(V)) + ) + }. + -spec set_primary_weapon_id (shr_weapon:id(), type()) -> type(); (shr_weapon:id(), unresolved()) -> unresolved(). @@ -192,6 +291,19 @@ set_primary_weapon_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_primary_weapon_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ primary = shr_weapon:from_id(V) }. +-spec ataxia_set_primary_weapon_id + (shr_weapon:id(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_primary_weapon_id (V, Eq) -> + { + set_primary_weapon_id(V, Eq), + ataxic:update_field + ( + get_primary_weapon_field(), + ataxic:constant(V) + ) + }. + -spec set_secondary_weapon_id (shr_weapon:id(), type()) -> type(); (shr_weapon:id(), unresolved()) -> unresolved(). @@ -200,6 +312,19 @@ set_secondary_weapon_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_secondary_weapon_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ secondary = shr_weapon:from_id(V) }. +-spec ataxia_set_secondary_weapon_id + (shr_weapon:id(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_secondary_weapon_id (V, Eq) -> + { + set_secondary_weapon_id(V, Eq), + ataxic:update_field + ( + get_secondary_weapon_field(), + ataxic:constant(V) + ) + }. + -spec set_armor_id (shr_armor:id(), type()) -> type(); (shr_armor:id(), unresolved()) -> unresolved(). @@ -208,6 +333,19 @@ set_armor_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_armor_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ armor = shr_armor:from_id(V) }. +-spec ataxia_set_armor_id + (shr_armor:id(), type()) -> {type(), ataxic:basic()}; + (shr_armor:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_armor_id (V, Eq) -> + { + set_armor_id(V, Eq), + ataxic:update_field + ( + get_armor_field(), + ataxic:constant(V) + ) + }. + -spec set_portrait_id (shr_portrait:id(), type()) -> type(); (shr_portrait:id(), unresolved()) -> unresolved(). @@ -216,6 +354,19 @@ set_portrait_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_portrait_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ portrait = shr_portrait:from_id(V) }. +-spec ataxia_set_portrait_id + (shr_portrait:id(), type()) -> {type(), ataxic:basic()}; + (shr_portrait:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_portrait_id (V, Eq) -> + { + set_portrait_id(V, Eq), + ataxic:update_field + ( + get_portrait_field(), + ataxic:constant(V) + ) + }. + -spec set_glyph_board_id (shr_glyph_board:id(), type()) -> type(); (shr_glyph_board:id(), unresolved()) -> unresolved(). @@ -224,6 +375,19 @@ set_glyph_board_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_glyph_board_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ glyph_board = shr_glyph_board:from_id(V) }. +-spec ataxia_set_glyph_board_id + (shr_glyph_board:id(), type()) -> {type(), ataxic:basic()}; + (shr_glyph_board:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyph_board_id (V, Eq) -> + { + set_glyph_board_id(V, Eq), + ataxic:update_field + ( + get_glyph_board_field(), + ataxic:constant(V) + ) + }. + -spec set_glyph_ids (list(shr_glyph:id()), type()) -> type(); (list(shr_glyph:id()), unresolved()) -> unresolved(). @@ -232,6 +396,19 @@ set_glyph_ids (V, Eq) when is_record(Eq, shr_eq_ref) -> set_glyph_ids (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ glyphs = lists:map(fun shr_glyph:from_id/1, V) }. +-spec ataxia_set_glyph_ids + (shr_glyph:id(), type()) -> {type(), ataxic:basic()}; + (shr_glyph:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyph_ids (V, Eq) -> + { + set_glyph_ids(V, Eq), + ataxic:update_field + ( + get_glyphs_field(), + ataxic:constant(V) + ) + }. + -spec default () -> type(). default () -> #shr_eq @@ -255,3 +432,21 @@ default_unresolved () -> glyph_board = shr_glyph_board:default_id(), glyphs = [] }. + +-spec get_primary_weapon_field () -> non_neg_integer(). +get_primary_weapon_field () -> #shr_eq_ref.primary. + +-spec get_secondary_weapon_field () -> non_neg_integer(). +get_secondary_weapon_field () -> #shr_eq_ref.secondary. + +-spec get_armor_field () -> non_neg_integer(). +get_armor_field () -> #shr_eq_ref.armor. + +-spec get_portrait_field () -> non_neg_integer(). +get_portrait_field () -> #shr_eq_ref.portrait. + +-spec get_glyph_board_field () -> non_neg_integer(). +get_glyph_board_field () -> #shr_eq_ref.glyph_board. + +-spec get_glyphs_field () -> non_neg_integer(). +get_glyphs_field () -> #shr_eq_ref.glyphs. diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl index 0670546..4f64f68 100644 --- a/src/shared/struct/inventory/shr_inventory.erl +++ b/src/shared/struct/inventory/shr_inventory.erl @@ -32,11 +32,17 @@ get_glyph_boards/1, get_glyphs/1, - set_weapons/2, - set_armors/2, - set_portraits/2, - set_glyph_boards/2, - set_glyphs/2 + add_weapon/2, + add_armor/2, + add_portrait/2, + add_glyph_board/2, + add_glyph/2, + + ataxia_add_armor/2, + ataxia_add_weapon/2, + ataxia_add_portrait/2, + ataxia_add_glyph_board/2, + ataxia_add_glyph/2 ] ). @@ -46,7 +52,8 @@ [ default/0, allows_equipment/2, - add_equipment/2 + add_equipment/2, + ataxia_add_equipment/2 ] ). @@ -72,20 +79,164 @@ get_glyph_boards (Inv) -> Inv#inventory.glyph_boards. -spec get_glyphs (type()) -> ordsets:ordset(shr_glyph:id()). get_glyphs (Inv) -> Inv#inventory.glyphs. --spec set_weapons (ordsets:ordset(shr_weapon:id()), type()) -> type(). -set_weapons (V, Inv) -> Inv#inventory{ weapons = V }. --spec set_armors (ordsets:ordset(shr_armor:id()), type()) -> type(). -set_armors (V, Inv) -> Inv#inventory{ armors = V }. +-spec add_weapon (shr_weapon:id(), type()) -> type(). +add_weapon (V, Inv) -> Inv#inventory{ weapons = V }. + +-spec add_armor (shr_armor:id(), type()) -> type(). +add_armor (V, Inv) -> Inv#inventory{ armors = V }. + +-spec add_portrait (shr_portrait:id(), type()) -> type(). +add_portrait (V, Inv) -> Inv#inventory{ portraits = V }. + +-spec add_glyph_board (shr_glyph_board:id(), type()) -> type(). +add_glyph_board (V, Inv) -> Inv#inventory{ glyph_boards = V }. + +-spec add_glyph (shr_glyph:id(), type()) -> type(). +add_glyph (V, Inv) -> Inv#inventory{ glyphs = V }. + + +-spec ataxia_add_weapon + ( + shr_weapon:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_weapon (V, Inv) -> + CurrentWeapons = Inv#inventory.weapons, --spec set_portraits (ordsets:ordset(shr_portrait:id()), type()) -> type(). -set_portraits (V, Inv) -> Inv#inventory{ portraits = V }. + case ordsets:is_element(V, CurrentWeapons) of + true -> Inv; + false -> + { + Inv#inventory{ weapons = ordsets:add_element(V, CurrentWeapons) }, + ataxic:update_field + ( + get_weapons_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. --spec set_glyph_boards (ordsets:ordset(shr_glyph_board:id()), type()) -> type(). -set_glyph_boards (V, Inv) -> Inv#inventory{ glyph_boards = V }. +-spec ataxia_add_armor + ( + shr_armor:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_armor (V, Inv) -> + CurrentArmors = Inv#inventory.armors, + + case ordsets:is_element(V, CurrentArmors) of + true -> Inv; + false -> + { + Inv#inventory{ armors = ordsets:add_element(V, CurrentArmors) }, + ataxic:update_field + ( + get_armors_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. + +-spec ataxia_add_portrait + ( + shr_portrait:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_portrait (V, Inv) -> + CurrentPortraits = Inv#inventory.portraits, + + case ordsets:is_element(V, CurrentPortraits) of + true -> Inv; + false -> + { + Inv#inventory + { + portraits = ordsets:add_element(V, CurrentPortraits) + }, + ataxic:update_field + ( + get_portraits_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. + +-spec ataxia_add_glyph_board + ( + shr_glyph_board:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_glyph_board (V, Inv) -> + CurrentGlyphBoards = Inv#inventory.glyph_boards, + + case ordsets:is_element(V, CurrentGlyphBoards) of + true -> Inv; + false -> + { + Inv#inventory + { + glyph_boards = ordsets:add_element(V, CurrentGlyphBoards) + }, + ataxic:update_field + ( + get_glyph_boards_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. + +-spec ataxia_add_glyph + ( + shr_glyph:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_glyph (V, Inv) -> + CurrentGlyphs = Inv#inventory.glyphs, + + case ordsets:is_element(V, CurrentGlyphs) of + true -> Inv; + false -> + { + Inv#inventory{ glyphs = ordsets:add_element(V, CurrentGlyphs) }, + ataxic:update_field + ( + get_glyphs_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. --spec set_glyphs (ordsets:ordset(shr_glyph:id()), type()) -> type(). -set_glyphs (V, Inv) -> Inv#inventory{ glyphs = V }. -spec default () -> type(). default () -> @@ -183,3 +334,57 @@ add_equipment (Eq, Inv) -> shr_equipment:get_glyph_ids(Eq) ) }. + +-spec ataxia_add_equipment + ( + (shr_equipment:type()|shr_equipment:unresolved()), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_equipment (Eq, Inv) -> + {S0Inv, Ataxic0} = + ataxia_add_weapon(shr_equipment:get_primary_weapon_id(Eq), Inv), + + {S1Inv, Ataxic1} = + ataxia_add_weapon(shr_equipment:get_secondary_weapon_id(Eq), S0Inv), + + {S2Inv, Ataxic2} = ataxia_add_armor(shr_equipment:get_armor_id(Eq), S1Inv), + + {S3Inv, Ataxic3} = + ataxia_add_glyph_board(shr_equipment:get_glyph_board_id(Eq), S2Inv), + + {S4Inv, Ataxic4s} = + lists:foldl + ( + fun (GlyphID, {PrevInv, PrevAtaxic}) -> + {NewInv, NewAtaxic} = ataxia_add_glyph(GlyphID, PrevInv), + {NewInv, [NewAtaxic|PrevAtaxic]} + end, + {S3Inv, []}, + shr_equipment:get_glyph_ids(Eq) + ), + + { + S4Inv, + lists:flatten + ( + [Ataxic0, Ataxic1, Ataxic2, Ataxic3], + lists:flatten(Ataxic4s) + ) + }. + + +-spec get_weapons_field () -> non_neg_integer(). +get_weapons_field () -> #inventory.weapons. + +-spec get_armors_field () -> non_neg_integer(). +get_armors_field () -> #inventory.armors. + +-spec get_portraits_field () -> non_neg_integer(). +get_portraits_field () -> #inventory.portraits. + +-spec get_glyph_boards_field () -> non_neg_integer(). +get_glyph_boards_field () -> #inventory.glyph_boards. + +-spec get_glyphs_field () -> non_neg_integer(). +get_glyphs_field () -> #inventory.glyphs. -- cgit v1.2.3-70-g09d2