summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tacticians/conditions.hrl18
-rw-r--r--src/battle/mechanic/action/btl_action_move.erl63
2 files changed, 68 insertions, 13 deletions
diff --git a/include/tacticians/conditions.hrl b/include/tacticians/conditions.hrl
index 8af2033..cc27972 100644
--- a/include/tacticians/conditions.hrl
+++ b/include/tacticians/conditions.hrl
@@ -41,3 +41,21 @@
-define(CONDITION_TRIGGER_PLAYER_DEFEAT, pd).
-define(CONDITION_TRIGGER_A_CHARACTER_HAS_DIED, achd).
+
+-define(CONDITION_TRIGGER_ABOUT_TO_MOVE, atm).
+-define(CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_MOVE, aciatm).
+
+-define(CONDITION_TRIGGER_HAS_MOVED, hm).
+-define(CONDITION_TRIGGER_A_CHARACTER_HAS_MOVED, achm).
+
+-define(CONDITION_TRIGGER_ABOUT_TO_SWITCH_WEAPONS, atsw).
+-define(CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_SWITCH_WEAPONS, aciatsw).
+
+-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_HAS_CAST_SKILL, hcs).
+-define(CONDITION_TRIGGER_A_CHARACTER_HAS_CAST_SKILL, achcs).
diff --git a/src/battle/mechanic/action/btl_action_move.erl b/src/battle/mechanic/action/btl_action_move.erl
index ad19f7a..347ca93 100644
--- a/src/battle/mechanic/action/btl_action_move.erl
+++ b/src/battle/mechanic/action/btl_action_move.erl
@@ -2,6 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-include("tacticians/conditions.hrl").
+
-type attack_candidate_ref() ::
{
non_neg_integer(), % Character IX
@@ -14,7 +16,7 @@
-export
(
[
- handle/3
+ handle/2
]
).
@@ -454,7 +456,11 @@ commit_move (CharacterIX, Character, S0Update, Path, NewLocation) ->
handle (Action, S0Update) ->
ActorIX = btl_action:get_actor_index(Action),
- S0MovementPoints = ...,
+ S0Battle = btl_character_turn_update:get_battle(S0Update),
+ {S0Actor, S1Battle} = btl_battle:get_resolved_character(ActorIX, S0Battle),
+ S1Update = btl_character_turn_update:set_battle(S1Battle, S0Update),
+
+ S0MovementPoints = get_movement_points(Action, S0Actor),
S0Path = btl_action:get_path(Action),
@@ -463,10 +469,23 @@ handle (Action, S0Update) ->
(
ActorIX,
?CONDITION_TRIGGER_ABOUT_TO_MOVE,
+ Action,
{S0MovementPoints, S0Path},
S1Update
),
+ {{S2MovementPoints, S2Path}, S3Update} =
+ btl_condition:apply_to_battle
+ (
+ ?CONDITION_TRIGGER_A_CHARACTER_IS_ABOUT_TO_MOVE,
+ Action,
+ {S1MovementPoints, S1Path},
+ S2Update
+ ),
+
+ S2Battle = btl_character_turn_update:get_battle(S3Update),
+ {S1Actor, S3Battle} = btl_battle:get_resolved_character(ActorIX, S2Battle),
+ S4Update = btl_character_turn_update:set_battle(S3Battle, S3Update),
{
NewLocation,
@@ -475,21 +494,39 @@ handle (Action, S0Update) ->
Interruptions,
HandledPath
} =
- get_path_cost_and_destination(CharacterIX, Character, S0Update, Path),
-
- MovementPoints = get_movement_points(Action, Character),
+ get_path_cost_and_destination(ActorIX, S1Actor, S4Update, S2Path),
- case (MovementPoints >= PathCost) of
+ case (S2MovementPoints >= PathCost) of
true -> ok;
- _ -> error({movement, MovementPoints, PathCost})
+ _ -> error({movement, S2MovementPoints, PathCost})
end,
% [FIXME][IMPORTANT]: 'Path' will not be correct if there is an interruption.
- S1Update =
- commit_move(CharacterIX, Character, S0Update, HandledPath, NewLocation),
+ S4Update =
+ commit_move(ActorIX, S1Actor, S4Update, HandledPath, NewLocation),
+
+ {_Nothing, S5Update} =
+ btl_condition:apply_to_character
+ (
+ ActorIX,
+ ?CONDITION_TRIGGER_HAS_MOVED,
+ {Action, HandledPath, PathCost, NewLocation},
+ none,
+ S4Update
+ ),
+
+ {_Nothing, S6Update} =
+ btl_condition:apply_to_character
+ (
+ ActorIX,
+ ?CONDITION_TRIGGER_A_CHARACTER_HAS_MOVED,
+ {Action, HandledPath, PathCost, NewLocation},
+ none,
+ S5Update
+ ),
case RemainingPath of
- [] -> {ok, S1Update};
+ [] -> {ok, S6Update};
_ ->
{events,
(
@@ -498,12 +535,12 @@ handle (Action, S0Update) ->
[
btl_action:new_move
(
- CharacterIX,
+ ActorIX,
RemainingPath,
- (MovementPoints - PathCost)
+ (S2MovementPoints - PathCost)
)
]
),
- S1Update
+ S6Update
}
end.