summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-10-09 22:16:07 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-10-09 22:16:07 +0200
commitab4bcc69e713c9cc8d6d5577cc2d85e5f36eb26a (patch)
treeebf67e07b3128bdc8068ffc2d714aeb80ae8161c
parent85b4344b0aa478ae0a206ba4f0fb9b2e4f14106e (diff)
Handling expressive conditions is difficult...
-rw-r--r--include/tacticians/conditions.hrl.m428
-rw-r--r--src/battle/mechanic/action/btl_action_attack.erl140
2 files changed, 123 insertions, 45 deletions
diff --git a/include/tacticians/conditions.hrl.m4 b/include/tacticians/conditions.hrl.m4
index e4f2c34..0b72b1a 100644
--- a/include/tacticians/conditions.hrl.m4
+++ b/include/tacticians/conditions.hrl.m4
@@ -7,23 +7,17 @@ m4_include(__MAKEFILE_DATA_DIR/condition/trigger.m4.conf)
-define(CONDITION_TRIGGER_START_OF_OWN_ATTACK, __COND_TRIG_START_OF_OWN_ATTACK).
-define(CONDITION_TRIGGER_END_OF_OWN_ATTACK, __COND_TRIG_END_OF_OWN_ATTACK).
--define(CONDITION_TRIGGER_START_OF_OWN_HIT, __COND_TRIG_START_OF_OWN_HIT).
--define(CONDITION_TRIGGER_END_OF_OWN_HIT, __COND_TRIG_END_OF_OWN_HIT).
-
--define(CONDITION_TRIGGER_OWN_DODGE, __COND_TRIG_OWN_DODGE).
--define(CONDITION_TRIGGER_OWN_CRITICAL, __COND_TRIG_OWN_CRITICAL).
--define(CONDITION_TRIGGER_OWN_DOUBLE_HIT, __COND_TRIG_OWN_DOUBLE_HIT).
--define(CONDITION_TRIGGER_OWN_DAMAGE, __COND_TRIG_OWN_DAMAGE).
-
--define(CONDITION_TRIGGER_START_OF_TARGET_ATTACK, __COND_TRIG_START_OF_TARGET_ATTACK).
--define(CONDITION_TRIGGER_END_OF_TARGET_ATTACK, __COND_TRIG_END_OF_TARGET_ATTACK).
--define(CONDITION_TRIGGER_START_OF_TARGET_HIT, __COND_TRIG_START_OF_TARGET_HIT).
--define(CONDITION_TRIGGER_END_OF_TARGET_HIT, __COND_TRIG_END_OF_TARGET_HIT).
-
--define(CONDITION_TRIGGER_TARGET_DODGE, __COND_TRIG_TARGET_DODGE).
--define(CONDITION_TRIGGER_TARGET_CRITICAL, __COND_TRIG_TARGET_CRITICAL).
--define(CONDITION_TRIGGER_TARGET_DOUBLE_HIT, __COND_TRIG_TARGET_DOUBLE_HIT).
--define(CONDITION_TRIGGER_TARGET_DAMAGE, __COND_TRIG_TARGET_DAMAGE).
+
+-define(CONDITION_TRIGGER_INITIAL_DATA_FOR_OWN_HIT, __COND_TRIG_INITIAL_DATA_FOR_OWN_HIT).
+-define(CONDITION_TRIGGER_ROLLS_FOR_OWN_HIT, __ROLLS_FOR_OWN_HIT).
+-define(CONDITION_TRIGGER_END_OF_OWN_HIT, __END_OF_OWN_HIT).
+
+-define(CONDITION_TRIGGER_START_OF_OTHER_ATTACK, __COND_TRIG_START_OF_OTHER_ATTACK).
+-define(CONDITION_TRIGGER_END_OF_OTHER_ATTACK, __COND_TRIG_END_OF_OTHER_ATTACK).
+
+-define(CONDITION_TRIGGER_INITIAL_DATA_FOR_OTHER_HIT, __COND_TRIG_INITIAL_DATA_FOR_OTHER_HIT).
+-define(CONDITION_TRIGGER_ROLLS_FOR_OTHER_HIT, __ROLLS_FOR_OTHER_HIT).
+-define(CONDITION_TRIGGER_END_OF_OTHER_HIT, __END_OF_OTHER_HIT).
-define(CONDITION_TRIGGER_START_OF_MOVEMENT, __COND_TRIG_START_OF_MOVEMENT).
-define(CONDITION_TRIGGER_END_OF_MOVEMENT, __COND_TRIG_END_OF_MOVEMENT).
diff --git a/src/battle/mechanic/action/btl_action_attack.erl b/src/battle/mechanic/action/btl_action_attack.erl
index 399e050..863ddb4 100644
--- a/src/battle/mechanic/action/btl_action_attack.erl
+++ b/src/battle/mechanic/action/btl_action_attack.erl
@@ -3,6 +3,8 @@
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-include("tacticians/conditions.hrl").
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -613,19 +615,19 @@ apply_luck_decay (Luck) ->
_ -> 0
end.
--spec apply_battle_frontier_conditions
+-spec apply_mirror_conditions
(
shr_condition:trigger(),
shr_condition:trigger(),
- btl_action:type(),
+ {btl_action:type(), OtherData},
btl_character_turn_update:type()
)
- -> {btl_action:type(), btl_character_turn_update:type()}.
-apply_battle_frontier_conditions
+ -> {{btl_action:type(), OtherData}, btl_character_turn_update:type()}.
+apply_mirror_conditions
(
OwnTriggerName,
OtherTriggerName,
- S0Action,
+ {S0Action, S0Data},
S0Update
) ->
CharacterIX = btl_action:get_actor_index(S0Action),
@@ -635,11 +637,11 @@ apply_battle_frontier_conditions
S1Update = btl_character_turn_update:set_battle(S1Battle, S0Update),
- {S1Action, S2Update} =
+ {{S1Action, S1Data}, S2Update} =
apply_conditions
(
OwnTriggerName,
- S0Action,
+ {S0Action, S0Data},
Character,
S1Update
),
@@ -651,51 +653,133 @@ apply_battle_frontier_conditions
S3Update = btl_character_turn_update:set_battle(S3Battle, S2Update),
- {S2Action, S4Update} =
+ {{S2Action, S2Data}, S4Update} =
apply_conditions
(
OtherTriggerName,
- S1Action,
+ {S1Action, S1Data},
TargetCharacter,
S3Update
),
- {S2Action, S4Update}.
+ {{S2Action, S2Data}, S4Update}.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec handle
+-spec handle_start_of_attack
(
+ list(btl_attack:category()),
btl_action:type(),
btl_character_turn_update:type()
)
- -> {ok, btl_character_turn_update:type()}.
-handle (S0Action, S0Update) ->
+ ->
+ {
+ list(btl_attack:category()),
+ btl_action:type(),
+ btl_character_turn_update:type()
+ }.
+handle_start_of_attack (S0AttackSequence, S0Action, S0Update) ->
S1Update = add_targeting_event(S0Action, S0Update),
- {S1Action, S2Update} =
- apply_battle_frontier_conditions
+
+ {{S1Action, S1AttackSequence}, S2Update} =
+ apply_mirror_conditions
(
?CONDITION_TRIGGER_START_OF_OWN_ATTACK,
- ?CONDITION_TRIGGER_START_OF_TARGET_ATTACK,
- S0Action,
+ ?CONDITION_TRIGGER_START_OF_OTHER_ATTACK,
+ {S0Action, S0AttackSequence},
S1Update
),
- {AttackSequence, S3Update} = plan_attack_sequence(S1Action, S2Update),
- {S2Action, S4Update} =
- handle_attack_sequence(AttackSequence, S1Action, S3Update),
+ {S1AttackSequence, S1Action, S2Update}.
- {S3Action, S2Update} =
- apply_battle_frontier_conditions
+-spec handle_end_of_attack
+ (
+ btl_action:type(),
+ btl_character_turn_update:type()
+ )
+ -> {btl_action:type(), btl_character_turn_update:type()}.
+handle_end_of_attack (S0Action, S0Update) ->
+ {{S1Action, _PlaceHolder}, S1Update} =
+ apply_mirror_conditions
(
?CONDITION_TRIGGER_END_OF_OWN_ATTACK,
- ?CONDITION_TRIGGER_END_OF_TARGET_ATTACK,
- S0Action,
+ ?CONDITION_TRIGGER_END_OF_OTHER_ATTACK,
+ {S0Action, ok},
+ S0Update
+ ),
+
+ {S1Action, S1Update}.
+
+-spec handle_first_hit
+ (
+ list(btl_attack:category()),
+ btl_action:type(),
+ btl_character_turn_update:type()
+ )
+ ->
+ {
+ list(btl_attack:category()),
+ btl_action:type(),
+ btl_character_turn_update:type()
+ }.
+handle_first_hit (S0Sequence, S0Action, S0Update) ->
+ {BaseActor, BaseTarget, S1Update} = get_actors(S0Action, S0Update),
+ {{_S1Action, {ModdedActor, ModdedTarget}}, S2Update} =
+ apply_mirror_conditions
+ (
+ ?CONDITION_TRIGGER_INITIAL_DATA_FOR_OWN_HIT,
+ ?CONDITION_TRIGGER_INITIAL_DATA_FOR_OTHER_HIT,
+ {S0Action, {BaseActor, BaseTarget}},
S1Update
),
- {ok, S2Update}.
+ case can_perform(ModdedActor, ModdedTarget) of
+ false -> {S0Sequence, S0Action, S2Update};
+ true ->
+ {HitData, S1Update} = get_hit_data(S0Action, S0Update),
+ end.
+
+-spec handle_attack_sequence
+ (
+ list(btl_attack:category()),
+ btl_action:type(),
+ btl_character_turn_update:type()
+ )
+ -> {btl_action:type(), btl_character_turn_update:type()}.
+handle_attack_sequence ([], Action, Update) ->
+ {Action, Update};
+handle_attack_sequence ([first|S0NextElements], S0Action, S0Update) ->
+ {S1NextElements, S1Action, S1Update} =
+ handle_first_hit(S0NextElements, S0Action, S0Update),
+ handle_attack_sequence(S1NextElements, S1Action, S1Update);
+handle_attack_sequence ([second|S0NextElements], S0Action, S0Update) ->
+ {S1NextElements, S1Action, S1Update} =
+ handle_second_hit(S0NextElements, S0Action, S0Update),
+ handle_attack_sequence(S1NextElements, S1Action, S1Update);
+handle_attack_sequence ([counter|S0NextElements], S0Action, S0Update) ->
+ {S1NextElements, S1Action, S1Update} =
+ handle_counter_hit(S0NextElements, S0Action, S0Update),
+ handle_attack_sequence(S1NextElements, S1Action, S1Update).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec handle
+ (
+ btl_action:type(),
+ btl_character_turn_update:type()
+ )
+ -> btl_character_turn_update:type().
+handle (S0Action, S0Update) ->
+ S0Sequence = [first, counter, second],
+
+ {S1Sequence, S1Action, S1Update} =
+ handle_start_of_attack(S0Sequence, S0Action, S0Update),
+
+ {S2Action, S2Update} =
+ handle_attack_sequence(S1Sequence, S1Action, S1Update),
+
+ {_S3Action, S3Update} = handle_end_of_attack(S2Action, S2Update),
+
+ S3Update.
PlayerIX = btl_character:get_player_index(S0Character),
S0Player = btl_battle:get_player(PlayerIX, S0Battle),