summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-10-14 17:18:12 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-10-14 17:18:12 +0200 |
commit | 0e980b08f266b48d9b40f5d58fa40e1a748f8bbf (patch) | |
tree | 5d08621af8ccf3813ab6be57215bc2d5d9ee6595 | |
parent | 04b5b40e9493645eef978473fd4e10f3ea757832 (diff) |
...
-rw-r--r-- | src/battle/mechanic/action/btl_action_attack.erl | 76 | ||||
-rw-r--r-- | src/battle/mechanic/btl_victory_progression.erl | 87 |
2 files changed, 119 insertions, 44 deletions
diff --git a/src/battle/mechanic/action/btl_action_attack.erl b/src/battle/mechanic/action/btl_action_attack.erl index f4f3c3f..1024f44 100644 --- a/src/battle/mechanic/action/btl_action_attack.erl +++ b/src/battle/mechanic/action/btl_action_attack.erl @@ -390,11 +390,83 @@ handle_end_of_attack (Action, S0Update) -> ?CONDITION_TRIGGER_END_OF_OTHER_ATTACK, ?CONDITION_TRIGGER_END_OF_ANY_ATTACK, Action, - {Action, none}, + none, S0Update ), - S1Update. + S0Battle = btl_character_turn_update:get_battle(S0Update), + ActorIX = btl_action:get_actor_index(Action), + {S0Actor, S1Battle} = btl_battle:get_resolved_character(ActorIX, S0Battle), + TargetIX = btl_action:get_actor_index(Action), + {S0Target, S2Battle} = btl_battle:get_resolved_character(TargetIX, S1Battle), + + S2Update = btl_character_turn_update:set_battle(S2Battle, S1Update), + + S0ActorIsDead = (not btl_character:get_is_alive(Actor)), + S0TargetIsDead = (not btl_character:get_is_alive(Actor)), + + S3Update = + case S0ActorIsDead of + false -> S2Update; + true -> + {_None, NextUpdate} = + apply_mirror_conditions + ( + false, + ?CONDITION_TRIGGER_COMPUTED_WAS_KILLED, + ?CONDITION_TRIGGER_COMPUTED_HAS_KILLED, + ?CONDITION_TRIGGER_COMPUTED_ANY_KILL, + Action, + none, + S2Update + ), + + NextUpdate + end, + + S4Update = + case S0TargetIsDead of + false -> S3Update; + true -> + {_None, NextUpdate} = + apply_mirror_conditions + ( + true, + ?CONDITION_TRIGGER_COMPUTED_WAS_KILLED, + ?CONDITION_TRIGGER_COMPUTED_HAS_KILLED, + ?CONDITION_TRIGGER_COMPUTED_ANY_KILL, + Action, + none, + S3Update + ), + + NextUpdate + end, + + S3Battle = btl_character_turn_update:get_battle(S4Update), + {S1Actor, S1Battle} = btl_battle:get_resolved_character(ActorIX, S0Battle), + {S1Target, S2Battle} = btl_battle:get_resolved_character(TargetIX, S1Battle), + + S5Update = btl_character_turn_update:set_battle(S2Battle, S4Update), + + S1ActorIsDead = (not btl_character:get_is_alive(Actor)), + S1TargetIsDead = (not btl_character:get_is_alive(Actor)), + + S6Update = + case S1ActorIsDead of + false -> S5Update; + true -> + btl_victory_progression:handle_character_loss(S1Actor, S5Update) + end, + + S7Update = + case S1TargetIsDead of + false -> S6Update; + true -> + btl_victory_progression:handle_character_loss(S1Target, S6Update) + end, + + S7Update. -spec commit_luck_change ( diff --git a/src/battle/mechanic/btl_victory_progression.erl b/src/battle/mechanic/btl_victory_progression.erl index 667d010..c6a7dae 100644 --- a/src/battle/mechanic/btl_victory_progression.erl +++ b/src/battle/mechanic/btl_victory_progression.erl @@ -129,47 +129,50 @@ handle_character_loss (Character, Update) -> Characters = btl_battle:get_characters(Battle), CharacterPlayerIX = btl_character:get_player_index(Character), - case btl_character:get_rank(Character) of - optional -> - %% Let's not assume there is a commander, meaning that we still have - %% to check if at least one character is alive, despite the fact that - %% if there is a commander, it being killed would have triggered - %% the defeat. - StillHasAliveChar = - lists:any - ( - fun ({_IX, Char}) -> - ( - (CharacterPlayerIX == btl_character:get_player_index(Char)) - and btl_character:get_is_alive(Char) - ) - end, - orddict:to_list(Characters) - ), - - case StillHasAliveChar of - true -> Update; - _ -> handle_player_defeat(CharacterPlayerIX, Update) - end; - - commander -> handle_player_defeat(CharacterPlayerIX, Update); - - target -> - StillHasAliveTargetChar = - lists:any + StillHasAliveChar = + lists:any + ( + fun ({_IX, Char}) -> ( - fun ({_IX, Char}) -> - ( - (CharacterPlayerIX == btl_character:get_player_index(Char)) - and btl_character:get_is_alive(Char) - and (btl_character:get_rank(Char) == target) - ) - end, - orddict:to_list(Characters) - ), - - case StillHasAliveTargetChar of - true -> Update; - _ -> handle_player_defeat(CharacterPlayerIX, Update) - end + (CharacterPlayerIX == btl_character:get_player_index(Char)) + and btl_character:get_is_alive(Char) + ) + end, + orddict:to_list(Characters) + ), + + case StillHasAliveChar of + true -> Update; + _ -> handle_player_defeat(CharacterPlayerIX, Update) end. + + %% TODO: Trigger condition: actually dead. + +% TODO: set rank as a condition. +% case btl_character:get_rank(Character) of +% optional -> +% %% Let's not assume there is a commander, meaning that we still have +% %% to check if at least one character is alive, despite the fact that +% %% if there is a commander, it being killed would have triggered +% %% the defeat. +% +% commander -> handle_player_defeat(CharacterPlayerIX, Update); +% +% target -> +% StillHasAliveTargetChar = +% lists:any +% ( +% fun ({_IX, Char}) -> +% ( +% (CharacterPlayerIX == btl_character:get_player_index(Char)) +% and btl_character:get_is_alive(Char) +% and (btl_character:get_rank(Char) == target) +% ) +% end, +% orddict:to_list(Characters) +% ), +% +% case StillHasAliveTargetChar of +% true -> Update; +% _ -> handle_player_defeat(CharacterPlayerIX, Update) +% end |