From 95f112f827ffef5605c384b86a9d718c74e9bbbc Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 27 Oct 2019 21:14:25 +0100 Subject: ... --- 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 +- 6 files changed, 263 insertions(+), 265 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 (limited to 'src/battle/mechanic') 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. -- cgit v1.2.3-70-g09d2