summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/battle/mechanic/turn_action')
-rw-r--r--src/battle/mechanic/turn_action/btl_turn_actions_attack.erl339
-rw-r--r--src/battle/mechanic/turn_action/btl_turn_actions_move.erl278
-rw-r--r--src/battle/mechanic/turn_action/btl_turn_actions_opportunity_attack.erl178
-rw-r--r--src/battle/mechanic/turn_action/btl_turn_actions_switch_weapon.erl55
4 files changed, 0 insertions, 850 deletions
diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl
deleted file mode 100644
index 2b032a0..0000000
--- a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl
+++ /dev/null
@@ -1,339 +0,0 @@
--module(btl_turn_actions_attack).
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- handle/2
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
--spec handle_attack_sequence
- (
- btl_character:type(),
- non_neg_integer(),
- btl_character:type(),
- non_neg_integer(),
- integer(),
- integer(),
- list(btl_attack:step()),
- list(btl_attack:type())
- )
- ->
- {
- list(btl_attack:type()),
- non_neg_integer(),
- non_neg_integer(),
- integer(),
- integer()
- }.
-handle_attack_sequence
-(
- _Character,
- CharacterCurrentHealth,
- _TargetCharacter,
- TargetCurrentHealth,
- AttackerLuck,
- DefenderLuck,
- AttackSequence,
- Result
-)
-when
-(
- (CharacterCurrentHealth == 0)
- or (TargetCurrentHealth == 0)
- or (AttackSequence == [])
-) ->
- {
- lists:reverse(Result),
- CharacterCurrentHealth,
- TargetCurrentHealth,
- AttackerLuck,
- DefenderLuck
- };
-handle_attack_sequence
-(
- Character,
- AttackerHealth,
- TargetCharacter,
- DefenderHealth,
- AttackerLuck,
- DefenderLuck,
- [NextAttack | AttackSequence],
- Result
-) ->
- AttackEffect =
- btl_attack:get_description_of
- (
- NextAttack,
- btl_character:get_base_character(Character),
- btl_character:get_base_character(TargetCharacter),
- AttackerLuck,
- DefenderLuck
- ),
-
- {
- AttackResult,
- NewAttackerHealth,
- NewAttackerLuck,
- NewDefenderHealth,
- NewDefenderLuck
- } =
- btl_attack:apply_to_healths_and_lucks
- (
- AttackEffect,
- AttackerHealth,
- AttackerLuck,
- DefenderHealth,
- DefenderLuck
- ),
-
- NextResult =
- case AttackResult of
- {nothing, _, _} -> Result;
- _ -> [AttackResult|Result]
- end,
-
- handle_attack_sequence
- (
- Character,
- NewAttackerHealth,
- TargetCharacter,
- NewDefenderHealth,
- NewAttackerLuck,
- NewDefenderLuck,
- AttackSequence,
- NextResult
- ).
-
--spec get_attack_sequence
- (
- btl_character:type(),
- btl_character:type()
- )
- -> list(btl_attack:step()).
-get_attack_sequence (Character, TargetCharacter) ->
- Range =
- shr_location:dist
- (
- btl_character:get_location(Character),
- btl_character:get_location(TargetCharacter)
- ),
-
- AttackingWeapon =
- shr_character:get_active_weapon
- (
- btl_character:get_base_character(Character)
- ),
-
- DefendingWeapon =
- shr_character:get_active_weapon
- (
- btl_character:get_base_character(TargetCharacter)
- ),
-
- btl_attack:get_sequence(Range, AttackingWeapon, DefendingWeapon).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec handle
- (
- btl_action:type(),
- btl_character_turn_update:type()
- )
- -> {ok, btl_character_turn_update:type()}.
-handle (BattleAction, Update) ->
- {S0Update, Battle} = btl_character_turn_update:get_battle(Update),
- {S1Update, Character} = btl_character_turn_update:get_character(S0Update),
-
- AttackingPlayerIX = btl_character:get_player_index(Character),
- AttackingPlayer = btl_battle:get_player(AttackingPlayerIX, Battle),
- AttackingPlayerLuck = btl_player:get_luck(AttackingPlayer),
-
- TargetIX = btl_action:get_target_ix(BattleAction),
- Map = btl_battle:get_map(Battle),
- TargetCharacterRef = btl_battle:get_character(TargetIX, Battle),
- TargetCharacter =
- btl_character:resolve
- (
- shr_tile:get_omnimods
- (
- shr_tile:from_id
- (
- shr_tile_instance:get_tile_id
- (
- shr_map:get_tile_instance
- (
- btl_character:get_location(TargetCharacterRef),
- Map
- )
- )
- )
- ),
- TargetCharacterRef
- ),
-
- DefendingPlayerIX = btl_character:get_player_index(TargetCharacter),
- DefendingPlayer = btl_battle:get_player(DefendingPlayerIX, Battle),
- DefendingPlayerLuck = btl_player:get_luck(DefendingPlayer),
-
-
- true = btl_character:get_is_alive(TargetCharacter),
-
-
- AttackSequence = get_attack_sequence(Character, TargetCharacter),
-
- {
- AttackEffects,
- RemainingAttackerHealth,
- RemainingDefenderHealth,
- NewAttackerLuck,
- NewDefenderLuck
- } =
- handle_attack_sequence
- (
- Character,
- btl_character:get_current_health(Character),
- TargetCharacter,
- btl_character:get_current_health(TargetCharacter),
- AttackingPlayerLuck,
- DefendingPlayerLuck,
- AttackSequence,
- []
- ),
-
- S0NewAttackerLuck =
- case {(NewAttackerLuck =< -2), (NewAttackerLuck >= 2)} of
- {true, _} -> (NewAttackerLuck + 2);
- {_, true} -> (NewAttackerLuck - 2);
- _ -> 0
- end,
-
- S0NewDefenderLuck =
- case {(NewDefenderLuck =< -2), (NewDefenderLuck >= 2)} of
- {true, _} -> (NewDefenderLuck + 2);
- {_, true} -> (NewDefenderLuck - 2);
- _ -> 0
- end,
-
- {UpdatedAttackingPlayer, AttackingPlayerAtaxiaUpdate} =
- btl_player:ataxia_set_luck(S0NewAttackerLuck, AttackingPlayer),
-
- {UpdatedDefendingPlayer, DefendingPlayerAtaxiaUpdate} =
- btl_player:ataxia_set_luck(S0NewDefenderLuck, DefendingPlayer),
-
- {UpdatedCharacter, CharacterAtaxiaUpdate} =
- btl_character:ataxia_set_current_health
- (
- RemainingAttackerHealth,
- Character
- ),
-
- {UpdatedTargetCharacterRef, TargetCharacterRefAtaxiaUpdate} =
- btl_character:ataxia_set_current_health
- (
- RemainingDefenderHealth,
- TargetCharacterRef
- ),
-
- {S0Battle, BattleAtaxiaUpdate0} =
- btl_battle:ataxia_set_player
- (
- AttackingPlayerIX,
- UpdatedAttackingPlayer,
- AttackingPlayerAtaxiaUpdate,
- Battle
- ),
-
- {S1Battle, BattleAtaxiaUpdate1} =
- btl_battle:ataxia_set_player
- (
- DefendingPlayerIX,
- UpdatedDefendingPlayer,
- DefendingPlayerAtaxiaUpdate,
- S0Battle
- ),
-
- {S2Battle, BattleAtaxiaUpdate2} =
- btl_battle:ataxia_set_character
- (
- TargetIX,
- UpdatedTargetCharacterRef,
- TargetCharacterRefAtaxiaUpdate,
- S1Battle
- ),
-
- % Potential danger ahead: we're going to update both the 'character' and
- % 'battle' members of a btl_character_turn_update.
- % 'S1Update' is sure to have both up to date (as it's the result of 'get'
- % requests for both) and there is no risk of the 'battle' update influencing
- % 'character', making what follows safe.
-
- S2Update =
- btl_character_turn_update:ataxia_set_battle
- (
- S2Battle,
- false,
- ataxic:optimize
- (
- ataxic:sequence
- (
- [
- BattleAtaxiaUpdate0,
- BattleAtaxiaUpdate1,
- BattleAtaxiaUpdate2
- ]
- )
- ),
- S1Update
- ),
-
- S3Update =
- btl_character_turn_update:ataxia_set_character
- (
- UpdatedCharacter,
- CharacterAtaxiaUpdate,
- S2Update
- ),
-
- TimelineItem =
- btl_turn_result:new_character_attacked
- (
- btl_character_turn_update:get_character_ix(S3Update),
- TargetIX,
- AttackEffects,
- S0NewAttackerLuck,
- S0NewDefenderLuck
- ),
-
- S4Update = btl_character_turn_update:add_to_timeline(TimelineItem, S3Update),
-
- S5Update =
- case (RemainingAttackerHealth > 0) of
- true -> S4Update;
- false ->
- btl_victory_progression:handle_character_loss(Character, S4Update)
- end,
-
- S6Update =
- case (RemainingDefenderHealth > 0) of
- true -> S5Update;
- false ->
- btl_victory_progression:handle_character_loss
- (
- TargetCharacterRef,
- S5Update
- )
- end,
-
- {ok, S6Update}.
diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_move.erl b/src/battle/mechanic/turn_action/btl_turn_actions_move.erl
deleted file mode 100644
index 70b42c9..0000000
--- a/src/battle/mechanic/turn_action/btl_turn_actions_move.erl
+++ /dev/null
@@ -1,278 +0,0 @@
--module(btl_turn_actions_move).
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- handle/2
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec cross
- (
- non_neg_integer(),
- shr_map:type(),
- list(shr_location:type()),
- list(shr_direction:enum()),
- non_neg_integer(),
- shr_location:type()
- )
- ->
- {
- shr_location:type(),
- list(shr_direction:type()),
- non_neg_integer(),
- list(shr_map_marker:type())
- }.
-cross (_PlayerIX, _Map, _ForbiddenLocations, [], Cost, Location) ->
- {Location, [], Cost, []};
-cross (PlayerIX, Map, ForbiddenLocations, [Step|NextSteps], Cost, Location) ->
- NextLocation = shr_location:apply_direction(Step, Location),
- NextTileInstance = shr_map:get_tile_instance(NextLocation, Map),
- NextTileClassID = shr_tile_instance:get_tile_id(NextTileInstance),
- NextTile = shr_tile:from_id(NextTileClassID),
- NextCost = (Cost + shr_tile:get_cost(NextTile)),
- IsForbidden =
- lists:foldl
- (
- fun (ForbiddenLocation, Prev) ->
- (Prev or (NextLocation == ForbiddenLocation))
- end,
- false,
- ForbiddenLocations
- ),
-
- false = IsForbidden,
-
- Interruptions =
- list:foldl
- (
- fun (MarkerName, CurrentInterruptions) ->
- case shr_map:get_marker(MarkerName, Map) of
- {ok, Marker} ->
- case shr_map_marker:interrupts_movement(PlayerIX, Marker) of
- true -> [Marker|CurrentInterruptions];
- _ -> CurrentInterruptions
- end;
-
- error ->
- %% TODO: Error.
- CurrentInterruptions
- end
- end,
- [],
- shr_tile_instance:get_triggers(NextTileInstance)
- ),
-
- case Interruptions of
- [] ->
- cross
- (
- PlayerIX,
- Map,
- ForbiddenLocations,
- NextSteps,
- NextCost,
- NextLocation
- );
-
- _ -> {NextLocation, NextSteps, NextCost, Interruptions}
- end.
-
--spec cross
- (
- non_neg_integer(),
- shr_map:type(),
- list(shr_location:type()),
- list(shr_direction:enum()),
- shr_location:type()
- )
- ->
- {
- shr_location:type(),
- list(shr_direction:type()),
- non_neg_integer(),
- list(shr_map_marker:type())
- }.
-cross (PlayerIX, Map, ForbiddenLocations, Path, Location) ->
- cross(PlayerIX, Map, ForbiddenLocations, Path, 0, Location).
-
--spec get_path_cost_and_destination
- (
- btl_character_turn_update:type(),
- list(shr_direction:type())
- )
- ->
- {
- non_neg_integer(),
- shr_location:type(),
- list(shr_direction:type()),
- list(shr_map_marker:type()),
- btl_character_turn_update:type()
- }.
-get_path_cost_and_destination (Update, Path) ->
- {S0Update, Character} = btl_character_turn_update:get_character(Update),
- {S1Update, Battle} = btl_character_turn_update:get_battle(S0Update),
- CharacterIX = btl_character_turn_update:get_character_ix(S1Update),
- Map = btl_battle:get_map(Battle),
-
- % FIXME: This is recalculated at every move action, despite there be no need
- % to: The client will not allow the character to go somewhere that would
- % only be freed because of an event.
- ForbiddenLocations =
- orddict:fold
- (
- fun (IX, Char, Prev) ->
- IsAlive = btl_character:get_is_alive(Char),
- if
- (IX == CharacterIX) -> Prev;
- (not IsAlive) -> Prev;
- true ->
- ordsets:add_element(btl_character:get_location(Char), Prev)
- end
- end,
- ordsets:new(),
- btl_battle:get_characters(Battle)
- ),
-
- {NewLocation, RemainingPath, Cost, Interruptions} =
- cross
- (
- btl_character:get_player_index(Character),
- Map,
- ForbiddenLocations,
- Path,
- btl_character:get_location(Character)
- ),
-
- {Cost, NewLocation, RemainingPath, Interruptions, S1Update}.
-
--spec get_movement_points
- (
- btl_action:type(),
- btl_character:type()
- )
- -> non_neg_integer().
-get_movement_points (Action, Char) ->
- case btl_action:get_category(Action) of
- interrupted_move -> btl_action:get_movement_points(Action);
- _ ->
- shr_statistics:get_movement_points
- (
- shr_character:get_statistics
- (
- btl_character:get_base_character(Char)
- )
- )
- end.
-
--spec commit_move
- (
- btl_character:type(),
- btl_character_turn_update:type(),
- list(shr_direction:type()),
- shr_location:type()
- )
- -> btl_character_turn_update:type().
-commit_move (Character, Update, Path, NewLocation) ->
- {S0Update, Battle} = btl_character_turn_update:get_battle(Update),
- Map = btl_battle:get_map(Battle),
- TileOmnimods =
- shr_tile:get_omnimods
- (
- shr_tile:from_id
- (
- shr_tile_instance:get_tile_id
- (
- shr_map:get_tile_instance(NewLocation, Map)
- )
- )
- ),
-
- {UpdatedCharacter, CharacterAtaxiaUpdate} =
- btl_character:ataxia_set_location(NewLocation, TileOmnimods, Character),
-
- S1Update =
- btl_character_turn_update:ataxia_set_character
- (
- UpdatedCharacter,
- CharacterAtaxiaUpdate,
- S0Update
- ),
-
- TimelineItem =
- btl_turn_result:new_character_moved
- (
- btl_character_turn_update:get_character_ix(S1Update),
- Path,
- NewLocation
- ),
-
- S2Update = btl_character_turn_update:add_to_timeline(TimelineItem, S1Update),
-
- S2Update.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec handle
- (
- btl_action:type(),
- btl_character_turn_update:type()
- )
- ->
- (
- {'ok', btl_character_turn_update:type()}
- | {'events', list(btl_action:type()), btl_character_turn_update:type()}
- ).
-handle (BattleAction, Update) ->
- {S0Update, Character} = btl_character_turn_update:get_character(Update),
-
- Path = btl_action:get_path(BattleAction),
-
- {PathCost, NewLocation, RemainingPath, Interruptions, S1Update} =
- get_path_cost_and_destination(S0Update, Path),
-
- MovementPoints = get_movement_points(BattleAction, Character),
-
- true = (MovementPoints >= PathCost),
-
- S2Update = commit_move(Character, S1Update, Path, NewLocation),
-
- case RemainingPath of
- [] -> {ok, S2Update};
- _ ->
- {events,
- (
- lists:foldl
- (
- fun (Marker, CurrentActions) ->
- (
- btl_action:from_map_marker(Character, Marker)
- ++
- CurrentActions
- )
- end,
- [],
- Interruptions
- )
- ++
- [
- btl_action:new_interrupted_move
- (
- RemainingPath,
- (MovementPoints - PathCost)
- )
- ]
- ),
- S2Update
- }
- end.
diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_opportunity_attack.erl b/src/battle/mechanic/turn_action/btl_turn_actions_opportunity_attack.erl
deleted file mode 100644
index c1dbbdd..0000000
--- a/src/battle/mechanic/turn_action/btl_turn_actions_opportunity_attack.erl
+++ /dev/null
@@ -1,178 +0,0 @@
--module(btl_turn_actions_opportunity_attack).
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- handle/2
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec handle
- (
- btl_action:type(),
- btl_character_turn_update:type()
- )
- -> {ok, btl_character_turn_update:type()}.
-handle (BattleAction, Update) ->
- {S0Update, Battle} = btl_character_turn_update:get_battle(Update),
- {S1Update, Character} = btl_character_turn_update:get_character(S0Update),
-
- DefendingPlayerIX = btl_character:get_player_index(Character),
- DefendingPlayer = btl_battle:get_player(DefendingPlayerIX, Battle),
- DefendingPlayerLuck = btl_player:get_luck(DefendingPlayer),
-
- AttackerIX = btl_action:get_target_ix(BattleAction),
- AttackerRef = btl_battle:get_character(AttackerIX, Battle),
- Attacker = btl_battle:resolve_character(AttackerRef, Battle),
-
- AttackingPlayerIX = btl_character:get_player_index(Attacker),
- AttackingPlayer = btl_battle:get_player(AttackingPlayerIX, Battle),
- AttackingPlayerLuck = btl_player:get_luck(AttackingPlayer),
-
- Attack = btl_attack:attack_of_opportunity(),
-
- AttackEffect =
- btl_attack:get_description_of
- (
- Attack,
- btl_character:get_base_character(Character),
- btl_character:get_base_character(Attacker),
- AttackingPlayerLuck,
- DefendingPlayerLuck
- ),
-
- {
- AttackResult,
- NewAttackerHealth,
- S0NewAttackerLuck,
- NewDefenderHealth,
- S0NewDefenderLuck
- } =
- btl_attack:apply_to_healths_and_lucks
- (
- AttackEffect,
- btl_character:get_current_health(Attacker),
- AttackingPlayerLuck,
- btl_character:get_current_health(Character),
- DefendingPlayerLuck
- ),
-
- S1NewAttackerLuck =
- case {(S0NewAttackerLuck =< -2), (S0NewAttackerLuck >= 2)} of
- {true, _} -> (S0NewAttackerLuck + 2);
- {_, true} -> (S0NewAttackerLuck - 2);
- _ -> 0
- end,
-
- S1NewDefenderLuck =
- case {(S0NewDefenderLuck =< -2), (S0NewDefenderLuck >= 2)} of
- {true, _} -> (S0NewDefenderLuck + 2);
- {_, true} -> (S0NewDefenderLuck - 2);
- _ -> 0
- end,
-
- {UpdatedAttackingPlayer, AttackingPlayerAtaxiaUpdate} =
- btl_player:ataxia_set_luck(S1NewAttackerLuck, AttackingPlayer),
-
- {UpdatedDefendingPlayer, DefendingPlayerAtaxiaUpdate} =
- btl_player:ataxia_set_luck(S1NewDefenderLuck, DefendingPlayer),
-
- {UpdatedCharacter, CharacterAtaxiaUpdate} =
- btl_character:ataxia_set_current_health(NewDefenderHealth, Character),
-
- {UpdatedAttackerRef, AttackerRefAtaxiaUpdate} =
- btl_character:ataxia_set_current_health(NewAttackerHealth, AttackerRef),
-
- {S0Battle, BattleAtaxiaUpdate0} =
- btl_battle:ataxia_set_player
- (
- AttackingPlayerIX,
- UpdatedAttackingPlayer,
- AttackingPlayerAtaxiaUpdate,
- Battle
- ),
-
- {S1Battle, BattleAtaxiaUpdate1} =
- btl_battle:ataxia_set_player
- (
- DefendingPlayerIX,
- UpdatedDefendingPlayer,
- DefendingPlayerAtaxiaUpdate,
- S0Battle
- ),
-
- {S2Battle, BattleAtaxiaUpdate2} =
- btl_battle:ataxia_set_character
- (
- AttackerIX,
- UpdatedAttackerRef,
- AttackerRefAtaxiaUpdate,
- S1Battle
- ),
-
- % Potential danger ahead: we're going to update both the 'character' and
- % 'battle' members of a btl_character_turn_update.
- % 'S1Update' is sure to have both up to date (as it's the result of 'get'
- % requests for both) and there is no risk of the 'battle' update influencing
- % 'character', making what follows safe.
-
- S2Update =
- btl_character_turn_update:ataxia_set_battle
- (
- S2Battle,
- false,
- ataxic:optimize
- (
- ataxic:sequence
- (
- [
- BattleAtaxiaUpdate0,
- BattleAtaxiaUpdate1,
- BattleAtaxiaUpdate2
- ]
- )
- ),
- S1Update
- ),
-
- S3Update =
- btl_character_turn_update:ataxia_set_character
- (
- UpdatedCharacter,
- CharacterAtaxiaUpdate,
- S2Update
- ),
-
- TimelineItem =
- btl_turn_result:new_character_attacked
- (
- AttackerIX,
- btl_character_turn_update:get_character_ix(S3Update),
- AttackResult,
- S0NewAttackerLuck,
- S0NewDefenderLuck
- ),
-
- S4Update = btl_character_turn_update:add_to_timeline(TimelineItem, S3Update),
-
- S5Update =
- case (NewDefenderHealth > 0) of
- true -> S4Update;
- false ->
- btl_victory_progression:handle_character_loss(Character, S4Update)
- end,
-
- {ok, S5Update}.
diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_switch_weapon.erl b/src/battle/mechanic/turn_action/btl_turn_actions_switch_weapon.erl
deleted file mode 100644
index 8e4aeab..0000000
--- a/src/battle/mechanic/turn_action/btl_turn_actions_switch_weapon.erl
+++ /dev/null
@@ -1,55 +0,0 @@
--module(btl_turn_actions_switch_weapon).
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- handle/1
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec handle
- (
- btl_character_turn_update:type()
- )
- -> {'ok', btl_character_turn_update:type()}.
-handle (Update) ->
- {S0Update, Character} = btl_character_turn_update:get_character(Update),
- CharacterIX = btl_character_turn_update:get_character_ix(S0Update),
- BaseCharacter = btl_character:get_base_character(Character),
-
- {UpdatedBaseCharacter, BaseCharacterAtaxiaUpdate} =
- shr_character:ataxia_switch_weapons(BaseCharacter),
-
- {UpdatedCharacter, CharacterAtaxiaUpdate} =
- btl_character:ataxia_set_base_character
- (
- UpdatedBaseCharacter,
- BaseCharacterAtaxiaUpdate,
- Character
- ),
-
- TimelineItem = btl_turn_result:new_character_switched_weapons(CharacterIX),
-
- S1Update = btl_character_turn_update:add_to_timeline(TimelineItem, S0Update),
- S2Update =
- btl_character_turn_update:ataxia_set_character
- (
- UpdatedCharacter,
- CharacterAtaxiaUpdate,
- S1Update
- ),
-
- {ok, S2Update}.