summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-01-18 15:10:19 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-01-18 15:10:19 +0100 |
commit | a38766a1b008347df932d7578aa99ae1ef30b4fd (patch) | |
tree | f8598da649ecc95c6bafeabb11a5ad8fa260ffa3 /src/battle | |
parent | bd380fa5fdb604bf07bc7b58b79b3abc04147b4a (diff) |
Looks like there are still issues with DB updates.
Switching weapons does not work.
In the little test I did, only one of their character got activated once
the second player's turn started.
Diffstat (limited to 'src/battle')
-rw-r--r-- | src/battle/struct/btl_battle_action.erl | 43 | ||||
-rw-r--r-- | src/battle/struct/btl_character_turn_request.erl | 16 |
2 files changed, 28 insertions, 31 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |