aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-09-10 21:44:45 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-09-10 21:44:45 +0200
commit37be15261c35d732e6a254b75b77654ad0ad9d97 (patch)
tree34102799ff0f16982d3b7b4c87f5f1b6a4bdd923
parentcfdd37c261bfb814740aa8cec30177f9c5f85d36 (diff)
downloadtacticians-server-37be15261c35d732e6a254b75b77654ad0ad9d97.zip
tacticians-server-37be15261c35d732e6a254b75b77654ad0ad9d97.tar.bz2
Transforms some "assert" into error throws.
-rw-r--r--src/battle/mechanic/action/btl_action_attack.erl5
-rw-r--r--src/battle/mechanic/action/btl_action_move.erl10
-rw-r--r--src/battle/query/btl_character_turn.erl29
-rw-r--r--src/battle/struct/btl_turn_result.erl3
-rw-r--r--src/login/query/lgn_sign_in.erl5
-rw-r--r--src/map/query/map_update.erl18
-rw-r--r--src/shared/struct/map/shr_location.erl6
7 files changed, 57 insertions, 19 deletions
diff --git a/src/battle/mechanic/action/btl_action_attack.erl b/src/battle/mechanic/action/btl_action_attack.erl
index ef4d9d3..8dc9d5c 100644
--- a/src/battle/mechanic/action/btl_action_attack.erl
+++ b/src/battle/mechanic/action/btl_action_attack.erl
@@ -108,7 +108,10 @@ get_character_abilities (Action, Character, TargetCharacter) ->
btl_character:get_location(TargetCharacter)
),
- true = (AttackRange >= RequiredRange),
+ case (AttackRange >= RequiredRange) of
+ true -> ok;
+ _ -> error({attack, range, AttackRange, RequiredRange})
+ end,
{
(DefenseRange == 0),
diff --git a/src/battle/mechanic/action/btl_action_move.erl b/src/battle/mechanic/action/btl_action_move.erl
index ebc79db..97cec25 100644
--- a/src/battle/mechanic/action/btl_action_move.erl
+++ b/src/battle/mechanic/action/btl_action_move.erl
@@ -191,7 +191,10 @@ cross
NextRemainingStepsCount = (RemainingStepsCount - 1),
IsForbidden = sets:is_element(NextLocation, ForbiddenLocations),
- false = IsForbidden,
+ case IsForbidden of
+ true -> error({forbidden, tile, NextLocation});
+ false -> ok
+ end,
{NextAttacksOfOpportunityCandidates, Attackers} =
detect_attacks_of_opportunity
@@ -461,7 +464,10 @@ handle (Action, Character, S0Update) ->
MovementPoints = get_movement_points(Action, Character),
- true = (MovementPoints >= PathCost),
+ case (MovementPoints >= PathCost) of
+ true -> ok;
+ _ -> error({movement, MovementPoints, PathCost})
+ end,
% [FIXME][IMPORTANT]: 'Path' will not be correct if there is an interruption.
S1Update =
diff --git a/src/battle/query/btl_character_turn.erl b/src/battle/query/btl_character_turn.erl
index 4f96552..9534945 100644
--- a/src/battle/query/btl_character_turn.erl
+++ b/src/battle/query/btl_character_turn.erl
@@ -65,9 +65,18 @@ assert_user_is_current_player (Update, Request) ->
CurrentPlayerIX = btl_player_turn:get_player_ix(CurrentPlayerTurn),
CurrentPlayer = btl_battle:get_player(CurrentPlayerIX, Battle),
- true = (PlayerID == btl_player:get_id(CurrentPlayer)),
-
- ok.
+ case (PlayerID == btl_player:get_id(CurrentPlayer)) of
+ true -> ok;
+ _ ->
+ error
+ (
+ {
+ player_id,
+ btl_player:get_id(CurrentPlayer),
+ PlayerID
+ }
+ )
+ end.
-spec assert_user_owns_played_character
(
@@ -83,9 +92,10 @@ assert_user_owns_played_character (Update, Request) ->
CharacterPlayer = btl_battle:get_player(CharacterPlayerIX, Battle),
CharacterPlayerID = btl_player:get_id(CharacterPlayer),
- true = (PlayerID == CharacterPlayerID),
-
- ok.
+ case (PlayerID == CharacterPlayerID) of
+ true -> ok;
+ _ -> error({player_id, CharacterPlayerID, PlayerID})
+ end.
-spec assert_character_can_be_played (btl_character_turn_update:type()) -> 'ok'.
assert_character_can_be_played (Update) ->
@@ -93,9 +103,10 @@ assert_character_can_be_played (Update) ->
CharacterIX = btl_character_turn_update:get_character_ix(Update),
Character = btl_battle:get_character(CharacterIX, Battle),
- true = btl_character:get_is_active(Character),
-
- ok.
+ case btl_character:get_is_active(Character) of
+ true -> ok;
+ _ -> error({character, active, CharacterIX})
+ end.
-spec assert_user_permissions
(
diff --git a/src/battle/struct/btl_turn_result.erl b/src/battle/struct/btl_turn_result.erl
index af1fded..eaf974b 100644
--- a/src/battle/struct/btl_turn_result.erl
+++ b/src/battle/struct/btl_turn_result.erl
@@ -228,5 +228,4 @@ encode (TurnResult) when is_record(TurnResult, player_turn_started) ->
]
};
encode (Other) ->
- io:format("~n invalid encode param\"~p\"~n", [Other]),
- true = Other.
+ error(io_lib:format("~n invalid encode param\"~p\"~n", [Other])).
diff --git a/src/login/query/lgn_sign_in.erl b/src/login/query/lgn_sign_in.erl
index 83d2e5f..89801b1 100644
--- a/src/login/query/lgn_sign_in.erl
+++ b/src/login/query/lgn_sign_in.erl
@@ -64,7 +64,10 @@ update_data (QueryState, Input) ->
InputPassword = Input#input.password,
Player = QueryState#query_state.player,
- true = (shr_player:password_is(InputPassword, Player)),
+ case shr_player:password_is(InputPassword, Player) of
+ true -> error({password, QueryState#query_state.player_id});
+ _ -> ok
+ end,
S0Player = shr_player:new_token(Player),
S1Player = shr_player:refresh_active(S0Player),
diff --git a/src/map/query/map_update.erl b/src/map/query/map_update.erl
index ffdb37b..fbe9203 100644
--- a/src/map/query/map_update.erl
+++ b/src/map/query/map_update.erl
@@ -46,9 +46,21 @@ parse_input (Query) ->
EncodedMapContent = maps:get(<<"t">>, JSONReqMap),
%% TODO [LOW]: those checks should be done while queries are locked.
- true = (MapWidth > 0),
- true = (MapHeight > 0),
- true = (length(EncodedMapContent) == (MapWidth * MapHeight)),
+ if
+ (MapWidth =< 0) -> error({map, width, MapWidth});
+ (MapHeight =< 0) -> error({map, height, MapHeight});
+ (length(EncodedMapContent) =/= (MapWidth * MapHeight)) ->
+ error
+ (
+ {
+ map,
+ content_size,
+ (MapWidth * MapHeight),
+ length(EncodedMapContent)
+ }
+ );
+ true -> ok
+ end,
MapContent = lists:map(fun shr_tile_instance:decode/1, EncodedMapContent),
diff --git a/src/shared/struct/map/shr_location.erl b/src/shared/struct/map/shr_location.erl
index e7d4432..f980134 100644
--- a/src/shared/struct/map/shr_location.erl
+++ b/src/shared/struct/map/shr_location.erl
@@ -86,7 +86,11 @@ decode (Map) ->
X = maps:get(<<"x">>, Map),
Y = maps:get(<<"y">>, Map),
- true = (is_integer(X) and is_integer(Y)),
+ if
+ (not is_integer(X)) -> error({map, width, X});
+ (not is_integer(Y)) -> error({map, height, Y});
+ true -> ok
+ end,
validate({X, Y}).