summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-05-08 21:17:32 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-05-08 21:17:32 +0200 |
commit | 48668b142f99ea8ca58fd649ed331c4823787b61 (patch) | |
tree | 92509cd90ae9f66d19d19565363e625cd9ec3f82 /src/battlemap | |
parent | cdd59b539337c02e3ff5d44860e4287f07ce052d (diff) |
... and struct() -> type().
Diffstat (limited to 'src/battlemap')
21 files changed, 428 insertions, 379 deletions
diff --git a/src/battlemap/src/game-logic/movement.erl b/src/battlemap/src/game-logic/movement.erl index 588fad9..467f87b 100644 --- a/src/battlemap/src/game-logic/movement.erl +++ b/src/battlemap/src/game-logic/movement.erl @@ -19,7 +19,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec cross ( - battlemap:struct(), + battlemap:type(), list(location:type()), list(direction:enum()), non_neg_integer(), @@ -48,7 +48,7 @@ cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, Location) -> -spec cross ( - battlemap:struct(), + battlemap:type(), list(location:type()), list(direction:enum()), location:type() diff --git a/src/battlemap/src/game-logic/turn_actions.erl b/src/battlemap/src/game-logic/turn_actions.erl new file mode 100644 index 0000000..f0e2e8f --- /dev/null +++ b/src/battlemap/src/game-logic/turn_actions.erl @@ -0,0 +1,262 @@ +-module(turn_actions). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + handle/2 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec handle_attack_sequence + ( + character_instance:type(), + character_instance:type(), + list(attack:step()) + ) + -> {list(attack:type()), non_neg_integer(), non_neg_integer()}. +handle_attack_sequence +( + CharacterInstance, + TargetCharacterInstance, + AttackSequence +) -> + Character = character_instance:get_character(CharacterInstance), + TargetCharacter = character_instance:get_character(TargetCharacterInstance), + CharacterStatistics = character:get_statistics(Character), + TargetCharacterStatistics = character:get_statistics(TargetCharacter), + + AttackPlannedEffects = + lists:map + ( + fun (AttackStep) -> + attack:get_description_of + ( + AttackStep, + CharacterStatistics, + TargetCharacterStatistics + ) + end, + AttackSequence + ), + + lists:foldl + ( + fun + ( + AttackEffectCandidate, + {AttackValidEffects, AttackerHealth, DefenderHealth} + ) -> + {AttackResult, NewAttackerHealth, NewDefenderHealth} = + attack:apply_to_healths + ( + AttackEffectCandidate, + AttackerHealth, + DefenderHealth + ), + case AttackResult of + nothing -> {AttackValidEffects, AttackerHealth, DefenderHealth}; + _ -> + { + (AttackValidEffects ++ [AttackResult]), + NewAttackerHealth, + NewDefenderHealth + } + end + end, + { + [], + character_instance:get_current_health(CharacterInstance), + character_instance:get_current_health(TargetCharacterInstance) + }, + AttackPlannedEffects + ). + +-spec handle_switch_weapon + ( + character_turn_update:type() + ) + -> character_turn_update:type(). +handle_switch_weapon (Update) -> + Data = character_turn_update:get_data(Update), + CharacterInstance = character_turn_data:get_character_instance(Data), + CharacterInstanceIX = character_turn_data:get_character_instance_ix(Data), + Character = character_instance:get_character(CharacterInstance), + CharacterAttributes = character:get_attributes(Character), + {PrimaryWeaponID, SecondaryWeaponID} = character:get_weapon_ids(Character), + + UpdatedWeaponIDs = {SecondaryWeaponID, PrimaryWeaponID}, + UpdatedCharacterStatistics = + statistics:new(CharacterAttributes, UpdatedWeaponIDs), + UpdatedCharacter = + character:set_statistics + ( + UpdatedCharacterStatistics, + character:set_weapon_ids(UpdatedWeaponIDs, Character) + ), + UpdatedCharacterInstance = + character_instance:set_character(UpdatedCharacter, CharacterInstance), + + % TODO: db update entries... + % {character_instance, CharacterInstanceIX, wp0, SecondaryWeaponID}, + % {character_instance, CharacterInstanceIX, wp1, PrimaryWeaponID} + S0Update = + character_turn_update:add_to_timeline + ( + turn_result:new_character_switched_weapons(CharacterInstanceIX), + Update + ), + + UpdatedData = + character_turn_data:set_character_instance + ( + UpdatedCharacterInstance, + Data + ), + + character_turn_update:set_data(UpdatedData, S0Update). + +-spec handle_move + ( + character_turn_update:type(), + battle_action:type() + ) + -> character_turn_update:type(). +handle_move (Update, BattleAction) -> + Character = character_instance:get_character(CharacterInstance), + CharacterStatistics = character:get_statistics(Character), + Battlemap = battle:get_battlemap(Battle), + Path = BattleAction#move.path, + CharacterMovementPoints = + statistics:get_movement_points(CharacterStatistics), + + ForbiddenLocations = + array:foldl + ( + fun (IX, CharInst, Prev) -> + IsAlive = character_instance:get_is_alive(CharInst), + if + (IX == CharacterInstanceIX) -> Prev; + (not IsAlive) -> Prev; + true -> [character_instance:get_location(CharInst)|Prev] + end + end, + [], + battle:get_character_instances(Battle) + ), + + {NewLocation, Cost} = + movement:cross + ( + Battlemap, + ForbiddenLocations, + Path, + character_instance:get_location(CharacterInstance) + ), + + true = (Cost =< CharacterMovementPoints), + + UpdatedCharacterInstance = + character_instance:set_location(NewLocation, CharacterInstance), + + { + % TODO: hide that into database_diff structs. + [{character_instance, CharacterInstanceIX, loc, NewLocation}], + % TODO: hide that into turn_result structs. + [turn_result:new_character_moved(CharacterInstanceIX, Path, NewLocation)], + Battle, + UpdatedCharacterInstance + }. + +-spec handle_attack + ( + character_turn_update:type(), + battle_action:type() + ) + -> character_turn_update:type(). +handle_attack (Update, BattleAction) -> + Character = character_instance:get_character(CharacterInstance), + TargetIX = BattleAction#attack.target_ix, + TargetCharacterInstance = battle:get_character_instance(TargetIX, Battle), + TargetCharacter = character_instance:get_character(TargetCharacterInstance), + + Range = + location:dist + ( + character_instance:get_location(CharacterInstance), + character_instance:get_location(TargetCharacterInstance) + ), + + {AttackingWeaponID, _} = character:get_weapon_ids(Character), + {DefendingWeaponID, _} = character:get_weapon_ids(TargetCharacter), + + AttackingWeapon = weapon:from_id(AttackingWeaponID), + DefendingWeapon = weapon:from_id(DefendingWeaponID), + + AttackSequence = + attack:get_sequence(Range, AttackingWeapon, DefendingWeapon), + + {AttackEffects, RemainingAttackerHealth, RemainingDefenderHealth} = + handle_attack_sequence + ( + CharacterInstance, + TargetCharacterInstance, + AttackSequence + ), + + UpdatedCharacterInstance = + character_instance:set_current_health + ( + RemainingAttackerHealth, + CharacterInstance + ), + + UpdatedBattle = + battle:set_character_instance + ( + TargetIX, + character_instance:set_current_health + ( + RemainingDefenderHealth, + TargetCharacterInstance + ), + Battle + ), + { + % TODO: hide that into database_diff structs. + [], % TODO + [ + turn_result:new_character_attacked + ( + CharacterInstanceIX, + TargetIX, + AttackEffects + ) + ], + UpdatedBattle, + UpdatedCharacterInstance + }. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec handle +( + character_turn_update:type(), + battle_action:type() +) +-> character_turn_update:type(). +handle (Update, BattleAction) -> + case battle_action:get_type(BattleAction) of + move -> handle_move(Update, BattleAction); + switch_weapon -> handle_switch_weapon(Update); + attack -> handle_attack(Update, BattleAction) + end. diff --git a/src/battlemap/src/query/character_turn.erl b/src/battlemap/src/query/character_turn.erl index 70afbca..b269084 100644 --- a/src/battlemap/src/query/character_turn.erl +++ b/src/battlemap/src/query/character_turn.erl @@ -15,7 +15,7 @@ %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%-spec send_to_database (list(database_diff:struct()), character_turn_request:type()) -> 'ok'. +%-spec send_to_database (list(database_diff:type()), character_turn_request:type()) -> 'ok'. %%%% REQUEST DECODING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/battlemap/src/query/load_state.erl b/src/battlemap/src/query/load_state.erl index a03a20f..37a30cf 100644 --- a/src/battlemap/src/query/load_state.erl +++ b/src/battlemap/src/query/load_state.erl @@ -19,7 +19,7 @@ ( query_state, { - battle :: battle:struct() + battle :: battle:type() } ). diff --git a/src/battlemap/src/reply/add_char.erl b/src/battlemap/src/reply/add_char.erl index 990b23e..7fad9a0 100644 --- a/src/battlemap/src/reply/add_char.erl +++ b/src/battlemap/src/reply/add_char.erl @@ -14,7 +14,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec attributes_as_json ( - attributes:struct() + attributes:type() ) -> {list({binary(), non_neg_integer()})}. attributes_as_json (Attributes) -> @@ -35,7 +35,7 @@ attributes_as_json (Attributes) -> -spec generate ( non_neg_integer(), - character_instance:struct(), + character_instance:type(), player:id() ) -> {list(any())}. diff --git a/src/battlemap/src/reply/set_map.erl b/src/battlemap/src/reply/set_map.erl index 6a7cd39..8518ac5 100644 --- a/src/battlemap/src/reply/set_map.erl +++ b/src/battlemap/src/reply/set_map.erl @@ -16,7 +16,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (battlemap:struct()) -> {list(any())}. +-spec generate (battlemap:type()) -> {list(any())}. generate (Battlemap) -> { [ diff --git a/src/battlemap/src/shim/database_shim.erl b/src/battlemap/src/shim/database_shim.erl index a26087d..1b1992b 100644 --- a/src/battlemap/src/shim/database_shim.erl +++ b/src/battlemap/src/shim/database_shim.erl @@ -47,9 +47,9 @@ add_to_db (ID, Val) -> non_neg_integer(), non_neg_integer(), non_neg_integer(), - list(character:struct()) + list(character:type()) ) - -> list(character:struct()). + -> list(character:type()). generate_random_characters ( 0, diff --git a/src/battlemap/src/struct/attack.erl b/src/battlemap/src/struct/attack.erl index 71bc2bb..bddc3cd 100644 --- a/src/battlemap/src/struct/attack.erl +++ b/src/battlemap/src/struct/attack.erl @@ -18,8 +18,8 @@ } ). --opaque struct() :: #attack{}. --type maybe_struct() :: ('nothing' | struct()). +-opaque type() :: #attack{}. +-type maybe_type() :: ('nothing' | type()). -opaque step() :: {order(), boolean()}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -47,8 +47,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec roll_precision ( - statistics:struct(), - statistics:struct() + statistics:type(), + statistics:type() ) -> precision(). roll_precision (AttackerStatistics, DefenderStatistics) -> @@ -63,8 +63,8 @@ roll_precision (AttackerStatistics, DefenderStatistics) -> -spec roll_damage ( - statistics:struct(), - statistics:struct() + statistics:type(), + statistics:type() ) -> {non_neg_integer(), boolean()}. roll_damage (AttackerStatistics, _DefenderStatistics) -> @@ -77,7 +77,7 @@ roll_damage (AttackerStatistics, _DefenderStatistics) -> _ -> {BaseDamage, false} end. --spec roll_parry (statistics:struct()) -> boolean(). +-spec roll_parry (statistics:type()) -> boolean(). roll_parry (DefenderStatistics) -> DefenderParryChance = statistics:get_parries(DefenderStatistics), (roll:percentage() =< DefenderParryChance). @@ -85,11 +85,11 @@ roll_parry (DefenderStatistics) -> -spec effect_of_attack ( order(), - statistics:struct(), - statistics:struct(), + statistics:type(), + statistics:type(), boolean() ) - -> struct(). + -> type(). effect_of_attack (Order, AttackerStatistics, DefenderStatistics, CanParry) -> ParryIsSuccessful = (CanParry and roll_parry(DefenderStatistics)), {ActualAtkStatistics, ActualDefStatistics} = @@ -133,10 +133,10 @@ encode_precision (misses) -> <<"m">>. -spec get_description_of ( step(), - statistics:struct(), - statistics:struct() + statistics:type(), + statistics:type() ) - -> maybe_struct(). + -> maybe_type(). get_description_of ( {first, CanParry}, @@ -175,11 +175,11 @@ get_description_of -spec apply_to_healths ( - maybe_struct(), + maybe_type(), non_neg_integer(), non_neg_integer() ) - -> {maybe_struct(), non_neg_integer(), non_neg_integer()}. + -> {maybe_type(), non_neg_integer(), non_neg_integer()}. apply_to_healths ( nothing, @@ -244,8 +244,8 @@ when -spec get_sequence ( non_neg_integer(), - weapon:struct(), - weapon:struct() + weapon:type(), + weapon:type() ) -> list(step()). get_sequence (AttackRange, AttackerWeapon, DefenderWeapon) -> @@ -279,7 +279,7 @@ get_sequence (AttackRange, AttackerWeapon, DefenderWeapon) -> [First, Counter, Second] end. --spec encode (struct()) -> {list(any())}. +-spec encode (type()) -> {list(any())}. % This shouldn't be a possibility. Types in this module are a mess... encode (Attack) -> Order = Attack#attack.order, diff --git a/src/battlemap/src/struct/attributes.erl b/src/battlemap/src/struct/attributes.erl index 6728831..0d503ee 100644 --- a/src/battlemap/src/struct/attributes.erl +++ b/src/battlemap/src/struct/attributes.erl @@ -16,7 +16,7 @@ } ). --opaque struct() :: #attributes{}. +-opaque type() :: #attributes{}. -export_type([struct/0]). @@ -59,43 +59,43 @@ %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_constitution (struct()) -> integer(). +-spec get_constitution (type()) -> integer(). get_constitution (Att) -> Att#attributes.constitution. --spec get_dexterity (struct()) -> integer(). +-spec get_dexterity (type()) -> integer(). get_dexterity (Att) -> Att#attributes.dexterity. --spec get_intelligence (struct()) -> integer(). +-spec get_intelligence (type()) -> integer(). get_intelligence (Att) -> Att#attributes.intelligence. --spec get_mind (struct()) -> integer(). +-spec get_mind (type()) -> integer(). get_mind (Att) -> Att#attributes.mind. --spec get_speed (struct()) -> integer(). +-spec get_speed (type()) -> integer(). get_speed (Att) -> Att#attributes.speed. --spec get_strength (struct()) -> integer(). +-spec get_strength (type()) -> integer(). get_strength (Att) -> Att#attributes.strength. --spec set_constitution (integer(), struct()) -> struct(). +-spec set_constitution (integer(), type()) -> type(). set_constitution (Val, Att) -> Att#attributes{ constitution = Val }. --spec set_dexterity (integer(), struct()) -> struct(). +-spec set_dexterity (integer(), type()) -> type(). set_dexterity (Val, Att) -> Att#attributes{ dexterity = Val }. --spec set_intelligence (integer(), struct()) -> struct(). +-spec set_intelligence (integer(), type()) -> type(). set_intelligence (Val, Att) -> Att#attributes{ intelligence = Val }. --spec set_mind (integer(), struct()) -> struct(). +-spec set_mind (integer(), type()) -> type(). set_mind (Val, Att) -> Att#attributes{ mind = Val }. --spec set_speed (integer(), struct()) -> struct(). +-spec set_speed (integer(), type()) -> type(). set_speed (Val, Att) -> Att#attributes{ speed = Val }. --spec set_strength (integer(), struct()) -> struct(). +-spec set_strength (integer(), type()) -> type(). set_strength (Val, Att) -> Att#attributes{ strength = Val }. --spec random () -> struct(). +-spec random () -> type(). random () -> #attributes { diff --git a/src/battlemap/src/struct/battle.erl b/src/battlemap/src/struct/battle.erl index 5ac12e4..4d5be8b 100644 --- a/src/battlemap/src/struct/battle.erl +++ b/src/battlemap/src/struct/battle.erl @@ -10,14 +10,14 @@ battle, { id :: id(), - battlemap :: battlemap:struct(), - character_instances :: array:array(character_instance:struct()), - players :: array:array(player:struct()), - current_player_turn :: player_turn:struct() + battlemap :: battlemap:type(), + character_instances :: array:array(character_instance:type()), + players :: array:array(player:type()), + current_player_turn :: player_turn:type() } ). --opaque struct() :: #battle{}. +-opaque type() :: #battle{}. -export_type([struct/0, id/0]). @@ -73,36 +73,36 @@ get_all_timelines (Result, CurrentIndex, EndPoint, ArraySize, Players) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_id (struct()) -> id(). +-spec get_id (type()) -> id(). get_id (Battle) -> Battle#battle.id. --spec get_battlemap (struct()) -> battlemap:struct(). +-spec get_battlemap (type()) -> battlemap:type(). get_battlemap (Battle) -> Battle#battle.battlemap. --spec get_character_instances (struct()) -> - array:array(character_instance:struct()). +-spec get_character_instances (type()) -> + array:array(character_instance:type()). get_character_instances (Battle) -> Battle#battle.character_instances. --spec get_character_instance (non_neg_integer(), struct()) -> - character_instance:struct(). +-spec get_character_instance (non_neg_integer(), type()) -> + character_instance:type(). get_character_instance (IX, Battle) -> array:get(IX, Battle#battle.character_instances). --spec get_players (struct()) -> array:array(player:struct()). +-spec get_players (type()) -> array:array(player:type()). get_players (Battle) -> Battle#battle.players. --spec get_player (non_neg_integer(), struct()) -> player:struct(). +-spec get_player (non_neg_integer(), type()) -> player:type(). get_player (IX, Battle) -> array:get(IX, Battle#battle.players). --spec get_current_player_turn (struct()) -> player_turn:struct(). +-spec get_current_player_turn (type()) -> player_turn:type(). get_current_player_turn (Battle) -> Battle#battle.current_player_turn. --spec get_encoded_last_turns_effects (struct()) -> list(any()). +-spec get_encoded_last_turns_effects (type()) -> list(any()). get_encoded_last_turns_effects (Battle) -> CurrentPlayerTurn = Battle#battle.current_player_turn, Players = Battle#battle.players, @@ -112,7 +112,7 @@ get_encoded_last_turns_effects (Battle) -> StartingPoint = ((CurrentPlayerIX + 1) rem PlayersCount), get_all_timelines([], StartingPoint, CurrentPlayerIX, PlayersCount, Players). --spec set_battlemap (battlemap:struct(), struct()) -> struct(). +-spec set_battlemap (battlemap:type(), type()) -> type(). set_battlemap (Battlemap, Battle) -> Battle#battle { @@ -121,10 +121,10 @@ set_battlemap (Battlemap, Battle) -> -spec set_character_instances ( - array:array(character_instance:struct()), - struct() + array:array(character_instance:type()), + type() ) - -> struct(). + -> type(). set_character_instances (CharacterInstances, Battle) -> Battle#battle { @@ -134,10 +134,10 @@ set_character_instances (CharacterInstances, Battle) -> -spec set_character_instance ( non_neg_integer(), - character_instance:struct(), - struct() + character_instance:type(), + type() ) - -> struct(). + -> type(). set_character_instance (IX, CharacterInstance, Battle) -> Battle#battle { @@ -152,10 +152,10 @@ set_character_instance (IX, CharacterInstance, Battle) -> -spec set_players ( - array:array(player:struct()), - struct() + array:array(player:type()), + type() ) - -> struct(). + -> type(). set_players (Players, Battle) -> Battle#battle { @@ -165,10 +165,10 @@ set_players (Players, Battle) -> -spec set_player ( non_neg_integer(), - player:struct(), - struct() + player:type(), + type() ) - -> struct(). + -> type(). set_player (IX, Player, Battle) -> Battle#battle { @@ -183,10 +183,10 @@ set_player (IX, Player, Battle) -> -spec set_current_player_turn ( - player_turn:struct(), - struct() + player_turn:type(), + type() ) - -> struct(). + -> type(). set_current_player_turn (PlayerTurn, Battle) -> Battle#battle { @@ -196,11 +196,11 @@ set_current_player_turn (PlayerTurn, Battle) -> -spec random ( id(), - list(player:struct()), - battlemap:struct(), - list(character:struct()) + list(player:type()), + battlemap:type(), + list(character:type()) ) - -> struct(). + -> type(). random (ID, PlayersAsList, Battlemap, Characters) -> BattlemapWidth = battlemap:get_width(Battlemap), BattlemapHeight = battlemap:get_height(Battlemap), diff --git a/src/battlemap/src/struct/battle_action.erl b/src/battlemap/src/struct/battle_action.erl index f40de0d..2b1a89e 100644 --- a/src/battlemap/src/struct/battle_action.erl +++ b/src/battlemap/src/struct/battle_action.erl @@ -27,7 +27,7 @@ ). -type category() :: ('move' | 'switch_weapon' | 'attack' | 'nothing'). --opaque struct() :: (#move{} | #switch_weapon{} | #attack{}). +-opaque type() :: (#move{} | #switch_weapon{} | #attack{}). -export_type([category/0, struct/0]). @@ -38,7 +38,6 @@ ( [ decode/1, - handle/4, can_follow/2 ] ). @@ -46,91 +45,28 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec decode_mov_action (map()) -> struct(). +-spec decode_mov_action (map()) -> type(). decode_mov_action (JSONMap) -> PathInBinary = maps:get(<<"p">>, JSONMap), Path = lists:map(fun direction:decode/1, PathInBinary), #move { path = Path }. --spec decode_atk_action (map()) -> struct(). +-spec decode_atk_action (map()) -> type(). decode_atk_action (JSONMap) -> TargetIX = binary_to_integer(maps:get(<<"tix">>, JSONMap)), #attack { target_ix = TargetIX }. --spec decode_swp_action (map()) -> struct(). +-spec decode_swp_action (map()) -> type(). decode_swp_action (_JSONMap) -> #switch_weapon{}. --spec handle_attack_sequence - ( - character_instance:struct(), - character_instance:struct(), - list(attack:step()) - ) - -> {list(attack:struct()), non_neg_integer(), non_neg_integer()}. -handle_attack_sequence -( - CharacterInstance, - TargetCharacterInstance, - AttackSequence -) -> - Character = character_instance:get_character(CharacterInstance), - TargetCharacter = character_instance:get_character(TargetCharacterInstance), - CharacterStatistics = character:get_statistics(Character), - TargetCharacterStatistics = character:get_statistics(TargetCharacter), - - AttackPlannedEffects = - lists:map - ( - fun (AttackStep) -> - attack:get_description_of - ( - AttackStep, - CharacterStatistics, - TargetCharacterStatistics - ) - end, - AttackSequence - ), - - lists:foldl - ( - fun - ( - AttackEffectCandidate, - {AttackValidEffects, AttackerHealth, DefenderHealth} - ) -> - {AttackResult, NewAttackerHealth, NewDefenderHealth} = - attack:apply_to_healths - ( - AttackEffectCandidate, - AttackerHealth, - DefenderHealth - ), - case AttackResult of - nothing -> {AttackValidEffects, AttackerHealth, DefenderHealth}; - _ -> - { - (AttackValidEffects ++ [AttackResult]), - NewAttackerHealth, - NewDefenderHealth - } - end - end, - { - [], - character_instance:get_current_health(CharacterInstance), - character_instance:get_current_health(TargetCharacterInstance) - }, - AttackPlannedEffects - ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec decode (map()) -> struct(). +-spec decode (map()) -> type(). decode (EncodedAction) -> JSONActionMap = EncodedAction, %jiffy:decode(EncodedAction, [return_maps]), ActionType = maps:get(<<"t">>, JSONActionMap), @@ -147,156 +83,3 @@ can_follow (nothing, move) -> true; can_follow (switch_weapon, attack) -> true; can_follow (move, attack) -> true; can_follow (_, _) -> false. - --spec handle -( - battle:struct(), - character_instance:struct(), - non_neg_integer(), - struct() -) --> -{ - list(database_diff:struct()), - list(turn_result:struct()), - battle:struct(), - character_instance:struct() -}. -handle (Battle, CharacterInstance, CharacterInstanceIX, BattleAction) -when is_record(BattleAction, switch_weapon) -> - Character = character_instance:get_character(CharacterInstance), - CharacterAttributes = character:get_attributes(Character), - {PrimaryWeaponID, SecondaryWeaponID} = character:get_weapon_ids(Character), - - UpdatedWeaponIDs = {SecondaryWeaponID, PrimaryWeaponID}, - UpdatedCharacterStatistics = - statistics:new(CharacterAttributes, UpdatedWeaponIDs), - UpdatedCharacter = - character:set_statistics - ( - UpdatedCharacterStatistics, - character:set_weapon_ids(UpdatedWeaponIDs, Character) - ), - UpdatedCharacterInstance = - character_instance:set_character(UpdatedCharacter, CharacterInstance), - - { - % TODO: hide that into database_diff structs. - [ - {character_instance, CharacterInstanceIX, wp0, SecondaryWeaponID}, - {character_instance, CharacterInstanceIX, wp1, PrimaryWeaponID} - % ... statistics as well. - ], - [turn_result:new_character_switched_weapons(CharacterInstanceIX)], - Battle, - UpdatedCharacterInstance - }; -handle (Battle, CharacterInstance, CharacterInstanceIX, BattleAction) -when is_record(BattleAction, move) -> - Character = character_instance:get_character(CharacterInstance), - CharacterStatistics = character:get_statistics(Character), - Battlemap = battle:get_battlemap(Battle), - Path = BattleAction#move.path, - CharacterMovementPoints = - statistics:get_movement_points(CharacterStatistics), - - ForbiddenLocations = - array:foldl - ( - fun (IX, CharInst, Prev) -> - IsAlive = character_instance:get_is_alive(CharInst), - if - (IX == CharacterInstanceIX) -> Prev; - (not IsAlive) -> Prev; - true -> [character_instance:get_location(CharInst)|Prev] - end - end, - [], - battle:get_character_instances(Battle) - ), - - {NewLocation, Cost} = - movement:cross - ( - Battlemap, - ForbiddenLocations, - Path, - character_instance:get_location(CharacterInstance) - ), - - true = (Cost =< CharacterMovementPoints), - - UpdatedCharacterInstance = - character_instance:set_location(NewLocation, CharacterInstance), - - { - % TODO: hide that into database_diff structs. - [{character_instance, CharacterInstanceIX, loc, NewLocation}], - % TODO: hide that into turn_result structs. - [turn_result:new_character_moved(CharacterInstanceIX, Path, NewLocation)], - Battle, - UpdatedCharacterInstance - }; -handle (Battle, CharacterInstance, CharacterInstanceIX, BattleAction) -when is_record(BattleAction, attack) -> - Character = character_instance:get_character(CharacterInstance), - TargetIX = BattleAction#attack.target_ix, - TargetCharacterInstance = battle:get_character_instance(TargetIX, Battle), - TargetCharacter = character_instance:get_character(TargetCharacterInstance), - - Range = - location:dist - ( - character_instance:get_location(CharacterInstance), - character_instance:get_location(TargetCharacterInstance) - ), - - {AttackingWeaponID, _} = character:get_weapon_ids(Character), - {DefendingWeaponID, _} = character:get_weapon_ids(TargetCharacter), - - AttackingWeapon = weapon:from_id(AttackingWeaponID), - DefendingWeapon = weapon:from_id(DefendingWeaponID), - - AttackSequence = - attack:get_sequence(Range, AttackingWeapon, DefendingWeapon), - - {AttackEffects, RemainingAttackerHealth, RemainingDefenderHealth} = - handle_attack_sequence - ( - CharacterInstance, - TargetCharacterInstance, - AttackSequence - ), - - UpdatedCharacterInstance = - character_instance:set_current_health - ( - RemainingAttackerHealth, - CharacterInstance - ), - - UpdatedBattle = - battle:set_character_instance - ( - TargetIX, - character_instance:set_current_health - ( - RemainingDefenderHealth, - TargetCharacterInstance - ), - Battle - ), - { - % TODO: hide that into database_diff structs. - [], % TODO - [ - turn_result:new_character_attacked - ( - CharacterInstanceIX, - TargetIX, - AttackEffects - ) - ], - UpdatedBattle, - UpdatedCharacterInstance - }. diff --git a/src/battlemap/src/struct/battlemap.erl b/src/battlemap/src/struct/battlemap.erl index 59e0639..e0d30a4 100644 --- a/src/battlemap/src/struct/battlemap.erl +++ b/src/battlemap/src/struct/battlemap.erl @@ -16,7 +16,7 @@ } ). --opaque struct() :: #battlemap{}. +-opaque type() :: #battlemap{}. -export_type([struct/0, id/0]). @@ -84,19 +84,19 @@ location_to_array_index (ArrayWidth, {X, Y}) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_id (struct()) -> id(). +-spec get_id (type()) -> id(). get_id (Battlemap) -> Battlemap#battlemap.id. --spec get_width (struct()) -> integer(). +-spec get_width (type()) -> integer(). get_width (Battlemap) -> Battlemap#battlemap.width. --spec get_height (struct()) -> integer(). +-spec get_height (type()) -> integer(). get_height (Battlemap) -> Battlemap#battlemap.height. --spec get_tile_ids (struct()) -> array:array(tile:id()). +-spec get_tile_ids (type()) -> array:array(tile:id()). get_tile_ids (Battlemap) -> Battlemap#battlemap.tile_ids. --spec get_tile_id (location:type(), struct()) -> tile:id(). +-spec get_tile_id (location:type(), type()) -> tile:id(). get_tile_id (Location, Battlemap) -> TileIX = location_to_array_index(Battlemap#battlemap.width, Location), array:get(TileIX, Battlemap#battlemap.tile_ids). @@ -107,7 +107,7 @@ get_tile_id (Location, Battlemap) -> non_neg_integer(), non_neg_integer() ) - -> struct(). + -> type(). random (ID, Width, Height) -> InitialTile = tile:random_id(), TileIDs = generate_random_tile_ids(InitialTile, [], Width, Height, Width), diff --git a/src/battlemap/src/struct/character.erl b/src/battlemap/src/struct/character.erl index 8e1099e..7daaadd 100644 --- a/src/battlemap/src/struct/character.erl +++ b/src/battlemap/src/struct/character.erl @@ -14,13 +14,13 @@ name :: binary(), icon :: binary(), portrait :: binary(), - attributes :: attributes:struct(), - statistics :: statistics:struct(), + attributes :: attributes:type(), + statistics :: statistics:type(), weapon_ids :: {weapon:id(), weapon:id()} } ). --opaque struct() :: #character{}. +-opaque type() :: #character{}. -export_type([struct/0, id/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -59,36 +59,36 @@ %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_id (struct()) -> id(). +-spec get_id (type()) -> id(). get_id (Char) -> Char#character.id. --spec get_owner_id (struct()) -> player:id(). +-spec get_owner_id (type()) -> player:id(). get_owner_id (Char) -> Char#character.owner_id. --spec get_name (struct()) -> binary(). +-spec get_name (type()) -> binary(). get_name (Char) -> Char#character.name. --spec get_icon (struct()) -> binary(). +-spec get_icon (type()) -> binary(). get_icon (Char) -> Char#character.icon. --spec get_portrait (struct()) -> binary(). +-spec get_portrait (type()) -> binary(). get_portrait (Char) -> Char#character.portrait. --spec get_attributes (struct()) -> attributes:struct(). +-spec get_attributes (type()) -> attributes:type(). get_attributes (Char) -> Char#character.attributes. --spec get_weapon_ids (struct()) -> {weapon:id(), weapon:id()}. +-spec get_weapon_ids (type()) -> {weapon:id(), weapon:id()}. get_weapon_ids (Char) -> Char#character.weapon_ids. --spec get_statistics (struct()) -> statistics:struct(). +-spec get_statistics (type()) -> statistics:type(). get_statistics (Char) -> Char#character.statistics. -spec set_weapon_ids ( {weapon:id(), weapon:id()}, - struct() + type() ) - -> struct(). + -> type(). set_weapon_ids (WeaponIDs, Char) -> Char#character { @@ -97,10 +97,10 @@ set_weapon_ids (WeaponIDs, Char) -> -spec set_statistics ( - statistics:struct(), - struct() + statistics:type(), + type() ) - -> struct(). + -> type(). set_statistics (Stats, Char) -> Char#character { @@ -112,7 +112,7 @@ set_statistics (Stats, Char) -> non_neg_integer(), player:id() ) - -> struct(). + -> type(). random (ID, OwnerID) -> WeaponIDs = {weapon:random_id(), weapon:random_id()}, Attributes = attributes:random(), diff --git a/src/battlemap/src/struct/character_instance.erl b/src/battlemap/src/struct/character_instance.erl index b657f10..e58723e 100644 --- a/src/battlemap/src/struct/character_instance.erl +++ b/src/battlemap/src/struct/character_instance.erl @@ -7,14 +7,14 @@ ( character_instance, { - character :: character:struct(), + character :: character:type(), location :: {non_neg_integer(), non_neg_integer()}, current_health :: non_neg_integer(), active :: boolean() } ). --opaque struct() :: #character_instance{}. +-opaque type() :: #character_instance{}. -export_type([struct/0]). @@ -78,22 +78,22 @@ find_random_location (BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_character (struct()) -> character:struct(). +-spec get_character (type()) -> character:type(). get_character (CharInst) -> CharInst#character_instance.character. --spec get_location (struct()) -> {non_neg_integer(), non_neg_integer()}. +-spec get_location (type()) -> {non_neg_integer(), non_neg_integer()}. get_location (CharInst) -> true = get_is_alive(CharInst), CharInst#character_instance.location. --spec get_current_health (struct()) -> non_neg_integer(). +-spec get_current_health (type()) -> non_neg_integer(). get_current_health (CharInst) -> CharInst#character_instance.current_health. --spec get_is_alive (struct()) -> boolean(). +-spec get_is_alive (type()) -> boolean(). get_is_alive (CharInst) -> (CharInst#character_instance.current_health > 0). --spec get_is_active (struct()) -> boolean(). +-spec get_is_active (type()) -> boolean(). get_is_active (CharInst) -> ( CharInst#character_instance.active @@ -101,7 +101,7 @@ get_is_active (CharInst) -> get_is_alive(CharInst) ). --spec set_character (character:struct(), struct()) -> struct(). +-spec set_character (character:type(), type()) -> type(). set_character (Char, CharInst) -> CharInst#character_instance { @@ -111,23 +111,23 @@ set_character (Char, CharInst) -> -spec set_location ( {non_neg_integer(), non_neg_integer()}, - struct() + type() ) - -> struct(). + -> type(). set_location (Location, CharInst) -> CharInst#character_instance { location = Location }. --spec set_current_health (non_neg_integer(), struct()) -> struct(). +-spec set_current_health (non_neg_integer(), type()) -> type(). set_current_health (Health, CharInst) -> CharInst#character_instance { current_health = max(0, Health) }. --spec set_is_active (boolean(), struct()) -> struct(). +-spec set_is_active (boolean(), type()) -> type(). set_is_active (Active, CharInst) -> CharInst#character_instance { @@ -137,10 +137,10 @@ set_is_active (Active, CharInst) -> %%%% Utils -spec new ( - character:struct(), + character:type(), {non_neg_integer(), non_neg_integer()} ) - -> struct(). + -> type(). new (Character, Location) -> CharacterStatistics = character:get_statistics(Character), #character_instance @@ -153,12 +153,12 @@ new (Character, Location) -> -spec random ( - character:struct(), + character:type(), non_neg_integer(), non_neg_integer(), list({non_neg_integer(), non_neg_integer()}) ) - -> struct(). + -> type(). random (Character, BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> new ( diff --git a/src/battlemap/src/struct/character_turn_data.erl b/src/battlemap/src/struct/character_turn_data.erl index 0f8364e..ca0954e 100644 --- a/src/battlemap/src/struct/character_turn_data.erl +++ b/src/battlemap/src/struct/character_turn_data.erl @@ -8,8 +8,8 @@ type, { dirty :: boolean(), - battle :: battle:struct(), - character_instance :: character_instance:struct(), + battle :: battle:type(), + character_instance :: character_instance:type(), character_instance_ix :: non_neg_integer() } ). @@ -29,6 +29,7 @@ get_battle_is_dirty/1, get_battle/1, get_character_instance/1, + get_character_instance_ix/1, set_battle/2, set_character_instance/2 @@ -71,6 +72,9 @@ get_battle (Data) -> Data#type.battle. -spec get_character_instance (type()) -> character_instance:type(). get_character_instance (Data) -> Data#type.character_instance. +-spec get_character_instance_ix (type()) -> non_neg_integer(). +get_character_instance_ix (Data) -> Data#type.character_instance_ix. + -spec set_battle (battle:type(), type()) -> type(). set_battle (Battle, Data) -> Data#type{ battle = Battle }. diff --git a/src/battlemap/src/struct/character_turn_request.erl b/src/battlemap/src/struct/character_turn_request.erl index 8c816d9..1cfb212 100644 --- a/src/battlemap/src/struct/character_turn_request.erl +++ b/src/battlemap/src/struct/character_turn_request.erl @@ -17,7 +17,7 @@ session_token :: binary(), battle_id :: binary(), character_instance_ix :: non_neg_integer(), - actions :: list(battle_action:struct()) + actions :: list(battle_action:type()) } ). @@ -80,5 +80,5 @@ get_battle_id (Request) -> Request#type.battle_id. -spec get_character_instance_ix (type()) -> non_neg_integer(). get_character_instance_ix (Request) -> Request#type.character_instance_ix. --spec get_actions (type()) -> list(battle_action:struct()). +-spec get_actions (type()) -> list(battle_action:type()). get_actions (Request) -> Request#type.actions. diff --git a/src/battlemap/src/struct/player.erl b/src/battlemap/src/struct/player.erl index c4aefd1..04939cb 100644 --- a/src/battlemap/src/struct/player.erl +++ b/src/battlemap/src/struct/player.erl @@ -14,7 +14,7 @@ } ). --opaque struct() :: #player{}. +-opaque type() :: #player{}. -export_type([struct/0, id/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -44,13 +44,13 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec get_id (struct()) -> id(). +-spec get_id (type()) -> id(). get_id (Player) -> Player#player.id. --spec get_timeline (struct()) -> list(any()). +-spec get_timeline (type()) -> list(any()). get_timeline (Player) -> Player#player.timeline. --spec add_to_timeline (list(any()), struct()) -> struct(). +-spec add_to_timeline (list(any()), type()) -> type(). add_to_timeline (NewEvents, Player) -> OldTimeline = Player#player.timeline, @@ -59,10 +59,10 @@ add_to_timeline (NewEvents, Player) -> timeline = (NewEvents ++ OldTimeline) }. --spec reset_timeline (struct()) -> struct(). +-spec reset_timeline (type()) -> type(). reset_timeline (Player) -> Player#player{ timeline = [] }. --spec new (id()) -> struct(). +-spec new (id()) -> type(). new (ID) -> #player { diff --git a/src/battlemap/src/struct/statistics.erl b/src/battlemap/src/struct/statistics.erl index 6e29ea4..b1e88b8 100644 --- a/src/battlemap/src/struct/statistics.erl +++ b/src/battlemap/src/struct/statistics.erl @@ -19,7 +19,7 @@ } ). --opaque struct() :: #statistics{}. +-opaque type() :: #statistics{}. -export_type([struct/0]). @@ -110,34 +110,34 @@ apply_damage_base_modifier (Modifier, BaseValue) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_movement_points (struct()) -> non_neg_integer(). +-spec get_movement_points (type()) -> non_neg_integer(). get_movement_points (Stats) -> Stats#statistics.movement_points. --spec get_health (struct()) -> non_neg_integer(). +-spec get_health (type()) -> non_neg_integer(). get_health (Stats) -> Stats#statistics.health. --spec get_dodges (struct()) -> non_neg_integer(). +-spec get_dodges (type()) -> non_neg_integer(). get_dodges (Stats) -> Stats#statistics.dodges. --spec get_parries (struct()) -> non_neg_integer(). +-spec get_parries (type()) -> non_neg_integer(). get_parries (Stats) -> Stats#statistics.parries. --spec get_damage_min (struct()) -> non_neg_integer(). +-spec get_damage_min (type()) -> non_neg_integer(). get_damage_min (Stats) -> Stats#statistics.damage_min. --spec get_damage_max (struct()) -> non_neg_integer(). +-spec get_damage_max (type()) -> non_neg_integer(). get_damage_max (Stats) -> Stats#statistics.damage_max. --spec get_accuracy (struct()) -> non_neg_integer(). +-spec get_accuracy (type()) -> non_neg_integer(). get_accuracy (Stats) -> Stats#statistics.accuracy. --spec get_double_hits (struct()) -> non_neg_integer(). +-spec get_double_hits (type()) -> non_neg_integer(). get_double_hits (Stats) -> Stats#statistics.double_hits. --spec get_critical_hits (struct()) -> non_neg_integer(). +-spec get_critical_hits (type()) -> non_neg_integer(). get_critical_hits (Stats) -> Stats#statistics.critical_hits. --spec get_damages (struct()) -> {non_neg_integer(), non_neg_integer()}. +-spec get_damages (type()) -> {non_neg_integer(), non_neg_integer()}. get_damages (Stats) -> { Stats#statistics.damage_min, @@ -146,10 +146,10 @@ get_damages (Stats) -> -spec new ( - attributes:struct(), + attributes:type(), {weapon:id(), weapon:id()} ) - -> struct(). + -> type(). new (BaseAttributes, WeaponIDs) -> {ActiveWeaponID, _} = WeaponIDs, ActiveWeapon = weapon:from_id(ActiveWeaponID), diff --git a/src/battlemap/src/struct/tile.erl b/src/battlemap/src/struct/tile.erl index e86da56..aea139e 100644 --- a/src/battlemap/src/struct/tile.erl +++ b/src/battlemap/src/struct/tile.erl @@ -4,7 +4,7 @@ %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -opaque id() :: non_neg_integer(). --opaque struct() :: id(). +-opaque type() :: id(). -export_type([struct/0, id/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/battlemap/src/struct/turn_result.erl b/src/battlemap/src/struct/turn_result.erl index 5f796ca..797c8ca 100644 --- a/src/battlemap/src/struct/turn_result.erl +++ b/src/battlemap/src/struct/turn_result.erl @@ -28,11 +28,11 @@ { attacker_ix :: character_instance:id(), defender_ix :: character_instance:id(), - sequence :: list(attack:struct()) + sequence :: list(attack:type()) } ). --opaque struct() :: (#switched_weapon{} | #moved{} | #attacked{}). +-opaque type() :: (#switched_weapon{} | #moved{} | #attacked{}). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -62,7 +62,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec new_character_switched_weapons (character_instance:id()) -> struct(). +-spec new_character_switched_weapons (character_instance:id()) -> type(). new_character_switched_weapons (CharacterInstanceIX) -> #switched_weapon { character_instance_ix = CharacterInstanceIX }. @@ -72,7 +72,7 @@ new_character_switched_weapons (CharacterInstanceIX) -> list(direction:enum()), location:type() ) - -> struct(). + -> type(). new_character_moved (CharacterInstanceIX, Path, NewLocation) -> #moved { @@ -85,9 +85,9 @@ new_character_moved (CharacterInstanceIX, Path, NewLocation) -> ( character_instance:id(), character_instance:id(), - list(attack:struct()) + list(attack:type()) ) - -> struct(). + -> type(). new_character_attacked (AttackerIX, DefenderIX, AttackSequence) -> #attacked { @@ -96,7 +96,7 @@ new_character_attacked (AttackerIX, DefenderIX, AttackSequence) -> sequence = AttackSequence }. --spec encode (struct()) -> {list(any())}. +-spec encode (type()) -> {list(any())}. encode (TurnResult) when is_record(TurnResult, switched_weapon) -> CharacterInstanceIX = TurnResult#switched_weapon.character_instance_ix, diff --git a/src/battlemap/src/struct/weapon.erl b/src/battlemap/src/struct/weapon.erl index 80cb925..fa348a0 100644 --- a/src/battlemap/src/struct/weapon.erl +++ b/src/battlemap/src/struct/weapon.erl @@ -23,7 +23,7 @@ } ). --opaque struct() :: #weapon{}. +-opaque type() :: #weapon{}. -export_type([struct/0, id/0]). -export_type @@ -89,24 +89,24 @@ damages_of_type (melee, light) -> {15, 30}. %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_id (struct()) -> id(). +-spec get_id (type()) -> id(). get_id (Wp) -> Wp#weapon.id. --spec get_range_type (struct()) -> range_type(). +-spec get_range_type (type()) -> range_type(). get_range_type (Wp) -> Wp#weapon.range_type. --spec get_ranges (struct()) -> {non_neg_integer(), non_neg_integer()}. +-spec get_ranges (type()) -> {non_neg_integer(), non_neg_integer()}. get_ranges (Wp) -> ranges_of_type(Wp#weapon.range_type, Wp#weapon.range_mod). --spec get_damages (struct()) -> {non_neg_integer(), non_neg_integer()}. +-spec get_damages (type()) -> {non_neg_integer(), non_neg_integer()}. get_damages (Wp) -> damages_of_type(Wp#weapon.range_type, Wp#weapon.damage_mod). --spec can_parry (struct()) -> boolean(). +-spec can_parry (type()) -> boolean(). can_parry (Wp) -> (Wp#weapon.range_type == melee). --spec from_id (id()) -> struct(). +-spec from_id (id()) -> type(). from_id (0) -> #weapon{ id = 0, @@ -338,10 +338,10 @@ random_id () -> roll:between(0, 24). -spec apply_to_attributes ( - attributes:struct(), - weapon:struct() + attributes:type(), + weapon:type() ) - -> attributes:struct(). + -> attributes:type(). apply_to_attributes (Attributes, Weapon) -> Dexterity = attributes:get_dexterity(Attributes), Speed = attributes:get_speed(Attributes), |