summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-04-26 15:05:44 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-04-26 15:05:44 +0200 |
commit | ec6eec260d6383ae948505c3d42b3055ae3dd94c (patch) | |
tree | 1d9ab2b09ab0a534fc6c09b62b940d9f1c7e139f /src | |
parent | 7d428bac2f9d62c5a0e704eb32be869c10fec72e (diff) |
Makes Dialyzer validate shared & battle.
Diffstat (limited to 'src')
22 files changed, 370 insertions, 512 deletions
diff --git a/src/battle/mechanic/btl_turn_actions_management.erl b/src/battle/mechanic/btl_turn_actions_management.erl index d3a84bd..d33fbad 100644 --- a/src/battle/mechanic/btl_turn_actions_management.erl +++ b/src/battle/mechanic/btl_turn_actions_management.erl @@ -39,12 +39,12 @@ deactivate_character (Update) -> -spec handle_action ( - btl_battle_action:type(), + btl_action:type(), btl_character_turn_update:type() ) -> btl_character_turn_update:type(). handle_action (BattleAction, Update) -> - case btl_battle_action:get_category(BattleAction) of + case btl_action:get_category(BattleAction) of move -> btl_turn_actions_move:handle(BattleAction, Update); switch_weapon -> btl_turn_actions_switch_weapon:handle(Update); attack -> btl_turn_actions_attack:handle(BattleAction, Update) @@ -78,6 +78,7 @@ update_timeline (Update) -> btl_character_turn_update:ataxia_set_battle ( UpdatedBattle, + false, BattleAtaxiaUpdate, S0Update ), diff --git a/src/battle/mechanic/btl_turn_progression.erl b/src/battle/mechanic/btl_turn_progression.erl index a6443b8..6286cc1 100644 --- a/src/battle/mechanic/btl_turn_progression.erl +++ b/src/battle/mechanic/btl_turn_progression.erl @@ -87,7 +87,8 @@ activate_next_players_characters (Battle, NextPlayer) -> ( IX, UpdatedCharacter, - CharacterAtaxicUpdate + CharacterAtaxicUpdate, + CurrentBattle ), {UpdatedBattle, [BattleAtaxicUpdate|CurrentBattleUpdates]}; @@ -107,35 +108,41 @@ activate_next_players_characters (Battle, NextPlayer) -> ) -> btl_character_turn_update:type(). activate_next_player (Update) -> - Data = btl_character_turn_update:get_data(Update), - Battle = btl_character_turn_data:get_battle(Data), + {S0Update, Battle} = btl_character_turn_update:get_battle(Update), - {S0Battle, DBQuery0} = prepare_player_turn_for_next_player(Battle), - {S1Battle, NextPlayer, DBQuery1} = reset_next_player_timeline(S0Battle), - {S2Battle, DBQuery2} = - activate_next_players_characters(S1Battle, NextPlayer), + {S0Battle, BattleAtaxiaUpdate0} = + prepare_player_turn_for_next_player(Battle), - S0Data = btl_character_turn_data:set_battle(S2Battle, Data), + {S1Battle, NextPlayer, BattleAtaxiaUpdate1} = + reset_next_player_timeline(S0Battle), - S0Update = - btl_character_turn_update:add_to_timeline + {S2Battle, BattleAtaxiaUpdate2} = + activate_next_players_characters(S1Battle, NextPlayer), + + S1Update = + btl_character_turn_update:ataxia_set_battle ( - btl_turn_result:new_player_turn_started + S2Battle, + true, + ataxic:sequence ( - btl_player:get_index(NextPlayer) + [ + BattleAtaxiaUpdate0, + BattleAtaxiaUpdate1, + BattleAtaxiaUpdate2 + ] ), - DBQuery0, - Update + S0Update ), - S1Update = btl_character_turn_update:set_data(S0Data, S0Update), - S2Update = - lists:foldl + btl_character_turn_update:add_to_timeline ( - fun btl_character_turn_update:add_to_db/2, - S1Update, - [DBQuery1,DBQuery2] + btl_turn_result:new_player_turn_started + ( + btl_player:get_index(NextPlayer) + ), + S1Update ), S2Update. @@ -144,17 +151,19 @@ activate_next_player (Update) -> ( btl_character_turn_update:type() ) - -> boolean(). + -> {boolean(), btl_character_turn_update:type()}. has_active_characters_remaining (Update) -> - Data = btl_character_turn_update:get_data(Update), - Battle = btl_character_turn_data:get_battle(Data), + {S0Update, Battle} = btl_character_turn_update:get_battle(Update), Characters = btl_battle:get_characters(Battle), - lists:any - ( - fun ({_IX, Char}) -> btl_character:get_is_active(Char) end, - orddict:to_list(Characters) - ). + { + lists:any + ( + fun ({_IX, Char}) -> btl_character:get_is_active(Char) end, + orddict:to_list(Characters) + ), + S0Update + }. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -166,6 +175,6 @@ has_active_characters_remaining (Update) -> -> btl_character_turn_update:type(). handle (Update) -> case has_active_characters_remaining(Update) of - false -> activate_next_player(Update); - _ -> Update + {false, S0Update} -> activate_next_player(S0Update); + {true, S0Update} -> S0Update end. diff --git a/src/battle/mechanic/btl_victory_progression.erl b/src/battle/mechanic/btl_victory_progression.erl index f50718a..ab8a351 100644 --- a/src/battle/mechanic/btl_victory_progression.erl +++ b/src/battle/mechanic/btl_victory_progression.erl @@ -9,7 +9,7 @@ -export ( [ - handle_character_lost_health/3 + handle_character_loss/2 ] ). @@ -90,37 +90,43 @@ mark_player_as_inactive (PlayerIX, Battle) -> ) -> btl_character_turn_update:type(). handle_player_defeat (PlayerIX, Update) -> - Data = btl_character_turn_update:get_data(Update), - Battle = btl_character_turn_data:get_battle(Data), + {S0Update, Battle} = btl_character_turn_update:get_battle(Update), {S0Battle, BattleAtaxicUpdate0} = mark_characters_of_player_as_defeated(PlayerIX, Battle), {S1Battle, BattleAtaxicUpdate1} = mark_player_as_inactive(PlayerIX, S0Battle), - UpdatedData = btl_character_turn_data:set_battle(S1Battle, Data), - S0Update = btl_character_turn_update:set_data(UpdatedData, Update), - S1Update = + btl_character_turn_update:ataxia_set_battle + ( + S1Battle, + true, + ataxic:sequence([BattleAtaxicUpdate0, BattleAtaxicUpdate1]), + S0Update + ), + + S2Update = btl_character_turn_update:add_to_timeline ( btl_turn_result:new_player_lost(PlayerIX), - ataxia:sequence([BattleAtaxicUpdate0, BattleAtaxicUpdate1]), - S0Update + S1Update ), - S1Update. + S2Update. --spec actually_handle_character_lost_health + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec handle_character_loss ( - non_neg_integer(), + btl_character:either(), btl_character_turn_update:type() ) -> btl_character_turn_update:type(). -actually_handle_character_lost_health (CharIX, Update) -> - Data = btl_character_turn_update:get_data(Update), - Battle = btl_character_turn_data:get_battle(Data), - Character = btl_battle:get_character(CharIX, Battle), +handle_character_loss (Character, Update) -> + {S0Update, Battle} = btl_character_turn_update:get_battle(Update), Characters = btl_battle:get_characters(Battle), CharacterPlayerIX = btl_character:get_player_index(Character), @@ -133,10 +139,9 @@ actually_handle_character_lost_health (CharIX, Update) -> StillHasAliveChar = lists:any ( - fun ({IX, Char}) -> + fun ({_IX, Char}) -> ( (CharacterPlayerIX == btl_character:get_player_index(Char)) - and (IX /= CharIX) and btl_character:get_is_alive(Char) ) end, @@ -144,53 +149,28 @@ actually_handle_character_lost_health (CharIX, Update) -> ), case StillHasAliveChar of - true -> Update; - _ -> handle_player_defeat(CharacterPlayerIX, Update) + true -> S0Update; + _ -> handle_player_defeat(CharacterPlayerIX, S0Update) end; - commander -> handle_player_defeat(CharacterPlayerIX, Update); + commander -> handle_player_defeat(CharacterPlayerIX, S0Update); target -> StillHasAliveTargetChar = lists:any ( - fun ({IX, Char}) -> + fun ({_IX, Char}) -> ( (CharacterPlayerIX == btl_character:get_player_index(Char)) - and (IX /= CharIX) and btl_character:get_is_alive(Char) - and (blt_character:get_rank(Char) == target) + and (btl_character:get_rank(Char) == target) ) end, orddict:to_list(Characters) ), case StillHasAliveTargetChar of - true -> Update; - _ -> handle_player_defeat(CharacterPlayerIX, Update) + true -> S0Update; + _ -> handle_player_defeat(CharacterPlayerIX, S0Update) end end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec handle_character_lost_health - ( - non_neg_integer(), - integer(), - btl_character_turn_update:type() - ) - -> btl_character_turn_update:type(). -handle_character_lost_health (_, Health, Update) when (Health > 0) -> Update; -handle_character_lost_health (CharIX, _Health, Update) -> - Data = btl_character_turn_update:get_data(Update), - S1Data = btl_character_turn_data:clean_battle(Data), - S1Update = btl_character_turn_update:set_data(S1Data, Update), - - S2Update = actually_handle_character_lost_health(CharIX, S1Update), - - S2Data = btl_character_turn_update:get_data(S2Update), - S3Data = btl_character_turn_data:refresh_character(S2Data), - S3Update = btl_character_turn_update:set_data(S3Data, S2Update), - - S3Update. diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl index b59efb7..e36c7e3 100644 --- a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl +++ b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl @@ -19,9 +19,9 @@ -spec handle_attack_sequence ( - btl_character_current_data:type(), + btl_character:type(), non_neg_integer(), - btl_character_current_data:type(), + btl_character:type(), non_neg_integer(), integer(), integer(), @@ -38,9 +38,9 @@ }. handle_attack_sequence ( - _CharacterCurrentData, + _Character, CharacterCurrentHealth, - _TargetCurrentData, + _TargetCharacter, TargetCurrentHealth, AttackerLuck, DefenderLuck, @@ -62,9 +62,9 @@ when }; handle_attack_sequence ( - CharacterCurrentData, + Character, AttackerHealth, - TargetCurrentData, + TargetCharacter, DefenderHealth, AttackerLuck, DefenderLuck, @@ -75,8 +75,8 @@ handle_attack_sequence btl_attack:get_description_of ( NextAttack, - CharacterCurrentData, - TargetCurrentData, + btl_character:get_base_character(Character), + btl_character:get_base_character(TargetCharacter), AttackerLuck, DefenderLuck ), @@ -105,9 +105,9 @@ handle_attack_sequence handle_attack_sequence ( - CharacterCurrentData, + Character, NewAttackerHealth, - TargetCurrentData, + TargetCharacter, NewDefenderHealth, NewAttackerLuck, NewDefenderLuck, @@ -129,11 +129,17 @@ get_attack_sequence (Character, TargetCharacter) -> btl_character:get_location(TargetCharacter) ), - {AttackingWeaponID, _} = btl_character:get_weapon_ids(Character), - {DefendingWeaponID, _} = btl_character:get_weapon_ids(TargetCharacter), + AttackingWeapon = + shr_character:get_active_weapon + ( + btl_character:get_base_character(Character) + ), - AttackingWeapon = shr_weapon:from_id(AttackingWeaponID), - DefendingWeapon = shr_weapon:from_id(DefendingWeaponID), + DefendingWeapon = + shr_character:get_active_weapon + ( + btl_character:get_base_character(TargetCharacter) + ), btl_attack:get_sequence(Range, AttackingWeapon, DefendingWeapon). @@ -142,31 +148,49 @@ get_attack_sequence (Character, TargetCharacter) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec handle ( - btl_battle_action:type(), + btl_action:type(), btl_character_turn_update:type() ) -> btl_character_turn_update:type(). handle (BattleAction, Update) -> - Data = btl_character_turn_update:get_data(Update), - Battle = btl_character_turn_data:get_battle(Data), - Character = btl_character_turn_data:get_character(Data), - CharacterIX = btl_character_turn_data:get_character_ix(Data), - CharacterCurrentData = - btl_character_turn_data:get_character_current_data(Data), + {S0Update, Battle} = btl_character_turn_update:get_battle(Update), + {S1Update, Character} = btl_character_turn_update:get_character(S0Update), + AttackingPlayerIX = btl_character:get_player_index(Character), AttackingPlayer = btl_battle:get_player(AttackingPlayerIX, Battle), AttackingPlayerLuck = btl_player:get_luck(AttackingPlayer), + TargetIX = btl_action:get_target_ix(BattleAction), Map = btl_battle:get_map(Battle), - TargetIX = btl_battle_action:get_target_ix(BattleAction), - TargetCharacter = btl_battle:get_character(TargetIX, Battle), - TargetCurrentData = btl_character_current_data:new(TargetCharacter, Map), + TargetCharacterRef = btl_battle:get_character(TargetIX, Battle), + TargetCharacter = + btl_character:resolve + ( + shr_tile:get_omnimods + ( + shr_tile:from_id + ( + shr_tile_instance:get_tile_id + ( + shr_map:get_tile_instance + ( + btl_character:get_location(TargetCharacterRef), + Map + ) + ) + ) + ), + TargetCharacterRef + ), + DefendingPlayerIX = btl_character:get_player_index(TargetCharacter), DefendingPlayer = btl_battle:get_player(DefendingPlayerIX, Battle), DefendingPlayerLuck = btl_player:get_luck(DefendingPlayer), + true = btl_character:get_is_alive(TargetCharacter), + AttackSequence = get_attack_sequence(Character, TargetCharacter), { @@ -178,9 +202,9 @@ handle (BattleAction, Update) -> } = handle_attack_sequence ( - CharacterCurrentData, + Character, btl_character:get_current_health(Character), - TargetCurrentData, + TargetCharacter, btl_character:get_current_health(TargetCharacter), AttackingPlayerLuck, DefendingPlayerLuck, @@ -202,135 +226,114 @@ handle (BattleAction, Update) -> _ -> 0 end, - NextAttackingPlayer = - btl_player:set_luck(S0NewAttackerLuck, AttackingPlayer), + {UpdatedAttackingPlayer, AttackingPlayerAtaxiaUpdate} = + btl_player:ataxia_set_luck(S0NewAttackerLuck, AttackingPlayer), - NextDefendingPlayer = - btl_player:set_luck(S0NewDefenderLuck, DefendingPlayer), + {UpdatedDefendingPlayer, DefendingPlayerAtaxiaUpdate} = + btl_player:ataxia_set_luck(S0NewDefenderLuck, DefendingPlayer), - UpdatedCharacter = - btl_character:set_current_health(RemainingAttackerHealth, Character), + {UpdatedCharacter, CharacterAtaxiaUpdate} = + btl_character:ataxia_set_current_health + ( + RemainingAttackerHealth, + Character + ), - UpdatedBattle = - btl_battle:set_player + {UpdatedTargetCharacterRef, TargetCharacterRefAtaxiaUpdate} = + btl_character:ataxia_set_current_health ( - DefendingPlayerIX, - NextDefendingPlayer, - btl_battle:set_player - ( - AttackingPlayerIX, - NextAttackingPlayer, - btl_battle:set_character - ( - TargetIX, - btl_character:set_current_health - ( - RemainingDefenderHealth, - TargetCharacter - ), - Battle - ) - ) + RemainingDefenderHealth, + TargetCharacterRef ), - S0Data = btl_character_turn_data:set_battle(UpdatedBattle, Data), - S1Data = btl_character_turn_data:set_character(UpdatedCharacter, S0Data), + {S0Battle, BattleAtaxiaUpdate0} = + btl_battle:ataxia_set_player + ( + AttackingPlayerIX, + UpdatedAttackingPlayer, + AttackingPlayerAtaxiaUpdate, + Battle + ), - TimelineItem = - btl_turn_result:new_character_attacked + {S1Battle, BattleAtaxiaUpdate1} = + btl_battle:ataxia_set_player ( - CharacterIX, - TargetIX, - AttackEffects, - S0NewAttackerLuck, - S0NewDefenderLuck + DefendingPlayerIX, + UpdatedDefendingPlayer, + DefendingPlayerAtaxiaUpdate, + S0Battle ), - DBQuery0 = - ataxic:update_field + {S2Battle, BattleAtaxiaUpdate2} = + btl_battle:ataxia_set_character ( - btl_battle:get_characters_field(), - ataxic_sugar:update_orddict_element - ( - TargetIX, - ataxic:update_field - ( - btl_character:get_current_health_field(), - ataxic:constant(RemainingDefenderHealth) - ) - ) + TargetIX, + UpdatedTargetCharacterRef, + TargetCharacterRefAtaxiaUpdate, + S1Battle ), - DBQuery1 = - ataxic:update_field + % Potential danger ahead: we're going to update both the 'character' and + % 'battle' members of a btl_character_turn_update. + % 'S1Update' is sure to have both up to date (as it's the result of 'get' + % requests for both) and there is no risk of the 'battle' update influencing + % 'character', making what follows safe. + + S2Update = + btl_character_turn_update:ataxia_set_battle ( - btl_battle:get_characters_field(), - ataxic_sugar:update_orddict_element + S2Battle, + false, + ataxic:optimize ( - CharacterIX, - ataxic:update_field + ataxic:sequence ( - btl_character:get_current_health_field(), - ataxic:constant(RemainingAttackerHealth) + [ + BattleAtaxiaUpdate0, + BattleAtaxiaUpdate1, + BattleAtaxiaUpdate2 + ] ) - ) + ), + S1Update ), - DBQuery2 = - ataxic:update_field + S3Update = + btl_character_turn_update:ataxia_set_character ( - btl_battle:get_players_field(), - ataxic:sequence - ( - [ - ataxic_sugar:update_orddict_element - ( - DefendingPlayerIX, - ataxic:update_field - ( - btl_player:get_luck_field(), - ataxic:constant(S0NewDefenderLuck) - ) - ), - ataxic_sugar:update_orddict_element - ( - AttackingPlayerIX, - ataxic:update_field - ( - btl_player:get_luck_field(), - ataxic:constant(S0NewAttackerLuck) - ) - ) - ] - ) + UpdatedCharacter, + CharacterAtaxiaUpdate, + S2Update ), - S0Update = - btl_character_turn_update:add_to_timeline + TimelineItem = + btl_turn_result:new_character_attacked ( - TimelineItem, - DBQuery0, - Update + btl_character_turn_update:get_character_ix(S3Update), + TargetIX, + AttackEffects, + S0NewAttackerLuck, + S0NewDefenderLuck ), - S1Update = btl_character_turn_update:add_to_db(DBQuery1, S0Update), - S2Update = btl_character_turn_update:add_to_db(DBQuery2, S1Update), - S3Update = btl_character_turn_update:set_data(S1Data, S2Update), - - S4Update = - btl_victory:handle_character_lost_health - ( - CharacterIX, - RemainingAttackerHealth, - S3Update - ), + S4Update = btl_character_turn_update:add_to_timeline(TimelineItem, S3Update), S5Update = - btl_victory:handle_character_lost_health - ( - TargetIX, - RemainingDefenderHealth, - S4Update - ), + case (RemainingAttackerHealth > 0) of + true -> S4Update; + false -> + btl_victory_progression:handle_character_loss(Character, S4Update) + end, + + S6Update = + case (RemainingAttackerHealth > 0) of + true -> S5Update; + false -> + btl_victory_progression:handle_character_loss + ( + TargetCharacterRef, + S5Update + ) + end, - S5Update. + S6Update. diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_move.erl b/src/battle/mechanic/turn_action/btl_turn_actions_move.erl index db46ef0..da62e8c 100644 --- a/src/battle/mechanic/turn_action/btl_turn_actions_move.erl +++ b/src/battle/mechanic/turn_action/btl_turn_actions_move.erl @@ -60,14 +60,19 @@ cross (Map, ForbiddenLocations, Path, Location) -> -spec get_path_cost_and_destination ( - btl_character_turn_data:type(), + btl_character_turn_update:type(), list(shr_direction:type()) ) - -> {non_neg_integer(), shr_location:type()}. -get_path_cost_and_destination (Data, Path) -> - Character = btl_character_turn_data:get_character(Data), - CharacterIX = btl_character_turn_data:get_character_ix(Data), - Battle = btl_character_turn_data:get_battle(Data), + -> + { + non_neg_integer(), + shr_location:type(), + btl_character_turn_update:type() + }. +get_path_cost_and_destination (Update, Path) -> + {S0Update, Character} = btl_character_turn_update:get_character(Update), + {S1Update, Battle} = btl_character_turn_update:get_battle(S0Update), + CharacterIX = btl_character_turn_update:get_character_ix(S1Update), Map = btl_battle:get_map(Battle), ForbiddenLocations = @@ -95,18 +100,23 @@ get_path_cost_and_destination (Data, Path) -> btl_character:get_location(Character) ), - {Cost, NewLocation}. + {Cost, NewLocation, S1Update}. -spec assert_character_can_move ( - btl_character_turn_data:type(), + btl_character:type(), non_neg_integer() ) -> 'ok'. -assert_character_can_move (Data, Cost) -> - CharacterData = btl_character_turn_data:get_character_current_data(Data), - CharacterStats= btl_character_current_data:get_statistics(CharacterData), - CharacterMovementPoints = shr_statistics:get_movement_points(CharacterStats), +assert_character_can_move (Char, Cost) -> + CharacterMovementPoints = + shr_statistics:get_movement_points + ( + shr_character:get_statistics + ( + btl_character:get_base_character(Char) + ) + ), true = (Cost =< CharacterMovementPoints), @@ -114,54 +124,47 @@ assert_character_can_move (Data, Cost) -> -spec commit_move ( - btl_character_current_data:type(), + btl_character:type(), btl_character_turn_update:type(), list(shr_direction:type()), shr_location:type() ) -> btl_character_turn_update:type(). -commit_move (PreviousCurrentData, Update, Path, NewLocation) -> - Data = btl_character_turn_update:get_data(Update), - Character = btl_character_turn_data:get_character(Data), - CharacterIX = btl_character_turn_data:get_character_ix(Data), +commit_move (Character, Update, Path, NewLocation) -> + {S0Update, Battle} = btl_character_turn_update:get_battle(Update), + Map = btl_battle:get_map(Battle), + TileOmnimods = + shr_tile:get_omnimods + ( + shr_tile:from_id + ( + shr_tile_instance:get_tile_id + ( + shr_map:get_tile_instance(NewLocation, Map) + ) + ) + ), - UpdatedCharacter = btl_character:set_location(NewLocation, Character), - S0Data = btl_character_turn_data:set_character(UpdatedCharacter, Data), - S1Data = btl_character_turn_data:refresh_character_current_data(S0Data), + {UpdatedCharacter, CharacterAtaxiaUpdate} = + btl_character:ataxia_set_location(NewLocation, TileOmnimods, Character), - S0Update = btl_character_turn_update:set_data(S1Data, Update), S1Update = - btl_turn_actions_stats_change:handle_max_health_changes + btl_character_turn_update:ataxia_set_character ( - PreviousCurrentData, + UpdatedCharacter, + CharacterAtaxiaUpdate, S0Update ), TimelineItem = - btl_turn_result:new_character_moved(CharacterIX, Path, NewLocation), - - DBQuery = - ataxic:update_field + btl_turn_result:new_character_moved ( - btl_battle:get_characters_field(), - ataxic_sugar:update_orddict_element - ( - CharacterIX, - ataxic:update_field - ( - btl_character:get_location_field(), - ataxic:constant(NewLocation) - ) - ) + btl_character_turn_update:get_character_ix(S1Update), + Path, + NewLocation ), - S2Update = - btl_character_turn_update:add_to_timeline - ( - TimelineItem, - DBQuery, - S1Update - ), + S2Update = btl_character_turn_update:add_to_timeline(TimelineItem, S1Update), S2Update. @@ -170,17 +173,17 @@ commit_move (PreviousCurrentData, Update, Path, NewLocation) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec handle ( - btl_battle_action:type(), + btl_action:type(), btl_character_turn_update:type() ) -> btl_character_turn_update:type(). handle (BattleAction, Update) -> - Data = btl_character_turn_update:get_data(Update), - CharacterCurrentData = - btl_character_turn_data:get_character_current_data(Data), - Path = btl_battle_action:get_path(BattleAction), + {S0Update, Character} = btl_character_turn_update:get_character(Update), + Path = btl_action:get_path(BattleAction), + + {PathCost, NewLocation, S1Update} = + get_path_cost_and_destination(S0Update, Path), - {PathCost, NewLocation} = get_path_cost_and_destination(Data, Path), - assert_character_can_move(Data, PathCost), + assert_character_can_move(Character, PathCost), - commit_move(CharacterCurrentData, Update, Path, NewLocation). + commit_move(Character, S1Update, Path, NewLocation). diff --git a/src/battle/query/btl_character_turn.erl b/src/battle/query/btl_character_turn.erl index 455dd13..2048391 100644 --- a/src/battle/query/btl_character_turn.erl +++ b/src/battle/query/btl_character_turn.erl @@ -183,7 +183,7 @@ handle (Query) -> S0Update = fetch_data(Request), assert_user_permissions(S0Update, Request), - S1Update = btl_turn_actions:apply_requested_actions(S0Update, Request), + S1Update = btl_turn_actions_management:handle(S0Update, Request), commit_update(S1Update, Request), shr_security:unlock_queries(PlayerID), diff --git a/src/battle/query/btl_load.erl b/src/battle/query/btl_load.erl index 583cd4b..456f468 100644 --- a/src/battle/query/btl_load.erl +++ b/src/battle/query/btl_load.erl @@ -83,7 +83,7 @@ generate_reply (QueryState, Input) -> PlayerID = Input#input.player_id, PUser = ataxia_security:user_from_id(PlayerID), Battle = QueryState#query_state.battle, - RelevantInventory = btl_battle:get_relevant_inventory(Battle), + RelevantInventory = btl_battle:get_related_inventory(Battle), Players = btl_battle:get_players(Battle), {value, {PlayerIX, _Player}} = @@ -133,7 +133,7 @@ generate_reply (QueryState, Input) -> lists:map ( fun (PortraitID) -> - btl_add_portrait:generate(shr_portrait:from_id(PortraitID)) + shr_add_portrait:generate(shr_portrait:from_id(PortraitID)) end, ordsets:to_list(shr_inventory:get_portraits(RelevantInventory)) ), @@ -142,7 +142,7 @@ generate_reply (QueryState, Input) -> lists:map ( fun (WeaponID) -> - btl_add_weapon:generate(shr_weapon:from_id(WeaponID)) + shr_add_weapon:generate(shr_weapon:from_id(WeaponID)) end, ordsets:to_list(shr_inventory:get_weapons(RelevantInventory)) ), @@ -151,7 +151,7 @@ generate_reply (QueryState, Input) -> lists:map ( fun (ArmorID) -> - btl_add_armor:generate(shr_armor:from_id(ArmorID)) + shr_add_armor:generate(shr_armor:from_id(ArmorID)) end, ordsets:to_list(shr_inventory:get_armors(RelevantInventory)) ), @@ -160,7 +160,7 @@ generate_reply (QueryState, Input) -> lists:map ( fun (GlyphID) -> - btl_add_glyph:generate(shr_glyph:from_id(GlyphID)) + shr_add_glyph:generate(shr_glyph:from_id(GlyphID)) end, ordsets:to_list(shr_inventory:get_glyphs(RelevantInventory)) ), @@ -169,7 +169,7 @@ generate_reply (QueryState, Input) -> lists:map ( fun (GlyphBoardID) -> - btl_add_glyph_board:generate(shr_glyph_board:from_id(GlyphBoardID)) + shr_add_glyph_board:generate(shr_glyph_board:from_id(GlyphBoardID)) end, ordsets:to_list(shr_inventory:get_glyph_boards(RelevantInventory)) ), diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 8ee0169..cca53b3 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -116,7 +116,7 @@ handle_max_health_change (OldBaseChar, NewBaseChar, OldHealth) -> shr_statistics:get_health(shr_character:get_statistics(NewBaseChar)), case (OldMaxHealth == NewMaxHealth) of - true -> {false, OldMaxHealth, OldHealth}; + true -> {false, OldHealth}; false -> OldHealthRatio = (OldHealth / OldMaxHealth), NewHealth = @@ -207,7 +207,8 @@ ataxia_set_rank (Rank, Char) -> -> type(). set_location (Location, LocOmnimods, Char) -> CurrentBaseCharacter = Char#btl_char.base, - UpdatedBaseCharacter = shr_character:set_extra_omnimods(LocOmnimods), + UpdatedBaseCharacter = + shr_character:set_extra_omnimods(LocOmnimods, CurrentBaseCharacter), case handle_max_health_change @@ -217,7 +218,7 @@ set_location (Location, LocOmnimods, Char) -> Char#btl_char.current_health ) of - {false, _, _} -> + {false, _} -> Char#btl_char { location = Location, @@ -253,7 +254,7 @@ ataxia_set_location (Location, LocOmnimods, Char) -> { UpdatedChar, - case (CurrentHealth == UpdatedChar) of + case (CurrentHealth == UpdatedCharHealth) of true -> LocationUpdate; false -> ataxic:sequence @@ -344,7 +345,7 @@ set_base_character (NewBaseCharacter, Char) -> Char#btl_char.current_health ) of - {false, _, _} -> + {false, _} -> Char#btl_char { base = NewBaseCharacter @@ -378,7 +379,7 @@ ataxia_set_base_character (NewBaseCharacter, BaseCharacterAtaxicUpdate, Char) -> { UpdatedChar, - case (CurrentHealth == UpdatedChar) of + case (CurrentHealth == UpdatedCharHealth) of true -> BattleCharacterAtaxicUpdate; false -> ataxic:sequence diff --git a/src/battle/struct/btl_character_turn_request.erl b/src/battle/struct/btl_character_turn_request.erl index faf8d07..7246ca7 100644 --- a/src/battle/struct/btl_character_turn_request.erl +++ b/src/battle/struct/btl_character_turn_request.erl @@ -20,7 +20,7 @@ session_token :: binary(), battle_id :: binary(), character_ix :: non_neg_integer(), - actions :: list(btl_battle_action:type()) + actions :: list(btl_action:type()) } ). @@ -52,12 +52,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec decode_actions (map()) -> list(btl_battle_action:type()). +-spec decode_actions (map()) -> list(btl_action:type()). decode_actions (Act) -> S0Result = [], S1Result = case - btl_battle_action:maybe_decode_move(maps:get(?ACTIONS_MOVE_FIELD, Act)) + btl_action:maybe_decode_move(maps:get(?ACTIONS_MOVE_FIELD, Act)) of [] -> S0Result; [Move] -> [Move|S0Result] @@ -65,7 +65,7 @@ decode_actions (Act) -> S2Result = case - btl_battle_action:maybe_decode_attack + btl_action:maybe_decode_attack ( maps:get(?ACTIONS_ATTACK_FIELD, Act) ) @@ -76,7 +76,7 @@ decode_actions (Act) -> S3Result = case - btl_battle_action:maybe_decode_weapon_switch + btl_action:maybe_decode_weapon_switch ( maps:get(?ACTIONS_WEAPON_SWITCH_FIELD, Act) ) @@ -117,5 +117,5 @@ get_battle_id (Request) -> Request#type.battle_id. -spec get_character_ix (type()) -> non_neg_integer(). get_character_ix (Request) -> Request#type.character_ix. --spec get_actions (type()) -> list(btl_battle_action:type()). +-spec get_actions (type()) -> list(btl_action:type()). get_actions (Request) -> Request#type.actions. diff --git a/src/battle/struct/btl_character_turn_update.erl b/src/battle/struct/btl_character_turn_update.erl index 601f314..9f2c30a 100644 --- a/src/battle/struct/btl_character_turn_update.erl +++ b/src/battle/struct/btl_character_turn_update.erl @@ -56,10 +56,10 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec resolve_character_at ( - btl_battle:type(), - non_neg_integer() - ) -> btl_charater:type(). -resolve_character_at (Battle, CharacterIX) -> + non_neg_integer(), + btl_battle:type() + ) -> btl_character:type(). +resolve_character_at (CharacterIX, Battle) -> CharacterRef = btl_battle:get_character(CharacterIX, Battle), Location = btl_character:get_location(CharacterRef), Map = btl_battle:get_map(Battle), @@ -78,7 +78,6 @@ resolve_character_at (Battle, CharacterIX) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec new (btl_battle:type(), non_neg_integer()) -> type(). new (Battle, CharacterIX) -> - #type { character_is_outdated = false, @@ -87,7 +86,7 @@ new (Battle, CharacterIX) -> battle = Battle, reversed_battle_updates = [], - character = resolve_character_at(Battle, CharacterIX), + character = resolve_character_at(CharacterIX, Battle), reversed_character_updates = [], character_ix = CharacterIX, @@ -104,7 +103,7 @@ get_battle (Data) -> btl_battle:ataxia_set_character ( Data#type.character_ix, - Data#type.character, + btl_character:to_unresolved(Data#type.character), ataxic:sequence ( lists:reverse(Data#type.reversed_character_updates) @@ -153,9 +152,12 @@ get_character_ix (Data) -> Data#type.character_ix. -spec set_battle (btl_battle:type(), boolean(), type()) -> type(). set_battle (Battle, CouldAffectCharacter, Data) -> + false = (Data#type.battle_is_outdated and CouldAffectCharacter), + Data#type { - character_is_outdated = CouldAffectCharacter, + character_is_outdated = + (Data#type.character_is_outdated or CouldAffectCharacter), battle = Battle }. @@ -168,15 +170,20 @@ set_battle (Battle, CouldAffectCharacter, Data) -> ) -> type(). ataxia_set_battle (Battle, CouldAffectCharacter, BattleUpdate, Data) -> + false = (Data#type.battle_is_outdated and CouldAffectCharacter), + Data#type { - character_is_outdated = CouldAffectCharacter, + character_is_outdated = + (Data#type.character_is_outdated or CouldAffectCharacter), battle = Battle, reversed_battle_updates = [BattleUpdate|Data#type.reversed_battle_updates] }. -spec set_character (btl_character:type(), type()) -> type(). set_character (Character, Data) -> + false = Data#type.character_is_outdated, + Data#type { battle_is_outdated = true, @@ -186,11 +193,13 @@ set_character (Character, Data) -> -spec ataxia_set_character ( btl_character:type(), - ataxia:basic(), + ataxic:basic(), type() ) -> type(). ataxia_set_character (Character, CharacterUpdate, Data) -> + false = Data#type.character_is_outdated, + Data#type { battle_is_outdated = true, diff --git a/src/battle/struct/btl_pending_battle.erl b/src/battle/struct/btl_pending_battle.erl index c82d4ae..0e46a24 100644 --- a/src/battle/struct/btl_pending_battle.erl +++ b/src/battle/struct/btl_pending_battle.erl @@ -187,7 +187,7 @@ push_player_summary_ix (Val, PBattle) -> non_neg_integer(), type() ) - -> {type(), ataxic:constant()}. + -> {type(), ataxic:basic()}. ataxia_push_player_summary_ix (Val, PBattle) -> { PBattle#pending_battle @@ -209,7 +209,7 @@ set_player_ids (Val, PBattle) -> PBattle#pending_battle{ player_ids = Val }. list(shr_player:id()), type() ) - -> {type(), ataxia:basic()}. + -> {type(), ataxic:basic()}. ataxia_set_player_ids (Val, PBattle) -> { PBattle#pending_battle{ player_ids = Val }, @@ -232,7 +232,7 @@ push_player_id (Val, PBattle) -> shr_player:id(), type() ) - -> {type(), ataxia:basic()}. + -> {type(), ataxic:basic()}. ataxia_push_player_id (Val, PBattle) -> { PBattle#pending_battle diff --git a/src/battle/struct/btl_player.erl b/src/battle/struct/btl_player.erl index 3669e00..604efca 100644 --- a/src/battle/struct/btl_player.erl +++ b/src/battle/struct/btl_player.erl @@ -98,7 +98,7 @@ get_is_active (Player) -> Player#player.is_active. -spec set_is_active (boolean(), type()) -> type(). set_is_active (Val, Player) -> Player#player{ is_active = Val }. --spec ataxia_set_is_active (boolean(), type()) -> {type(), ataxia:basic()}. +-spec ataxia_set_is_active (boolean(), type()) -> {type(), ataxic:basic()}. ataxia_set_is_active (Val, Player) -> { Player#player{ is_active = Val }, diff --git a/src/shared/reply/shr_set_inventory.erl b/src/shared/reply/shr_set_inventory.erl index 61ba336..415beca 100644 --- a/src/shared/reply/shr_set_inventory.erl +++ b/src/shared/reply/shr_set_inventory.erl @@ -23,10 +23,10 @@ generate (Inventory) -> { [ {<<"msg">>, <<"set_inventory">>}, - {<<"pts">>, encode_set(shr_inventory:get_portrait_ids(Inventory))}, - {<<"gls">>, encode_set(shr_inventory:get_glyph_ids(Inventory))}, - {<<"gbs">>, encode_set(shr_inventory:get_glyph_board_ids(Inventory))}, - {<<"wps">>, encode_set(shr_inventory:get_weapon_ids(Inventory))}, - {<<"ars">>, encode_set(shr_inventory:get_armor_ids(Inventory))} + {<<"pts">>, encode_set(shr_inventory:get_portraits(Inventory))}, + {<<"gls">>, encode_set(shr_inventory:get_glyphs(Inventory))}, + {<<"gbs">>, encode_set(shr_inventory:get_glyph_boards(Inventory))}, + {<<"wps">>, encode_set(shr_inventory:get_weapons(Inventory))}, + {<<"ars">>, encode_set(shr_inventory:get_armors(Inventory))} ] }. diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl index cbd4381..a931444 100644 --- a/src/shared/struct/inventory/shr_equipment.erl +++ b/src/shared/struct/inventory/shr_equipment.erl @@ -40,7 +40,7 @@ -opaque unresolved() :: #shr_eq_ref{}. -type either() :: (type() | unresolved()). --export_type([type/0, unresolved/0]). +-export_type([type/0, unresolved/0, either/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -84,7 +84,6 @@ 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, @@ -299,14 +298,12 @@ set_glyphs (V, Eq) when is_record(Eq, shr_eq_ref) -> (list(shr_glyph:type()), type()) -> {type(), ataxic:basic()}; (list(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)) - ) - }. + ataxia_set_glyphs + ( + V, + ataxic:constant(lists:map(fun shr_glyph:get_id/1, V)), + Eq + ). -spec ataxia_set_glyphs ( @@ -448,14 +445,7 @@ set_glyph_ids (V, Eq) when is_record(Eq, shr_eq) -> (list(shr_glyph:id()), type()) -> {type(), ataxic:basic()}; (list(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) - ) - }. + ataxia_set_glyph_ids(V, ataxic:constant(V), Eq). -spec ataxia_set_glyph_ids ( diff --git a/src/shared/struct/inventory/shr_glyph.erl.m4 b/src/shared/struct/inventory/shr_glyph.erl.m4 index 0ce4c47..a451cc0 100644 --- a/src/shared/struct/inventory/shr_glyph.erl.m4 +++ b/src/shared/struct/inventory/shr_glyph.erl.m4 @@ -35,7 +35,7 @@ [ get_id/1, get_name/1, - get_omnimods/1, + get_omnimods/1 ] ). diff --git a/src/shared/struct/inventory/shr_glyph_board.erl.m4 b/src/shared/struct/inventory/shr_glyph_board.erl.m4 index c2128a9..3324997 100644 --- a/src/shared/struct/inventory/shr_glyph_board.erl.m4 +++ b/src/shared/struct/inventory/shr_glyph_board.erl.m4 @@ -58,7 +58,7 @@ list(shr_glyph:type()), list(integer()) ) - -> ({'ok', shr_omnimods:type()} | 'error'). + -> ('error' | {'ok', shr_omnimods:type()}). get_omnimods_with_glyphs_internals (Omnimods, [], []) -> {ok, Omnimods}; get_omnimods_with_glyphs_internals (_Omnimods, [], _) -> @@ -102,12 +102,15 @@ default () -> from_id(<<"0">>). list(shr_glyph:type()), type() ) - -> ({'ok', shr_omnimods:type()} | 'error'). + -> shr_omnimods:type(). get_omnimods_with_glyphs (Glyphs, GlyphBoard) -> BoardOmnimods = GlyphBoard#glyph_board.omnimods, BoardSlots = GlyphBoard#glyph_board.slots, - get_omnimods_with_glyphs_internals(BoardOmnimods, Glyphs, BoardSlots). + {ok, Omnimods} = + get_omnimods_with_glyphs_internals(BoardOmnimods, Glyphs, BoardSlots), + + Omnimods. -spec default_id () -> id(). default_id () -> <<"0">>. diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl index 4ea3e7b..884c213 100644 --- a/src/shared/struct/inventory/shr_inventory.erl +++ b/src/shared/struct/inventory/shr_inventory.erl @@ -22,8 +22,9 @@ ). -opaque type() :: #inventory{}. +-type id() :: ataxia_id:type(). --export_type([type/0]). +-export_type([type/0, id/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -95,19 +96,27 @@ get_glyphs (Inv) -> Inv#inventory.glyphs. -spec add_weapon (shr_weapon:id(), type()) -> type(). -add_weapon (V, Inv) -> Inv#inventory{ weapons = V }. +add_weapon (V, Inv) -> + Inv#inventory{ weapons = ordsets:add_element(V, Inv#inventory.weapons) }. -spec add_armor (shr_armor:id(), type()) -> type(). -add_armor (V, Inv) -> Inv#inventory{ armors = V }. +add_armor (V, Inv) -> + Inv#inventory{ armors = ordsets:add_element(V, Inv#inventory.armors) }. -spec add_portrait (shr_portrait:id(), type()) -> type(). -add_portrait (V, Inv) -> Inv#inventory{ portraits = V }. +add_portrait (V, Inv) -> + Inv#inventory{ portraits = ordsets:add_element(V, Inv#inventory.portraits) }. -spec add_glyph_board (shr_glyph_board:id(), type()) -> type(). -add_glyph_board (V, Inv) -> Inv#inventory{ glyph_boards = V }. +add_glyph_board (V, Inv) -> + Inv#inventory + { + glyph_boards = ordsets:add_element(V, Inv#inventory.glyph_boards) + }. -spec add_glyph (shr_glyph:id(), type()) -> type(). -add_glyph (V, Inv) -> Inv#inventory{ glyphs = V }. +add_glyph (V, Inv) -> + Inv#inventory{ glyphs = ordsets:add_element(V, Inv#inventory.glyphs) }. -spec ataxia_add_weapon @@ -115,12 +124,12 @@ add_glyph (V, Inv) -> Inv#inventory{ glyphs = V }. shr_weapon:id(), type() ) - -> {type(), list(ataxic:basic())}. + -> {type(), ataxic:basic()}. ataxia_add_weapon (V, Inv) -> CurrentWeapons = Inv#inventory.weapons, case ordsets:is_element(V, CurrentWeapons) of - true -> Inv; + true -> {Inv, ataxic:current_value()}; false -> { Inv#inventory{ weapons = ordsets:add_element(V, CurrentWeapons) }, @@ -142,12 +151,12 @@ ataxia_add_weapon (V, Inv) -> shr_armor:id(), type() ) - -> {type(), list(ataxic:basic())}. + -> {type(), ataxic:basic()}. ataxia_add_armor (V, Inv) -> CurrentArmors = Inv#inventory.armors, case ordsets:is_element(V, CurrentArmors) of - true -> Inv; + true -> {Inv, ataxic:current_value()}; false -> { Inv#inventory{ armors = ordsets:add_element(V, CurrentArmors) }, @@ -169,12 +178,12 @@ ataxia_add_armor (V, Inv) -> shr_portrait:id(), type() ) - -> {type(), list(ataxic:basic())}. + -> {type(), ataxic:basic()}. ataxia_add_portrait (V, Inv) -> CurrentPortraits = Inv#inventory.portraits, case ordsets:is_element(V, CurrentPortraits) of - true -> Inv; + true -> {Inv, ataxic:current_value()}; false -> { Inv#inventory @@ -199,12 +208,12 @@ ataxia_add_portrait (V, Inv) -> shr_glyph_board:id(), type() ) - -> {type(), list(ataxic:basic())}. + -> {type(), ataxic:basic()}. ataxia_add_glyph_board (V, Inv) -> CurrentGlyphBoards = Inv#inventory.glyph_boards, case ordsets:is_element(V, CurrentGlyphBoards) of - true -> Inv; + true -> {Inv, ataxic:current_value()}; false -> { Inv#inventory @@ -229,12 +238,12 @@ ataxia_add_glyph_board (V, Inv) -> shr_glyph:id(), type() ) - -> {type(), list(ataxic:basic())}. + -> {type(), ataxic:basic()}. ataxia_add_glyph (V, Inv) -> CurrentGlyphs = Inv#inventory.glyphs, case ordsets:is_element(V, CurrentGlyphs) of - true -> Inv; + true -> {Inv, ataxic:current_value()}; false -> { Inv#inventory{ glyphs = ordsets:add_element(V, CurrentGlyphs) }, @@ -354,7 +363,7 @@ add_equipment (Eq, Inv) -> (shr_equipment:type()|shr_equipment:unresolved()), type() ) - -> {type(), list(ataxic:basic())}. + -> {type(), ataxic:basic()}. ataxia_add_equipment (Eq, Inv) -> {S0Inv, Ataxic0} = ataxia_add_weapon(shr_equipment:get_primary_weapon_id(Eq), Inv), @@ -380,10 +389,9 @@ ataxia_add_equipment (Eq, Inv) -> { S4Inv, - lists:flatten + ataxic:optimize ( - [Ataxic0, Ataxic1, Ataxic2, Ataxic3], - lists:flatten(Ataxic4s) + ataxic:sequence([Ataxic0, Ataxic1, Ataxic2, Ataxic3|Ataxic4s]) ) }. diff --git a/src/shared/struct/inventory/shr_weapon.erl.m4 b/src/shared/struct/inventory/shr_weapon.erl.m4 index 189afa7..a18c48e 100644 --- a/src/shared/struct/inventory/shr_weapon.erl.m4 +++ b/src/shared/struct/inventory/shr_weapon.erl.m4 @@ -41,7 +41,7 @@ ( [ default/0, - default/0, + default_id/0, from_id/1 ] ). diff --git a/src/shared/struct/map/shr_inventory.erl b/src/shared/struct/map/shr_inventory.erl deleted file mode 100644 index 1f04533..0000000 --- a/src/shared/struct/map/shr_inventory.erl +++ /dev/null @@ -1,153 +0,0 @@ --module(shr_inventory). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type id() :: ataxia_id:type(). --record -( - inventory, - { - owner_id :: shr_player:id(), - portrait_ids :: ordsets:ordset(binary()), - glyph_ids :: ordsets:ordset(binary()), - glyph_board_ids :: ordsets:ordset(binary()), - weapon_ids :: ordsets:ordset(binary()), - armor_ids :: ordsets:ordset(binary()) - } -). - --opaque type() :: #inventory{}. - --export_type([type/0, id/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_owner_id/1, - - get_portrait_ids/1, - get_glyph_ids/1, - get_glyph_board_ids/1, - get_weapon_ids/1, - get_armor_ids/1, - - set_portrait_ids/2, - set_glyph_ids/2, - set_glyph_board_ids/2, - set_weapon_ids/2, - set_armor_ids/2 - ] -). - --export -( - [ - get_portrait_ids_field/0, - get_glyph_ids_field/0, - get_glyph_board_ids_field/0, - get_weapon_ids_field/0, - get_armor_ids_field/0 - ] -). - --export -( - [ - new/1 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_owner_id (type()) -> shr_player:id(). -get_owner_id (Inv) -> Inv#inventory.owner_id. - --spec get_portrait_ids (type()) -> ordsets:ordset(binary()). -get_portrait_ids (Inv) -> Inv#inventory.portrait_ids. - --spec get_glyph_ids (type()) -> ordsets:ordset(binary()). -get_glyph_ids (Inv) -> Inv#inventory.glyph_ids. - --spec get_glyph_board_ids (type()) -> ordsets:ordset(binary()). -get_glyph_board_ids (Inv) -> Inv#inventory.glyph_board_ids. - --spec get_weapon_ids (type()) -> ordsets:ordset(binary()). -get_weapon_ids (Inv) -> Inv#inventory.weapon_ids. - --spec get_armor_ids (type()) -> ordsets:ordset(binary()). -get_armor_ids (Inv) -> Inv#inventory.armor_ids. - --spec set_portrait_ids (ordsets:ordset(binary()), type()) -> type(). -set_portrait_ids (Value, Inv) -> - Inv#inventory - { - portrait_ids = Value - }. - --spec set_glyph_ids (ordsets:ordset(binary()), type()) -> type(). -set_glyph_ids (Value, Inv) -> - Inv#inventory - { - glyph_ids = Value - }. - --spec set_glyph_board_ids (ordsets:ordset(binary()), type()) -> type(). -set_glyph_board_ids (Value, Inv) -> - Inv#inventory - { - glyph_board_ids = Value - }. - --spec set_weapon_ids (ordsets:ordset(binary()), type()) -> type(). -set_weapon_ids (Value, Inv) -> - Inv#inventory - { - weapon_ids = Value - }. - --spec set_armor_ids (ordsets:ordset(binary()), type()) -> type(). -set_armor_ids (Value, Inv) -> - Inv#inventory - { - armor_ids = Value - }. - --spec get_portrait_ids_field () -> non_neg_integer(). -get_portrait_ids_field () -> #inventory.portrait_ids. - --spec get_glyph_ids_field () -> non_neg_integer(). -get_glyph_ids_field () -> #inventory.glyph_ids. - --spec get_glyph_board_ids_field () -> non_neg_integer(). -get_glyph_board_ids_field () -> #inventory.glyph_board_ids. - --spec get_weapon_ids_field () -> non_neg_integer(). -get_weapon_ids_field () -> #inventory.weapon_ids. - --spec get_armor_ids_field () -> non_neg_integer(). -get_armor_ids_field () -> #inventory.armor_ids. - --spec new (shr_player:id()) -> type(). -new (OwnerID) -> - EmptySet = ordsets:new(), - - #inventory - { - owner_id = OwnerID, - portrait_ids = EmptySet, - glyph_ids = EmptySet, - glyph_board_ids = EmptySet, - weapon_ids = EmptySet, - armor_ids = EmptySet - }. diff --git a/src/shared/struct/map/shr_map.erl b/src/shared/struct/map/shr_map.erl index c0bf385..6db984b 100644 --- a/src/shared/struct/map/shr_map.erl +++ b/src/shared/struct/map/shr_map.erl @@ -36,7 +36,7 @@ get_markers/1, get_marker/2, - get_used_tile_ids/1 + get_related_tile_ids/1 ] ). @@ -136,8 +136,8 @@ get_markers_field () -> #map.markers. get_tile_instances_field () -> #map.tile_instances. %%%% Utility --spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:id()). -get_used_tile_ids (Map) -> +-spec get_related_tile_ids (type()) -> ordsets:ordset(shr_tile:id()). +get_related_tile_ids (Map) -> UsedTileIDs = lists:foldl ( diff --git a/src/shared/struct/shr_character.erl b/src/shared/struct/shr_character.erl index d5dec75..ea8e857 100644 --- a/src/shared/struct/shr_character.erl +++ b/src/shared/struct/shr_character.erl @@ -164,15 +164,15 @@ set_equipment (Eq, Char) when is_record(Char, shr_char) -> NewAttributes = shr_omnimods:apply_to_attributes ( - shr_attributes:default(), - NewOmnimods + NewOmnimods, + shr_attributes:default() ), NewStatistics = shr_omnimods:apply_to_statistics ( - shr_statistics:new_raw(NewAttributes), - NewOmnimods + NewOmnimods, + shr_statistics:new_raw(NewAttributes) ), Char#shr_char @@ -239,15 +239,15 @@ switch_weapons (Char) when is_record(Char, shr_char) -> NewAttributes = shr_omnimods:apply_to_attributes ( - shr_attributes:default(), - NewOmnimods + NewOmnimods, + shr_attributes:default() ), NewStatistics = shr_omnimods:apply_to_statistics ( - shr_statistics:new_raw(NewAttributes), - NewOmnimods + NewOmnimods, + shr_statistics:new_raw(NewAttributes) ), Char#shr_char @@ -325,15 +325,15 @@ set_extra_omnimods (O, Char) -> NewAttributes = shr_omnimods:apply_to_attributes ( - shr_attributes:default(), - NewOmnimods + NewOmnimods, + shr_attributes:default() ), NewStatistics = shr_omnimods:apply_to_statistics ( - shr_statistics:new_raw(NewAttributes), - NewOmnimods + NewOmnimods, + shr_statistics:new_raw(NewAttributes) ), Char#shr_char diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl index bfd9d25..8d82287 100644 --- a/src/shared/struct/shr_omnimods.erl +++ b/src/shared/struct/shr_omnimods.erl @@ -28,6 +28,7 @@ -export ( [ + default/0, new/4, new_dirty/4 ] @@ -115,6 +116,9 @@ new (AttributeMods, StatisticMods, AttackMods, DefenseMods) -> defmods = dict:from_list(DefenseMods) }. +-spec default () -> type(). +default () -> new([], [], [], []). + -spec new_dirty ( list(entry()), |