summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/battle/struct/btl_battle_action.erl43
-rw-r--r--src/battle/struct/btl_character_turn_request.erl16
-rw-r--r--src/bounty/bnt_join_battle.erl12
3 files changed, 37 insertions, 34 deletions
diff --git a/src/battle/struct/btl_battle_action.erl b/src/battle/struct/btl_battle_action.erl
index 66c8304..5d42536 100644
--- a/src/battle/struct/btl_battle_action.erl
+++ b/src/battle/struct/btl_battle_action.erl
@@ -37,7 +37,9 @@
-export
(
[
- decode/1,
+ maybe_decode_move/1,
+ maybe_decode_weapon_switch/1,
+ maybe_decode_attack/1,
can_follow/2
]
).
@@ -54,35 +56,24 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec decode_mov_action (map()) -> type().
-decode_mov_action (JSONMap) ->
- PathInBinary = maps:get(<<"p">>, JSONMap),
- Path = lists:map(fun btl_direction:decode/1, PathInBinary),
-
- #move { path = Path }.
-
--spec decode_atk_action (map()) -> type().
-decode_atk_action (JSONMap) ->
- TargetIX = maps:get(<<"tix">>, JSONMap),
-
- #attack { target_ix = TargetIX }.
-
--spec decode_swp_action (map()) -> type().
-decode_swp_action (_JSONMap) ->
- #switch_weapon{}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec decode (map()) -> type().
-decode (EncodedAction) ->
- JSONActionMap = EncodedAction, %jiffy:decode(EncodedAction, [return_maps]),
- ActionType = maps:get(<<"t">>, JSONActionMap),
- case ActionType of
- <<"mov">> -> decode_mov_action(JSONActionMap);
- <<"atk">> -> decode_atk_action(JSONActionMap);
- <<"swp">> -> decode_swp_action(JSONActionMap)
- end.
+-spec maybe_decode_move (list(btl_direction:type())) -> list(type()).
+maybe_decode_move ([]) -> [];
+maybe_decode_move (PathInBinary) ->
+ Path = lists:map(fun btl_direction:decode/1, PathInBinary),
+
+ [#move { path = Path }].
+
+-spec maybe_decode_attack (integer()) -> list(type()).
+maybe_decode_attack (TargetIX) when (TargetIX < 0) -> [];
+maybe_decode_attack (TargetIX) -> [#attack { target_ix = TargetIX }].
+
+-spec maybe_decode_weapon_switch (boolean()) -> list(type()).
+maybe_decode_weapon_switch (false) -> [];
+maybe_decode_weapon_switch (true) -> [#switch_weapon{}].
-spec can_follow (category(), category()) -> boolean().
can_follow (nothing, attack) -> true;
diff --git a/src/battle/struct/btl_character_turn_request.erl b/src/battle/struct/btl_character_turn_request.erl
index e26f79c..faf8d07 100644
--- a/src/battle/struct/btl_character_turn_request.erl
+++ b/src/battle/struct/btl_character_turn_request.erl
@@ -6,8 +6,8 @@
-define(CHAR_IX_FIELD, <<"cix">>).
-define(ACTIONS_FIELD, <<"act">>).
-define(ACTIONS_MOVE_FIELD, <<"mov">>).
--define(ACTIONS_WPS_FIELD, <<"wps">>).
--define(ACTIONS_ATK_FIELD, <<"tar">>).
+-define(ACTIONS_WEAPON_SWITCH_FIELD, <<"wps">>).
+-define(ACTIONS_ATTACK_FIELD, <<"tar">>).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -65,7 +65,10 @@ decode_actions (Act) ->
S2Result =
case
- btl_battle_action:maybe_decode_atk(maps:get(?ACTIONS_ATK_FIELD, Act))
+ btl_battle_action:maybe_decode_attack
+ (
+ maps:get(?ACTIONS_ATTACK_FIELD, Act)
+ )
of
[] -> S1Result;
[Atk] -> [Atk|S1Result]
@@ -73,13 +76,16 @@ decode_actions (Act) ->
S3Result =
case
- btl_battle_action:maybe_decode_move(maps:get(?ACTIONS_WPS_FIELD, Act))
+ btl_battle_action:maybe_decode_weapon_switch
+ (
+ maps:get(?ACTIONS_WEAPON_SWITCH_FIELD, Act)
+ )
of
[] -> S2Result;
[Wps] -> [Wps|S2Result]
end,
- S3Result.
+ lists:reverse(S3Result).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/bounty/bnt_join_battle.erl b/src/bounty/bnt_join_battle.erl
index eae0c98..63b57df 100644
--- a/src/bounty/bnt_join_battle.erl
+++ b/src/bounty/bnt_join_battle.erl
@@ -612,8 +612,14 @@ repair_create_battle
(
[
ataxic:update_value(ataxic:constant(NewPendingBattle)),
- ataxic:update_read_permission(ataxia_security:allow_any()),
- ataxic:update_write_permission(ataxia_security:allow_any())
+ ataxic:update_read_permission
+ (
+ ataxic:constant(ataxia_security:allow_any())
+ ),
+ ataxic:update_write_permission
+ (
+ ataxic:constant(ataxia_security:allow_any())
+ )
]
),
PBattleID
@@ -823,7 +829,7 @@ repair_battle_final_links (PendingBattleID, BattleID, Battle) ->
true =
lists:all
(
- fun (Player) ->
+ fun ({_, Player}) ->
(repair_battle_final_link_of_player(BattleID, Player) == ok)
end,
orddict:to_list(Players)