From 95f112f827ffef5605c384b86a9d718c74e9bbbc Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 27 Oct 2019 21:14:25 +0100 Subject: ... --- Makefile | 3 +- include/tacticians/conditions.hrl | 8 +- src/battle/mechanic/action/btl_action_skill.erl | 139 --------------------- .../mechanic/action/btl_action_switch_weapon.erl | 118 ----------------- .../mechanic/action/btl_action_switch_weapons.erl | 118 +++++++++++++++++ .../mechanic/action/btl_action_use_skill.erl | 139 +++++++++++++++++++++ src/battle/mechanic/btl_actions_management.erl | 6 +- .../mechanic/skill/btl_skill_static_heal.erl | 8 +- src/battle/struct/btl_action.erl | 132 ++++++++++--------- src/battle/struct/btl_character_turn_request.erl | 89 +++++-------- src/battle/struct/btl_condition.erl | 63 ++++++++-- 11 files changed, 415 insertions(+), 408 deletions(-) delete mode 100644 src/battle/mechanic/action/btl_action_skill.erl delete mode 100644 src/battle/mechanic/action/btl_action_switch_weapon.erl create mode 100644 src/battle/mechanic/action/btl_action_switch_weapons.erl create mode 100644 src/battle/mechanic/action/btl_action_use_skill.erl diff --git a/Makefile b/Makefile index 3fccb34..b14b123 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ run_db_node: build $(ERL_EXEC) $(ERL_NAME_VS_SNAME) db_node -run db_node start run_query_node: build $(YAWS_CONFIG_FILE) - $(YAWS_EXEC) --conf $(YAWS_CONFIG_FILE) + $(YAWS_EXEC) --conf $(YAWS_CONFIG_FILE) clean: # Preprocessor @@ -152,6 +152,7 @@ $(PREPROCESSED_FILES): %: %.m4 .PHONY $(OPTIONAL_DIRS): %: mkdir -p $@ +# [TODO][IMPORTANT] Handle 'include' directives. $(ERL_BIN_FILES): $(BIN_DIR)/%.beam: $(SRC_DIR)/%.erl mkdir -p $(dir $@) $(ERLC_EXEC) -o $(dir $@) $< diff --git a/include/tacticians/conditions.hrl b/include/tacticians/conditions.hrl index cc27972..3558732 100644 --- a/include/tacticians/conditions.hrl +++ b/include/tacticians/conditions.hrl @@ -54,8 +54,8 @@ -define(CONDITION_TRIGGER_HAS_SWITCHED_WEAPONS, hsw). -define(CONDITION_TRIGGER_A_CHARACTER_HAS_SWITCHED_WEAPONS, achsw). --define(CONDITION_TRIGGER_ABOUT_TO_CAST_SKILL, atcs). --define(CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_CAST_SKILL, aciatcs). +-define(CONDITION_TRIGGER_ABOUT_TO_USE_THEIR_SKILL, atcs). +-define(CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_USE_THEIR_SKILL, aciatcs). --define(CONDITION_TRIGGER_HAS_CAST_SKILL, hcs). --define(CONDITION_TRIGGER_A_CHARACTER_HAS_CAST_SKILL, achcs). +-define(CONDITION_TRIGGER_HAS_USED_THEIR_SKILL, hcs). +-define(CONDITION_TRIGGER_A_CHARACTER_HAS_USED_THEIR_SKILL, achcs). diff --git a/src/battle/mechanic/action/btl_action_skill.erl b/src/battle/mechanic/action/btl_action_skill.erl deleted file mode 100644 index 7e6579b..0000000 --- a/src/battle/mechanic/action/btl_action_skill.erl +++ /dev/null @@ -1,139 +0,0 @@ --module(btl_action_skill). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --include("tacticians/conditions.hrl"). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - handle/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec pay_for_cast - ( - non_neg_integer(), - btl_character_turn_update:type() - ) - -> btl_character_turn_update:type(). -pay_for_cast (ActorIX, S0Update) -> - S0Battle = btl_character_turn_update:get_battle(S0Update), - S0Actor = btl_battle:get_character(ActorIX, S0Battle), - BaseActor = btl_character:get_base_character(S0Actor), - Equipment = shr_character:get_equipment(BaseActor), - Skill = shr_equipment:get_skill(Equipment), - - SkillCost = shr_skill:get_cost(Skill), - S0SkillPoints = btl_character:get_skill_points(S0Actor), - S1SkillPoints = (S0SkillPoints - SkillCost), - - {S1Actor, ActorAtaxiaUpdate} = - case (S1SkillPoints < 0) of - true -> error({skill, points, S0SkillPoints, Skill}); - false -> - btl_character:ataxia_set_skill_points(S1SkillPoints, S0Actor) - end, - - {S1Battle, BattleAtaxiaUpdate} = - btl_battle:ataxia_set_character - ( - ActorIX, - S1Actor, - ActorAtaxiaUpdate, - S0Battle - ), - - S1Update = - btl_character_turn:ataxia_set_battle - ( - S1Battle, - BattleAtaxiaUpdate, - S0Update - ), - - {S1Update, Skill}. - --spec cast_skill - ( - btl_action:type(), - btl_character_turn_update:type() - ) - -> btl_character_turn_update:type(). -cast_skill (Action, S0Update) -> - ActorIX = btl_action:get_actor_index(Action), - {S1Update, Skill} = pay_for_cast(ActorIX, S0Update), - - S2Update = - erlang:apply - ( - shr_skill:get_module(Skill), - cast, - [Skill, Action, S1Update] - ), - - {none, S3Update} = - btl_condition:apply_to_character - ( - ActorIX, - ?CONDITION_TRIGGER_HAS_CAST_SKILL, - Action, - none, - S2Update - ), - - {none, S3Update} = - btl_condition:apply_to_battle - ( - ?CONDITION_TRIGGER_A_CHARACTER_HAS_CAST_SKILL, - Action, - none, - S2Update - ), - - S3Update. - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec handle - ( - btl_action:type(), - btl_character_turn_update:type() - ) - -> btl_character_turn_update:type(). -handle (S0Action, S0Update) -> - ActorIX = btl_action:get_actor_index(S0Action), - - S0PerformAction = true, - - {{S1Action, S1PerformAction}, S1Update} = - btl_condition:apply_to_character - ( - ActorIX, - ?CONDITION_TRIGGER_ABOUT_TO_CAST_SKILL, - none, - {S0Action, S0PerformAction}, - S0Update - ), - - {{S2Action, S2PerformAction}, S2Update} = - btl_condition:apply_to_battle - ( - ?CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_CAST_SKILL, - none, - {S1Action, S1PerformAction}, - S1Update - ), - - case S2PerformAction of - true -> cast_skill(S2Action, S2Update); - false -> S2Update - end. diff --git a/src/battle/mechanic/action/btl_action_switch_weapon.erl b/src/battle/mechanic/action/btl_action_switch_weapon.erl deleted file mode 100644 index 10348bc..0000000 --- a/src/battle/mechanic/action/btl_action_switch_weapon.erl +++ /dev/null @@ -1,118 +0,0 @@ --module(btl_action_switch_weapon). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% 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) -> - % TODO: assert actor is alive. - ActorIX = btl_action:get_actor_index(Action), - - S0PerformSwitch = true, - - {S1PerformSwitch, S1Update} = - btl_condition:apply_to_character - ( - ActorIX, - ?CONDITION_TRIGGER_ABOUT_TO_SWITCH_WEAPONS, - Action, - S0PerformSwitch, - S0Update - ), - - {S2PerformSwitch, S2Update} = - btl_condition:apply_to_battle - ( - ?CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_SWITCH_WEAPONS, - Action, - S1PerformSwitch, - S1Update - ), - - case S2PerformSwitch of - false -> S2Update; - true -> - S0Battle = btl_character_turn_update:get_battle(S2Update), - {S0Actor, S1Battle} = - btl_battle:get_resolved_character(ActorIX, S0Battle), - - S0BaseActor = btl_character:get_base_character(S0Actor), - - {S1BaseActor, BaseActorAtaxicUpdate} = - shr_character:ataxia_switch_weapons(S0BaseActor), - - {S1Actor, ActorAtaxicUpdate} = - btl_character:ataxia_set_base_character - ( - S1BaseActor, - BaseActorAtaxicUpdate, - S0Actor - ), - - {S1Battle, BattleAtaxicUpdate} = - btl_battle:ataxia_set_character - ( - ActorIX, - S1Actor, - ActorAtaxicUpdate, - S0Battle - ), - - TimelineItem = - btl_turn_result:new_character_switched_weapons(ActorIX), - - S3Update = - btl_character_turn_update:add_to_timeline(TimelineItem, S2Update), - - S4Update = - btl_character_turn_update:ataxia_set_battle - ( - S1Battle, - BattleAtaxicUpdate, - S3Update - ), - - {_V0Nothing, S5Update} = - btl_condition:apply_to_character - ( - ActorIX, - ?CONDITION_TRIGGER_HAS_SWITCHED_WEAPONS, - Action, - none, - S4Update - ), - - {_V1Nothing, S6Update} = - btl_condition:apply_to_battle - ( - ?CONDITION_TRIGGER_A_CHARACTER_HAS_SWITCHED_WEAPONS, - Action, - none, - S5Update - ), - - S6Update - end. diff --git a/src/battle/mechanic/action/btl_action_switch_weapons.erl b/src/battle/mechanic/action/btl_action_switch_weapons.erl new file mode 100644 index 0000000..693c258 --- /dev/null +++ b/src/battle/mechanic/action/btl_action_switch_weapons.erl @@ -0,0 +1,118 @@ +-module(btl_action_switch_weapons). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% 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) -> + % TODO: assert actor is alive. + ActorIX = btl_action:get_actor_index(Action), + + S0PerformSwitch = true, + + {S1PerformSwitch, S1Update} = + btl_condition:apply_to_character + ( + ActorIX, + ?CONDITION_TRIGGER_ABOUT_TO_SWITCH_WEAPONS, + Action, + S0PerformSwitch, + S0Update + ), + + {S2PerformSwitch, S2Update} = + btl_condition:apply_to_battle + ( + ?CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_SWITCH_WEAPONS, + Action, + S1PerformSwitch, + S1Update + ), + + case S2PerformSwitch of + false -> S2Update; + true -> + S0Battle = btl_character_turn_update:get_battle(S2Update), + {S0Actor, S1Battle} = + btl_battle:get_resolved_character(ActorIX, S0Battle), + + S0BaseActor = btl_character:get_base_character(S0Actor), + + {S1BaseActor, BaseActorAtaxicUpdate} = + shr_character:ataxia_switch_weapons(S0BaseActor), + + {S1Actor, ActorAtaxicUpdate} = + btl_character:ataxia_set_base_character + ( + S1BaseActor, + BaseActorAtaxicUpdate, + S0Actor + ), + + {S1Battle, BattleAtaxicUpdate} = + btl_battle:ataxia_set_character + ( + ActorIX, + S1Actor, + ActorAtaxicUpdate, + S0Battle + ), + + TimelineItem = + btl_turn_result:new_character_switched_weapons(ActorIX), + + S3Update = + btl_character_turn_update:add_to_timeline(TimelineItem, S2Update), + + S4Update = + btl_character_turn_update:ataxia_set_battle + ( + S1Battle, + BattleAtaxicUpdate, + S3Update + ), + + {_V0Nothing, S5Update} = + btl_condition:apply_to_character + ( + ActorIX, + ?CONDITION_TRIGGER_HAS_SWITCHED_WEAPONS, + Action, + none, + S4Update + ), + + {_V1Nothing, S6Update} = + btl_condition:apply_to_battle + ( + ?CONDITION_TRIGGER_A_CHARACTER_HAS_SWITCHED_WEAPONS, + Action, + none, + S5Update + ), + + S6Update + end. diff --git a/src/battle/mechanic/action/btl_action_use_skill.erl b/src/battle/mechanic/action/btl_action_use_skill.erl new file mode 100644 index 0000000..154d7db --- /dev/null +++ b/src/battle/mechanic/action/btl_action_use_skill.erl @@ -0,0 +1,139 @@ +-module(btl_action_use_skill). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-include("tacticians/conditions.hrl"). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + handle/2 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec pay_for_cast + ( + non_neg_integer(), + btl_character_turn_update:type() + ) + -> {btl_character_turn_update:type(), shr_skill:type()}. +pay_for_cast (ActorIX, S0Update) -> + S0Battle = btl_character_turn_update:get_battle(S0Update), + S0Actor = btl_battle:get_character(ActorIX, S0Battle), + BaseActor = btl_character:get_base_character(S0Actor), + Equipment = shr_character:get_equipment(BaseActor), + Skill = shr_equipment:get_skill(Equipment), + + SkillCost = shr_skill:get_cost(Skill), + S0SkillPoints = btl_character:get_skill_points(S0Actor), + S1SkillPoints = (S0SkillPoints - SkillCost), + + {S1Actor, ActorAtaxiaUpdate} = + case (S1SkillPoints < 0) of + true -> error({skill, points, S0SkillPoints, Skill}); + false -> + btl_character:ataxia_set_skill_points(S1SkillPoints, S0Actor) + end, + + {S1Battle, BattleAtaxiaUpdate} = + btl_battle:ataxia_set_character + ( + ActorIX, + S1Actor, + ActorAtaxiaUpdate, + S0Battle + ), + + S1Update = + btl_character_turn_update:ataxia_set_battle + ( + S1Battle, + BattleAtaxiaUpdate, + S0Update + ), + + {S1Update, Skill}. + +-spec cast_skill + ( + btl_action:type(), + btl_character_turn_update:type() + ) + -> btl_character_turn_update:type(). +cast_skill (Action, S0Update) -> + ActorIX = btl_action:get_actor_index(Action), + {S1Update, Skill} = pay_for_cast(ActorIX, S0Update), + + S2Update = + erlang:apply + ( + shr_skill:get_module(Skill), + cast, + [Skill, Action, S1Update] + ), + + {none, S3Update} = + btl_condition:apply_to_character + ( + ActorIX, + ?CONDITION_TRIGGER_HAS_USED_THEIR_SKILL, + Action, + none, + S2Update + ), + + {none, S3Update} = + btl_condition:apply_to_battle + ( + ?CONDITION_TRIGGER_A_CHARACTER_HAS_USED_THEIR_SKILL, + Action, + none, + S2Update + ), + + S3Update. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec handle + ( + btl_action:type(), + btl_character_turn_update:type() + ) + -> btl_character_turn_update:type(). +handle (S0Action, S0Update) -> + ActorIX = btl_action:get_actor_index(S0Action), + + S0PerformAction = true, + + {{S1Action, S1PerformAction}, S1Update} = + btl_condition:apply_to_character + ( + ActorIX, + ?CONDITION_TRIGGER_ABOUT_TO_USE_THEIR_SKILL, + none, + {S0Action, S0PerformAction}, + S0Update + ), + + {{S2Action, S2PerformAction}, S2Update} = + btl_condition:apply_to_battle + ( + ?CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_USE_THEIR_SKILL, + none, + {S1Action, S1PerformAction}, + S1Update + ), + + case S2PerformAction of + true -> cast_skill(S2Action, S2Update); + false -> S2Update + end. diff --git a/src/battle/mechanic/btl_actions_management.erl b/src/battle/mechanic/btl_actions_management.erl index a3f9365..6305de7 100644 --- a/src/battle/mechanic/btl_actions_management.erl +++ b/src/battle/mechanic/btl_actions_management.erl @@ -30,9 +30,9 @@ 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) + skill -> btl_action_use_skill:handle(Action, S1Update); + switch_weapons -> + btl_action_switch_weapons:handle(Action, S1Update) end, handle(S2Update) diff --git a/src/battle/mechanic/skill/btl_skill_static_heal.erl b/src/battle/mechanic/skill/btl_skill_static_heal.erl index b1b7018..90d3154 100644 --- a/src/battle/mechanic/skill/btl_skill_static_heal.erl +++ b/src/battle/mechanic/skill/btl_skill_static_heal.erl @@ -10,7 +10,7 @@ -export ( [ - cast/5 + cast/3 ] ). @@ -24,11 +24,9 @@ -spec cast ( shr_skill:type(), - non_neg_integer(), - list(non_neg_integer()), - list(shr_location:type()), + btl_action:type(), btl_character_turn_update:type() ) -> btl_character_turn_update:type(). -cast (_Skill, _UserIX, _TargetIXs, _Locations, S0Update) -> +cast (_Skill, _Action, S0Update) -> S0Update. diff --git a/src/battle/struct/btl_action.erl b/src/battle/struct/btl_action.erl index 7feb986..71a9636 100644 --- a/src/battle/struct/btl_action.erl +++ b/src/battle/struct/btl_action.erl @@ -3,6 +3,19 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-define(CATEGORY_FIELD, <<"cat">>). +-define(CATEGORY_MOVE, <<"mov">>). +-define(CATEGORY_ATTACK, <<"atk">>). +-define(CATEGORY_SWITCH_WEAPONS, <<"swp">>). +-define(CATEGORY_USE_SKILL, <<"skl">>). + +-define(MOVE_PATH_FIELD, <<"pat">>). + +-define(ATTACK_TARGET_FIELD, <<"tar">>). + +-define(USE_SKILL_TARGETS_FIELD, <<"tar">>). +-define(USE_SKILL_LOCATIONS_FIELD, <<"loc">>). + -record ( move, @@ -15,7 +28,7 @@ -record ( - switch_weapon, + switch_weapons, { actor_ix :: non_neg_integer() } @@ -44,7 +57,7 @@ -type category() :: ( 'move' - | 'switch_weapon' + | 'switch_weapons' | 'attack' | 'skill' | 'nothing' @@ -53,7 +66,7 @@ -opaque type() :: ( #move{} - | #switch_weapon{} + | #switch_weapons{} | #attack{} | #skill{} ). @@ -67,10 +80,6 @@ ( [ from_map_marker/3, - maybe_decode_move/2, - maybe_decode_weapon_switch/2, - maybe_decode_attack/2, - maybe_decode_skill/2, can_follow/2 ] ). @@ -99,79 +108,63 @@ ] ). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + decode/2 + ] +). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec maybe_decode_move - ( - non_neg_integer(), - list(shr_direction:type()) - ) - -> ({ok, type()} | none). -maybe_decode_move (_CharacterIX, []) -> none; -maybe_decode_move (CharacterIX, PathInBinary) -> - Path = lists:map(fun shr_direction:decode/1, PathInBinary), +-spec decode (binary(), non_neg_integer(), map()) -> type(). +decode (?CATEGORY_MOVE, ActorIX, Map) -> + EncodedPath = map:get(?MOVE_PATH_FIELD, Map), + Path = lists:map(fun shr_direction:decode/1, EncodedPath), + #move { - ok, - #move - { - actor_ix = CharacterIX, - path = Path, - movement_points = -1 - } - }. + actor_ix = ActorIX, + path = Path, + movement_points = -1 + }; +decode (?CATEGORY_ATTACK, ActorIX, Map) -> + TargetIX = map:get(?ATTACK_TARGET_FIELD, Map), --spec maybe_decode_attack - ( - non_neg_integer(), - integer() - ) - -> ({ok, type()} | none). -maybe_decode_attack (_CharacterIX, TargetIX) when (TargetIX < 0) -> none; -maybe_decode_attack (CharacterIX, TargetIX) -> + #attack { - ok, - #attack - { - actor_ix = CharacterIX, - target_ix = TargetIX, - is_opportunistic = false - } - }. + actor_ix = ActorIX, + target_ix = TargetIX, + is_opportunistic = false + }; +decode (?CATEGORY_SWITCH_WEAPONS, ActorIX, _Map) -> + #switch_weapons + { + actor_ix = ActorIX + }; +decode (?CATEGORY_USE_SKILL, ActorIX, Map) -> + Targets = map:get(?USE_SKILL_TARGETS_FIELD, Map), + EncodedLocations = map:get(?USE_SKILL_LOCATIONS_FIELD, Map), + Locations = lists:map(fun shr_location:decode/1, EncodedLocations), --spec maybe_decode_weapon_switch - ( - non_neg_integer(), - boolean() - ) - -> ({ok, type()} | none). -maybe_decode_weapon_switch (_CharacterIX, false) -> none; -maybe_decode_weapon_switch (CharacterIX, true) -> - {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 + #skill { - ok, - #skill - { - actor_ix = CharacterIX - } + actor_ix = ActorIX, + targets = Targets, + locations = Locations }. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec can_follow (category(), category()) -> boolean(). can_follow (nothing, attack) -> true; -can_follow (nothing, switch_weapon) -> true; +can_follow (nothing, switch_weapons) -> true; can_follow (nothing, move) -> true; can_follow (nothing, skill) -> true; -can_follow (move, switch_weapon) -> true; +can_follow (move, switch_weapons) -> true; can_follow (move, attack) -> true; can_follow (move, skill) -> true; can_follow (_, _) -> false. @@ -206,8 +199,8 @@ get_actor_index (Action) when is_record(Action, attack) -> Action#attack.actor_ix; 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, switch_weapons) -> + Action#switch_weapons.actor_ix; get_actor_index (Action) when is_record(Action, skill) -> Action#skill.actor_ix; get_actor_index (_) -> @@ -274,9 +267,12 @@ new_skill (ActorIX, Targets, 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_weapons) -> switch_weapons; get_category (Action) when is_record(Action, skill) -> skill. +-spec decode (non_neg_integer(), map()) -> type(). +decode (ActorIX, Map) -> decode(map:get(?CATEGORY_FIELD), ActorIX, Map). + -spec from_map_marker ( non_neg_integer(), diff --git a/src/battle/struct/btl_character_turn_request.erl b/src/battle/struct/btl_character_turn_request.erl index 3596b4b..9f5747f 100644 --- a/src/battle/struct/btl_character_turn_request.erl +++ b/src/battle/struct/btl_character_turn_request.erl @@ -5,10 +5,6 @@ -define(BATTLE_ID_FIELD, <<"bid">>). -define(CHAR_IX_FIELD, <<"cix">>). -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">>). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -53,58 +49,28 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec decode_actions (non_neg_integer(), map()) -> list(btl_action:type()). -decode_actions (CharacterIX, Act) -> - S0Result = [], - S1Result = - case - btl_action:maybe_decode_move - ( - CharacterIX, - maps:get(?ACTIONS_MOVE_FIELD, Act) - ) - of - {ok, Move} -> [Move|S0Result]; - none -> S0Result - end, - - S2Result = - case - btl_action:maybe_decode_attack - ( - CharacterIX, - maps:get(?ACTIONS_ATTACK_FIELD, Act) - ) - of - {ok, Atk} -> [Atk|S1Result]; - none -> S1Result - end, - - S3Result = - case - btl_action:maybe_decode_weapon_switch - ( - CharacterIX, - maps:get(?ACTIONS_WEAPON_SWITCH_FIELD, Act) - ) - of - {ok, Wps} -> [Wps|S2Result]; - none -> S2Result - end, - - 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). +-spec validate_actions (list(btl_action:type())) -> ok. +validate_actions (Actions) -> + {AreValid, _LastAction} = + lists:foldl + ( + fun (Action, {CurrentResult, PrevAction}) -> + { + case CurrentResult of + false -> false; + true -> btl_action:can_follow(PrevAction, Action) + end, + Action + } + end, + {true, nothing}, + Actions + ), + + case AreValid of + false -> error({actions, Actions}); + true -> ok + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -113,7 +79,16 @@ decode_actions (CharacterIX, Act) -> decode (Map) -> CharacterIX = maps:get(?CHAR_IX_FIELD, Map), EncodedActions = maps:get(?ACTIONS_FIELD, Map), - Actions = decode_actions(CharacterIX, EncodedActions), + Actions = + lists:map + ( + fun (EncodedAction) -> + btl_action:decode(CharacterIX, EncodedAction) + end, + EncodedActions + ), + + validate_actions(Actions), #type { diff --git a/src/battle/struct/btl_condition.erl b/src/battle/struct/btl_condition.erl index 695830b..ee582d9 100644 --- a/src/battle/struct/btl_condition.erl +++ b/src/battle/struct/btl_condition.erl @@ -5,6 +5,13 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -include("tacticians/conditions.hrl"). +-type visibility() :: + ( + none + | {limited, ordsets:ordsets(non_neg_integer())} % PlayerIXs + | all + ). + -type update_action() :: ( none @@ -24,14 +31,15 @@ { category :: shr_condition:id(), triggers :: ordsets:ordset(shr_condition:trigger()), - parameters :: tuple() + parameters :: tuple(), + visibility :: visibility() } ). -opaque type() :: #btl_cond{}. -opaque collection() :: orddict:orddict(non_neg_integer(), type()). --export_type([type/0, ref/0, collection/0, update_action/0]). +-export_type([type/0, ref/0, visibility/0, collection/0, update_action/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -42,21 +50,26 @@ get_category/1, get_triggers/1, get_parameters/1, + get_visibility/1, - set_triggers/2, - set_parameters/2, + set_visibility/2, + ataxia_set_visibility/2, + set_triggers/2, ataxia_set_triggers/2, - ataxia_set_parameters/2, - ataxia_set_triggers/3, + + set_parameters/2, + ataxia_set_parameters/2, ataxia_set_parameters/3, + get_category_field/0, get_triggers_field/0, get_parameters_field/0, + get_visibility_field/0, - new/3, + new/4, new_collection/0 ] ). @@ -74,8 +87,7 @@ -export ( [ - encode/1, - encode_collection/1 + encode_collection_for/2 ] ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -437,8 +449,33 @@ new (CondID, Triggers, Params) -> -spec new_collection () -> collection(). new_collection () -> orddict:new(). --spec encode (type()) -> {list({binary(), any()})}. -encode (Condition) -> {[]}. % TODO +-spec encode + ( + non_neg_integer(), + type() + ) + -> list({binary(), any()}). +encode (IX, Condition) -> todo. % TODO --spec encode_collection (collection()) -> {list({binary(), any()})}. -encode_collection (Conditions) -> {[]}. % TODO +-spec encode_collection_for + ( + non_neg_integer(), + collection() + ) + -> list({binary(), any()}). +encode_collection_for (PlayerIX, Conditions) -> + lists:filtermap + ( + fun ({IX, Condition}) -> + case Condition#btl_cond.visibility of + none -> false; + any -> encode(IX, Condition); + {limited, AllowedPlayerIXs} -> + case ordsets:is_element(PlayerIX, AllowedPlayerIXs) of + false -> false; + true -> {true, encode(IX, Condition)} + end + end + end, + orddict:to_list(Conditions) + ). -- cgit v1.2.3-70-g09d2