summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-04-26 17:45:48 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-04-26 17:45:48 +0200 |
commit | a7c6455285cfd3a671078be4e58df0afae07bf0c (patch) | |
tree | b06531c2423e0fa6a1f60ace83b5e03a40067262 | |
parent | ec6eec260d6383ae948505c3d42b3055ae3dd94c (diff) |
...
-rw-r--r-- | src/bounty/bnt_join_battle.erl | 101 | ||||
-rw-r--r-- | src/roster/query/rst_update.erl | 37 | ||||
-rw-r--r-- | src/roster/reply/rst_add_char.erl | 12 | ||||
-rw-r--r-- | src/roster/struct/rst_character.erl | 239 | ||||
-rw-r--r-- | src/roster/struct/rst_roster.erl | 75 |
5 files changed, 93 insertions, 371 deletions
diff --git a/src/bounty/bnt_join_battle.erl b/src/bounty/bnt_join_battle.erl index fa5d36e..68ef167 100644 --- a/src/bounty/bnt_join_battle.erl +++ b/src/bounty/bnt_join_battle.erl @@ -13,70 +13,6 @@ %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% USED IDS COLLECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec update_ordset - ( - ordsets:ordset(any()), - ordsets:ordset(any()) - ) - -> ataxic:basic(). -update_ordset (New, Old) -> - AddedElements = ordsets:subtract(New, Old), - - ataxic:sequence - ( - lists:map - ( - fun (V) -> - ataxic:apply_function - ( - ordsets, - add_element, - [ - ataxic:constant(V), - ataxic:current_value() - ] - ) - end, - ordsets:to_list(AddedElements) - ) - ). - --spec get_equipment_ids - ( - list(rst_character:type()) - ) - -> - { - ordsets:ordset(shr_portrait:id()), - ordsets:ordset(shr_weapon:id()), - ordsets:ordset(shr_armor:id()) - }. -get_equipment_ids (Characters) -> - { - UsedPortraitIDs, - UsedWeaponIDs, - UsedArmorIDs - } = - lists:foldl - ( - fun (Character, {UPIDs, UWIDs, UAIDs}) -> - {MWpID, SWpID} = rst_character:get_weapon_ids(Character), - AID = rst_character:get_armor_id(Character), - PID = rst_character:get_portrait_id(Character), - { - ordsets:add_element(PID, UPIDs), - ordsets:add_element(MWpID, ordsets:add_element(SWpID, UWIDs)), - ordsets:add_element(AID, UAIDs) - } - end, - {ordsets:new(), ordsets:new(), ordsets:new()}, - Characters - ), - - {UsedPortraitIDs, UsedWeaponIDs, UsedArmorIDs}. - - %%%% ROSTERS HANDLING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec get_forbidden_locations ( @@ -131,21 +67,10 @@ find_random_location (Map, ForbiddenLocations) -> end end. --spec get_glyphs_omnimods (rst_character:type()) -> shr_omnimods:type(). -get_glyphs_omnimods (RosterChar) -> - GlyphBoardID = rst_character:get_glyph_board_id(RosterChar), - GlyphIDs = rst_character:get_glyph_ids(RosterChar), - GlyphBoard = shr_glyph_board:from_id(GlyphBoardID), - Glyphs = lists:map(fun shr_glyph:from_id/1, GlyphIDs), - case shr_glyph_board:get_omnimods_with_glyphs(Glyphs, GlyphBoard) of - {ok, Result} -> Result; - error -> shr_omnimods:new([], [], [], []) - end. - -spec create_character ( non_neg_integer(), - rst_character:type(), + shr_character:unresolved(), shr_map:type(), ordsets:ordset(shr_location:type()) ) @@ -153,27 +78,17 @@ get_glyphs_omnimods (RosterChar) -> create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) -> {Location, Tile} = find_random_location(Map, ForbiddenLocations), TileOmnimods = shr_tile:get_omnimods(Tile), - GlyphsOmnimods = get_glyphs_omnimods(RosterChar), - Result = - btl_character:new - ( - PlayerIX, - rst_character:get_name(RosterChar), - optional, % TODO: link this to roster. - GlyphsOmnimods, - rst_character:get_portrait_id(RosterChar), - rst_character:get_weapon_ids(RosterChar), - rst_character:get_armor_id(RosterChar), - Location, - TileOmnimods - ), + ResolvedBaseChar = shr_character:resolve(TileOmnimods, RosterChar), + + % TODO: link rank to roster. + Result = btl_character:new(PlayerIX, optional, Location, ResolvedBaseChar), Result. -spec handle_characters ( - list(rst_character:type()), + list(shr_character:unresolved()), non_neg_integer(), shr_map:type(), ordsets:ordset(shr_location:type()), @@ -280,7 +195,7 @@ add_player (PlayerID, PlayerSummaryIX, PlayerSummaryCategory, Battle) -> -spec add_characters ( - list(rst_character:type()), + list(shr_character:unresolved()), non_neg_integer(), btl_battle:type() ) @@ -369,7 +284,7 @@ add_characters (RosterCharacters, PlayerIX, Battle) -> shr_player:id(), list(non_neg_integer()) ) - -> list(rst_character:type()). + -> list(shr_character:unresolved()). get_roster_characters (PlayerID, SelectedRosterCharacterIXs) -> Player = shr_timed_cache:fetch(player_db, ataxia_security:any(), PlayerID), RosterID = shr_player:get_roster_id(Player), diff --git a/src/roster/query/rst_update.erl b/src/roster/query/rst_update.erl index bbae76e..933c52c 100644 --- a/src/roster/query/rst_update.erl +++ b/src/roster/query/rst_update.erl @@ -3,7 +3,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type decoded_character() :: {non_neg_integer(), rst_character:type()}. +-type decoded_character() :: {non_neg_integer(), shr_character:unresolved()}. -record ( @@ -41,7 +41,7 @@ decode_character_list (EncodedCharactersList) -> lists:map ( fun (Map) -> - {maps:get(<<"ix">>, Map), rst_character:decode(Map)} + {maps:get(<<"ix">>, Map), shr_character:decode(Map)} end, EncodedCharactersList ). @@ -102,15 +102,19 @@ update_data (QueryState, Input) -> Inventory = QueryState#query_state.inventory, Characters = Input#input.characters, - lists:map + %% TODO: Assert true, once inventories are put in place. + lists:all ( fun ({_IX, Character}) -> - rst_character:validate(Inventory, Character) + shr_inventory:allows_equipment + ( + shr_character:get_equipment(Character), + Inventory + ) end, Characters ), - %% TODO [FUNCTION: chr][REQUIRED]: unimplemented. QueryState. -spec commit_update (query_state(), input()) -> 'ok'. @@ -122,21 +126,14 @@ commit_update (QueryState, Input) -> RosterID = shr_player:get_roster_id(Player), - {UpdatedRoster, QueryList} = + {UpdatedRoster, RosterAtaxiaUpdates} = lists:foldl ( fun ({IX, Character}, {CurrentRoster, UpdateList}) -> - { - rst_roster:set_character(IX, Character, CurrentRoster), - [ - ataxic_sugar:update_orddict_element - ( - IX, - ataxic:constant(Character) - ) - | UpdateList - ] - } + {UpdatedRoster, NewUpdate} = + rst_roster:ataxia_set_character(IX, Character, CurrentRoster), + + {UpdatedRoster, [NewUpdate|UpdateList]} end, {Roster, []}, Characters @@ -149,11 +146,7 @@ commit_update (QueryState, Input) -> ataxia_security:user_from_id(PlayerID), ataxic:update_value ( - ataxic:update_field - ( - rst_roster:get_characters_field(), - ataxic:sequence(QueryList) - ) + ataxic:optimize(ataxic:sequence(RosterAtaxiaUpdates)) ), RosterID ), diff --git a/src/roster/reply/rst_add_char.erl b/src/roster/reply/rst_add_char.erl index 0f360ed..d759383 100644 --- a/src/roster/reply/rst_add_char.erl +++ b/src/roster/reply/rst_add_char.erl @@ -19,22 +19,14 @@ -spec generate ( non_neg_integer(), - rst_character:type() + shr_character:unresolved() ) -> {list(any())}. generate (IX, Character) -> - {ActiveWeapon, SecondaryWeapon} = rst_character:get_weapon_ids(Character), - { [ {<<"msg">>, <<"add_char">>}, {<<"ix">>, IX}, - {<<"nam">>, rst_character:get_name(Character)}, - {<<"prt">>, rst_character:get_portrait_id(Character)}, - {<<"awp">>, ActiveWeapon}, - {<<"swp">>, SecondaryWeapon}, - {<<"ar">>, rst_character:get_armor_id(Character)}, - {<<"gls">>, rst_character:get_glyph_ids(Character)}, - {<<"gb">>, rst_character:get_glyph_board_id(Character)} + {<<"bas">>, shr_character:encode(Character)} ] }. diff --git a/src/roster/struct/rst_character.erl b/src/roster/struct/rst_character.erl deleted file mode 100644 index 61d7b7e..0000000 --- a/src/roster/struct/rst_character.erl +++ /dev/null @@ -1,239 +0,0 @@ --module(rst_character). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - rst_char, - { - name :: binary(), - portrait_id :: shr_portrait:id(), - weapon_ids :: {shr_weapon:id(), shr_weapon:id()}, - armor_id :: shr_armor:id(), - glyph_ids :: list(shr_glyph:id()), - glyph_board_id :: shr_glyph_board:id() - } -). - --opaque type() :: #rst_char{}. - --export_type([type/0]). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_name/1, - get_portrait_id/1, - get_weapon_ids/1, - get_armor_id/1, - get_glyph_ids/1, - get_glyph_board_id/1, - - set_name/2, - set_portrait_id/2, - set_weapon_ids/2, - set_armor_id/2, - set_glyph_ids/2, - set_glyph_board_id/2, - - get_name_field/0, - get_portrait_id_field/0, - get_weapon_ids_field/0, - get_armor_id_field/0, - get_glyph_ids_field/0, - get_glyph_board_id_field/0 - ] -). - --export -( - [ - decode/1, - new/0 - ] -). - --export -( - [ - validate/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec validate_name (binary()) -> ok. -validate_name (_Name) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - --spec validate_portrait_id (shr_inventory:type(), shr_portrait:id()) -> ok. -validate_portrait_id (_Inventory, _Portrait) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - --spec validate_weapons - ( - shr_inventory:type(), - {shr_weapon:id(), shr_weapon:id()} - ) - -> ok. -validate_weapons (_Inventory, {_ActiveWeapon, _SecondaryWeapon}) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - --spec validate_armor (shr_inventory:type(), shr_armor:id()) -> ok. -validate_armor (_Inventory, _Armor) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - --spec validate_glyphs (shr_inventory:type(), list(shr_glyph:id())) -> ok. -validate_glyphs (_Inventory, _Glyphs) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - --spec validate_glyph_board (shr_inventory:type(), shr_glyph_board:id()) -> ok. -validate_glyph_board (_Inventory, _GlyphBoard) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - --spec validate_glyphs_on_board - ( - list(shr_glyph:id()), - shr_glyph_board:id() - ) - -> ok. -validate_glyphs_on_board (_Glyphs, _GlyphBoard) -> - % TODO [SECURITY][LOW]: unimplemented - ok. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_name (type()) -> binary(). -get_name (Char) -> Char#rst_char.name. - --spec get_portrait_id (type()) -> shr_portrait:id(). -get_portrait_id (Char) -> Char#rst_char.portrait_id. - --spec get_weapon_ids (type()) -> {shr_weapon:id(), shr_weapon:id()}. -get_weapon_ids (Char) -> Char#rst_char.weapon_ids. - --spec get_armor_id (type()) -> shr_armor:id(). -get_armor_id (Char) -> Char#rst_char.armor_id. - --spec get_glyph_ids (type()) -> list(shr_glyph:id()). -get_glyph_ids (Char) -> Char#rst_char.glyph_ids. - --spec get_glyph_board_id (type()) -> shr_glyph_board:id(). -get_glyph_board_id (Char) -> Char#rst_char.glyph_board_id. - - --spec set_name (binary(), type()) -> type(). -set_name (Name, Char) -> - Char#rst_char - { - name = Name - }. - --spec set_portrait_id (shr_portrait:id(), type()) -> type(). -set_portrait_id (PortraitID, Char) -> - Char#rst_char - { - portrait_id = PortraitID - }. - --spec set_armor_id (shr_armor:id(), type()) -> type(). -set_armor_id (ArmorID, Char) -> - Char#rst_char - { - armor_id = ArmorID - }. - --spec set_weapon_ids ({shr_weapon:id(), shr_weapon:id()}, type()) -> type(). -set_weapon_ids (WeaponIDs, Char) -> - Char#rst_char - { - weapon_ids = WeaponIDs - }. - --spec set_glyph_ids (list(shr_glyph:id()), type()) -> type(). -set_glyph_ids (GlyphIDs, Char) -> - Char#rst_char - { - glyph_ids = GlyphIDs - }. - --spec set_glyph_board_id (shr_glyph_board:id(), type()) -> type(). -set_glyph_board_id (GlyphBoardID, Char) -> - Char#rst_char - { - glyph_board_id = GlyphBoardID - }. - --spec new () -> type(). -new () -> - UnarmedID = shr_weapon:get_id(shr_weapon:none()), - #rst_char - { - name = <<"Nameless">>, - portrait_id = shr_portrait:get_id(shr_portrait:default()), - weapon_ids = {UnarmedID, UnarmedID}, - armor_id = shr_armor:get_id(shr_armor:none()), - glyph_ids = [], - glyph_board_id = shr_glyph_board:get_id(shr_glyph_board:none()) - }. - --spec get_name_field () -> non_neg_integer(). -get_name_field () -> #rst_char.name. --spec get_portrait_id_field () -> non_neg_integer(). -get_portrait_id_field () -> #rst_char.portrait_id. --spec get_armor_id_field () -> non_neg_integer(). -get_armor_id_field () -> #rst_char.armor_id. --spec get_weapon_ids_field () -> non_neg_integer(). -get_weapon_ids_field () -> #rst_char.weapon_ids. --spec get_glyph_ids_field () -> non_neg_integer(). -get_glyph_ids_field () -> #rst_char.glyph_ids. --spec get_glyph_board_id_field () -> non_neg_integer(). -get_glyph_board_id_field () -> #rst_char.glyph_board_id. - --spec decode (map()) -> type(). -decode (JSONReqMap) -> - Name = maps:get(<<"nam">>, JSONReqMap), - Portrait = maps:get(<<"prt">>, JSONReqMap), - ActiveWeapon = maps:get(<<"awp">>, JSONReqMap), - SecondaryWeapon = maps:get(<<"swp">>, JSONReqMap), - Armor = maps:get(<<"ar">>, JSONReqMap), - GlyphsList = maps:get(<<"gls">>, JSONReqMap), - GlyphBoard = maps:get(<<"gb">>, JSONReqMap), - - #rst_char - { - name = Name, - portrait_id = Portrait, - weapon_ids = {ActiveWeapon, SecondaryWeapon}, - armor_id = Armor, - glyph_ids = GlyphsList, - glyph_board_id = GlyphBoard - }. - --spec validate (shr_inventory:type(), type()) -> ok. -validate (Inventory, Character) -> - Glyphs = Character#rst_char.glyph_ids, - GlyphBoard = Character#rst_char.glyph_board_id, - - validate_name(Character#rst_char.name), - validate_portrait_id(Inventory, Character#rst_char.portrait_id), - validate_weapons(Inventory, Character#rst_char.weapon_ids), - validate_armor(Inventory, Character#rst_char.armor_id), - validate_glyphs(Inventory, Glyphs), - validate_glyph_board(Inventory, GlyphBoard), - validate_glyphs_on_board(Glyphs, GlyphBoard), - - ok. diff --git a/src/roster/struct/rst_roster.erl b/src/roster/struct/rst_roster.erl index 90b2f98..ec28db0 100644 --- a/src/roster/struct/rst_roster.erl +++ b/src/roster/struct/rst_roster.erl @@ -10,7 +10,8 @@ roster, { owner :: binary(), - characters :: orddict:orddict(non_neg_integer(), rst_character:type()) + characters :: + orddict:orddict(non_neg_integer(), shr_character:unresolved()) } ). @@ -30,7 +31,13 @@ get_character/2, set_characters/2, - set_character/3 + set_character/3, + + ataxia_set_characters/2, + ataxia_set_characters/3, + + ataxia_set_character/3, + ataxia_set_character/4 ] ). @@ -63,24 +70,50 @@ get_owner (Roster) -> Roster#roster.owner. ( type() ) - -> orddict:orddict(non_neg_integer(), rst_character:type()). + -> orddict:orddict(non_neg_integer(), shr_character:unresolved()). get_characters (Roster) -> Roster#roster.characters. --spec get_character (non_neg_integer(), type()) -> rst_character:type(). +-spec get_character (non_neg_integer(), type()) -> shr_character:unresolved(). get_character (IX, Roster) -> orddict:fetch(IX, Roster#roster.characters). -spec set_characters ( - orddict:orddict(non_neg_integer(), rst_character:type()), + orddict:orddict(non_neg_integer(), shr_character:unresolved()), type() ) -> type(). set_characters (Characters, Roster) -> Roster#roster{ characters = Characters }. +-spec ataxia_set_characters + ( + orddict:orddict(non_neg_integer(), shr_character:unresolved()), + type() + ) + -> {type(), ataxic:basic()}. +ataxia_set_characters (Characters, Roster) -> + ataxia_set_characters(Characters, ataxic:constant(Characters), Roster). + +-spec ataxia_set_characters + ( + orddict:orddict(non_neg_integer(), shr_character:unresolved()), + ataxic:basic(), + type() + ) + -> {type(), ataxic:basic()}. +ataxia_set_characters (Characters, CharactersAtaxiaUpdate, Roster) -> + { + set_characters(Characters, Roster), + ataxic:update_field + ( + get_characters_field(), + CharactersAtaxiaUpdate + ) + }. + -spec set_character ( non_neg_integer(), - rst_character:type(), + shr_character:unresolved(), type() ) -> type(). @@ -90,12 +123,40 @@ set_character (IX, Character, Roster) -> characters = orddict:store(IX, Character, Roster#roster.characters) }. +-spec ataxia_set_character + ( + non_neg_integer(), + shr_character:unresolved(), + type() + ) + -> {type(), ataxic:basic()}. +ataxia_set_character (IX, Character, Roster) -> + ataxia_set_character(IX, Character, ataxic:constant(Character), Roster). + +-spec ataxia_set_character + ( + non_neg_integer(), + shr_character:unresolved(), + ataxic:basic(), + type() + ) + -> {type(), ataxic:basic()}. +ataxia_set_character (IX, Character, CharacterAtaxiaUpdate, Roster) -> + { + ataxia_set_character(IX, Character, Roster), + ataxic:update_field + ( + get_characters_field(), + ataxic_sugar:update_orddict_element(IX, CharacterAtaxiaUpdate) + ) + }. + -spec get_characters_field () -> non_neg_integer(). get_characters_field () -> #roster.characters. -spec new (binary()) -> type(). new (Owner) -> - NewChar = rst_character:new(), + NewChar = shr_character:new(), #roster { owner = Owner, |