summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-10-26 19:47:46 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-10-26 19:47:46 +0200 |
commit | 86147b01bd6a240fa713dbf3368e324987664f7a (patch) | |
tree | 01deb35448429f76dcee61216f3e3a9636080baa /src/battle/mechanic/action | |
parent | f4f6314510789ba020930d08011270a93b362e47 (diff) |
...
Diffstat (limited to 'src/battle/mechanic/action')
-rw-r--r-- | src/battle/mechanic/action/btl_action_skill.erl | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/src/battle/mechanic/action/btl_action_skill.erl b/src/battle/mechanic/action/btl_action_skill.erl index 548eafe..7e6579b 100644 --- a/src/battle/mechanic/action/btl_action_skill.erl +++ b/src/battle/mechanic/action/btl_action_skill.erl @@ -17,6 +17,88 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -27,4 +109,31 @@ btl_character_turn_update:type() ) -> btl_character_turn_update:type(). -handle (_Action, S0Update) -> S0Update. % TODO +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. |