aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-03-01 18:18:48 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-03-01 18:18:48 +0100
commit45434f444962ef9c852e8122fe86ae65c9c49436 (patch)
tree87a3a9b080a46585a77181c946c807d4be3fd380
parent89866160c67444036ea0fb348952c37182feb8a1 (diff)
downloadtacticians-server-45434f444962ef9c852e8122fe86ae65c9c49436.zip
tacticians-server-45434f444962ef9c852e8122fe86ae65c9c49436.tar.bz2
...
-rw-r--r--src/struct/battle_action.erl100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/struct/battle_action.erl b/src/struct/battle_action.erl
index 5189384..7287a95 100644
--- a/src/struct/battle_action.erl
+++ b/src/struct/battle_action.erl
@@ -176,3 +176,103 @@ when is_record(BattleAction, move) ->
UpdatedCharacterInstance,
Battle
}.
+handle (Battle, CharacterInstance, CharacterInstanceIX, BattleAction)
+when is_record(BattleAction, attack) ->
+ Character = character_instance:get_character(CharacterInstance),
+ CharacterStatistics = character:get_statistics(Character),
+ Battlemap = battle:get_battlemap(Battle),
+ TargetIX = BattleAction#attack.target_ix,
+ TargetCharacterInstance = battle:get_character_instance(TargetIX, Battle),
+ TargetCharacter = character_instance:get_character(TargetCharacterInstance),
+ TargetCharacterStatistics = character:get_statistics(TargetCharacter),
+
+ Range =
+ location:dist
+ (
+ character_instance:get_location(CharacterInstance),
+ character_instance:get_location(TargetCharacterInstance)
+ ),
+
+ {AttackingWeaponID, _} = character:get_weapon_ids(Character),
+ {DefendingWeaponID, _} = character:get_weapon_ids(TargetCharacter),
+
+ AttackingWeapon = weapon:from_id(AttackingWeaponID),
+ DefendingWeapon = weapon:from_id(DefendingWeaponID),
+
+ AttackSequence =
+ attack:get_sequence(Range, AttackingWeapon, DefendingWeapon),
+
+ AttackPlannedEffects =
+ lists:map
+ (
+ fun (AttackStep) ->
+ attack:get_description_of
+ (
+ AttackStep,
+ CharacterStatistics,
+ TargetCharacterStatistics
+ )
+ end,
+ AttackSequence
+ ),
+
+ % FIXME: may warrant a separate function
+ {AttackEffects, RemainingAttakerHealth, RemainingDefenderHealth} =
+ lists:foldl
+ (
+ fun
+ (
+ AttackEffectCandidate,
+ {AttackValidEffects, AttackerHealth, DefenderHealth }
+ ) ->
+ {AttackResult, NewAttackerHealth, NewDefenderHealth} =
+ attack:apply_to_healths
+ (
+ AttackPlannedEffect,
+ AttackerHealth,
+ DefenderHealth
+ ),
+ case AttackResult of
+ nothing -> {AttackValidEffects, AttackerHealth, DefenderHealth};
+ _ ->
+ {
+ [AttackResult|AttackValidEffects],
+ NewAttackerHealth,
+ NewDefenderHealth
+ }
+ end,
+ end,
+ {
+ [],
+ character_instance:get_current_health(CharacterInstance),
+ character_instance:get_current_health(TargetCharacterInstance)
+ },
+ AttackPlannedEffects
+ ),
+
+ UpdatedCharacterInstance =
+ character_instance:set_current_health
+ (
+ RemainingAttackerHealth,
+ CharacterInstance
+ ),
+
+ UpdatedBattle =
+ battle:set_character_instance
+ (
+ TargetIX,
+ character_instance:set_current_health
+ (
+ RemainingDefenderHealth,
+ TargetCharacterInstance
+ ),
+ Battle
+ )
+ {
+ % TODO: hide that into database_diff structs.
+ [], % TODO
+ % TODO: hide that into turn_result structs.
+ AttackEffets,
+ UpdatedCharacterInstance,
+ UpdatedBattle
+ }.