| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/battle/mechanic/action/btl_action_skill.erl | 30 | ||||
| -rw-r--r-- | src/battle/mechanic/btl_actions_management.erl | 1 | ||||
| -rw-r--r-- | src/battle/struct/btl_action.erl | 84 | ||||
| -rw-r--r-- | src/battle/struct/btl_character_turn_request.erl | 27 | 
4 files changed, 123 insertions, 19 deletions
diff --git a/src/battle/mechanic/action/btl_action_skill.erl b/src/battle/mechanic/action/btl_action_skill.erl new file mode 100644 index 0000000..548eafe --- /dev/null +++ b/src/battle/mechanic/action/btl_action_skill.erl @@ -0,0 +1,30 @@ +-module(btl_action_skill). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-include("tacticians/conditions.hrl"). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( +   [ +      handle/2 +   ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec handle +   ( +      btl_action:type(), +      btl_character_turn_update:type() +   ) +   -> btl_character_turn_update:type(). +handle (_Action, S0Update) -> S0Update. % TODO diff --git a/src/battle/mechanic/btl_actions_management.erl b/src/battle/mechanic/btl_actions_management.erl index d7b85c5..a3f9365 100644 --- a/src/battle/mechanic/btl_actions_management.erl +++ b/src/battle/mechanic/btl_actions_management.erl @@ -30,6 +30,7 @@ handle (S0Update) ->              case btl_action:get_category(Action) of                 move -> btl_action_move:handle(Action, S1Update);                 attack -> btl_action_attack:handle(Action, S1Update); +               skill -> btl_action_skill:handle(Action, S1Update);                 switch_weapon ->                    btl_action_switch_weapon:handle(Action, S1Update)              end, diff --git a/src/battle/struct/btl_action.erl b/src/battle/struct/btl_action.erl index 4940456..7feb986 100644 --- a/src/battle/struct/btl_action.erl +++ b/src/battle/struct/btl_action.erl @@ -31,11 +31,22 @@     }  ). +-record +( +   skill, +   { +      actor_ix :: non_neg_integer(), +      targets :: list(non_neg_integer()), +      locations :: list(shr_location:type()) +   } +). +  -type category() ::     (        'move'        | 'switch_weapon'        | 'attack' +      | 'skill'        | 'nothing'     ). @@ -44,6 +55,7 @@        #move{}        | #switch_weapon{}        | #attack{} +      | #skill{}     ).  -export_type([category/0, type/0]). @@ -58,6 +70,7 @@        maybe_decode_move/2,        maybe_decode_weapon_switch/2,        maybe_decode_attack/2, +      maybe_decode_skill/2,        can_follow/2     ]  ). @@ -67,6 +80,7 @@     [        new_move/3,        new_attack/2, +      new_skill/3,        new_attack_of_opportunity/2     ]  ). @@ -79,6 +93,8 @@        get_movement_points/1,        get_target_index/1,        get_actor_index/1, +      get_target_indices/1, +      get_locations/1,        get_category/1     ]  ). @@ -95,53 +111,69 @@        non_neg_integer(),        list(shr_direction:type())     ) -   -> list(type()). -maybe_decode_move (_CharacterIX, []) -> []; +   -> ({ok, type()} | none). +maybe_decode_move (_CharacterIX, []) -> none;  maybe_decode_move (CharacterIX, PathInBinary) ->     Path = lists:map(fun shr_direction:decode/1, PathInBinary), -   [ +   { +      ok,        #move        {           actor_ix = CharacterIX,           path = Path,           movement_points = -1        } -   ]. +   }.  -spec maybe_decode_attack     (        non_neg_integer(),        integer()     ) -   -> list(type()). -maybe_decode_attack (_CharacterIX, TargetIX) when (TargetIX < 0) -> []; +   -> ({ok, type()} | none). +maybe_decode_attack (_CharacterIX, TargetIX) when (TargetIX < 0) -> none;  maybe_decode_attack (CharacterIX, TargetIX) -> -   [ +   { +      ok,        #attack        {           actor_ix = CharacterIX,           target_ix = TargetIX,           is_opportunistic = false        } -   ]. +   }.  -spec maybe_decode_weapon_switch     (        non_neg_integer(),        boolean()     ) -   -> list(type()). -maybe_decode_weapon_switch (_CharacterIX, false) -> []; +   -> ({ok, type()} | none). +maybe_decode_weapon_switch (_CharacterIX, false) -> none;  maybe_decode_weapon_switch (CharacterIX, true) -> -   [#switch_weapon{ actor_ix = CharacterIX }]. +   {ok, #switch_weapon{ actor_ix = CharacterIX }}. + +-spec maybe_decode_skill (non_neg_integer(), any()) -> ({ok, type()} | none). +maybe_decode_skill (_CharacterIX, what) -> none; +maybe_decode_skill (CharacterIX, _) -> +   % TODO +   { +      ok, +      #skill +      { +         actor_ix = CharacterIX +      } +   }.  -spec can_follow (category(), category()) -> boolean().  can_follow (nothing, attack) -> true;  can_follow (nothing, switch_weapon) -> true;  can_follow (nothing, move) -> true; +can_follow (nothing, skill) -> true;  can_follow (move, switch_weapon) -> true;  can_follow (move, attack) -> true; +can_follow (move, skill) -> true;  can_follow (_, _) -> false.  -spec get_path (type()) -> list(shr_direction:type()). @@ -159,6 +191,16 @@ get_target_index (Action) when is_record(Action, attack) ->     Action#attack.target_ix;  get_target_index (_) -> -1. +-spec get_target_indices (type()) -> list(non_neg_integer()). +get_target_indices (Action) when is_record(Action, skill) -> +   Action#skill.targets; +get_target_indices (_) -> []. + +-spec get_locations (type()) -> list(shr_location:type()). +get_locations (Action) when is_record(Action, skill) -> +   Action#skill.locations; +get_locations (_) -> []. +  -spec get_actor_index (type()) -> (non_neg_integer() | -1).  get_actor_index (Action) when is_record(Action, attack) ->     Action#attack.actor_ix; @@ -166,6 +208,8 @@ get_actor_index (Action) when is_record(Action, move) ->     Action#move.actor_ix;  get_actor_index (Action) when is_record(Action, switch_weapon) ->     Action#switch_weapon.actor_ix; +get_actor_index (Action) when is_record(Action, skill) -> +   Action#skill.actor_ix;  get_actor_index (_) ->     -1. @@ -212,10 +256,26 @@ new_attack (ActorIX, TargetIX) ->        is_opportunistic = false     }. +-spec new_skill +   ( +      non_neg_integer(), +      list(non_neg_integer()), +      list(shr_location:type()) +   ) +   -> type(). +new_skill (ActorIX, Targets, Locations) -> +   #skill +   { +      actor_ix = ActorIX, +      targets = Targets, +      locations = Locations +   }. +  -spec get_category (type()) -> category().  get_category (Action) when is_record(Action, attack) -> attack;  get_category (Action) when is_record(Action, move) -> move; -get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon. +get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon; +get_category (Action) when is_record(Action, skill) -> skill.  -spec from_map_marker     ( diff --git a/src/battle/struct/btl_character_turn_request.erl b/src/battle/struct/btl_character_turn_request.erl index 7d53bcd..3596b4b 100644 --- a/src/battle/struct/btl_character_turn_request.erl +++ b/src/battle/struct/btl_character_turn_request.erl @@ -7,6 +7,7 @@  -define(ACTIONS_FIELD, <<"act">>).  -define(ACTIONS_MOVE_FIELD, <<"mov">>).  -define(ACTIONS_WEAPON_SWITCH_FIELD, <<"wps">>). +-define(ACTIONS_SKILL_FIELD, <<"skl">>).  -define(ACTIONS_ATTACK_FIELD, <<"tar">>).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -63,8 +64,8 @@ decode_actions (CharacterIX, Act) ->              maps:get(?ACTIONS_MOVE_FIELD, Act)           )        of -         [] -> S0Result; -         [Move] -> [Move|S0Result] +         {ok, Move} -> [Move|S0Result]; +         none -> S0Result        end,     S2Result = @@ -75,8 +76,8 @@ decode_actions (CharacterIX, Act) ->              maps:get(?ACTIONS_ATTACK_FIELD, Act)           )        of -         [] -> S1Result; -         [Atk] -> [Atk|S1Result] +         {ok, Atk} -> [Atk|S1Result]; +         none -> S1Result        end,     S3Result = @@ -87,11 +88,23 @@ decode_actions (CharacterIX, Act) ->              maps:get(?ACTIONS_WEAPON_SWITCH_FIELD, Act)           )        of -         [] -> S2Result; -         [Wps] -> [Wps|S2Result] +         {ok, Wps} -> [Wps|S2Result]; +         none -> S2Result        end, -   lists:reverse(S3Result). +   S4Result = +      case +         btl_action:maybe_decode_skill +         ( +            CharacterIX, +            maps:get(?ACTIONS_SKILL_FIELD, Act) +         ) +      of +         {ok, Skill} -> [Skill|S3Result]; +         none -> S3Result +      end, + +   lists:reverse(S4Result).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 


