From e68004ee70c9102d00df2925c05d1354a6315bc0 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Wed, 24 Apr 2019 19:11:58 +0200 Subject: ... --- src/battle/struct/btl_action.erl | 102 ++++++++++++++ src/battle/struct/btl_attack.erl | 166 +++++++++++++---------- src/battle/struct/btl_battle_action.erl | 105 -------------- src/battle/struct/btl_character_current_data.erl | 113 --------------- 4 files changed, 195 insertions(+), 291 deletions(-) create mode 100644 src/battle/struct/btl_action.erl delete mode 100644 src/battle/struct/btl_battle_action.erl delete mode 100644 src/battle/struct/btl_character_current_data.erl (limited to 'src/battle/struct') diff --git a/src/battle/struct/btl_action.erl b/src/battle/struct/btl_action.erl new file mode 100644 index 0000000..34dd46e --- /dev/null +++ b/src/battle/struct/btl_action.erl @@ -0,0 +1,102 @@ +-module(btl_action). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + move, + { + path :: list(shr_direction:enum()) + } +). + +-record +( + switch_weapon, + { + } +). + +-record +( + attack, + { + target_ix :: non_neg_integer() + } +). + +-type category() :: ('move' | 'switch_weapon' | 'attack' | 'nothing'). +-opaque type() :: (#move{} | #switch_weapon{} | #attack{}). + +-export_type([category/0, type/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + maybe_decode_move/1, + maybe_decode_weapon_switch/1, + maybe_decode_attack/1, + can_follow/2 + ] +). + +-export +( + [ + get_path/1, + get_target_ix/1, + get_category/1 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec maybe_decode_move (list(shr_direction:type())) -> list(type()). +maybe_decode_move ([]) -> []; +maybe_decode_move (PathInBinary) -> + Path = lists:map(fun shr_direction:decode/1, PathInBinary), + + [#move{ path = Path }]. + +-spec maybe_decode_attack (integer()) -> list(type()). +maybe_decode_attack (TargetIX) when (TargetIX < 0) -> []; +maybe_decode_attack (TargetIX) -> [#attack{ target_ix = TargetIX }]. + +-spec maybe_decode_weapon_switch (boolean()) -> list(type()). +maybe_decode_weapon_switch (false) -> []; +maybe_decode_weapon_switch (true) -> [#switch_weapon{}]. + +-spec can_follow (category(), category()) -> boolean(). +can_follow (nothing, attack) -> true; +can_follow (nothing, switch_weapon) -> true; +can_follow (nothing, move) -> true; +can_follow (move, switch_weapon) -> true; +can_follow (move, attack) -> true; +can_follow (_, _) -> false. + +-spec get_path (type()) -> list(shr_direction:type()). +get_path (Action) when is_record(Action, move) -> + Action#move.path; +get_path (_) -> + []. + +-spec get_target_ix (type()) -> non_neg_integer(). +get_target_ix (Action) when is_record(Action, attack) -> + Action#attack.target_ix; +get_target_ix (_) -> + []. + +-spec get_category (type()) -> category(). +get_category (Action) when is_record(Action, attack) -> attack; +get_category (Action) when is_record(Action, move) -> move; +get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon. + diff --git a/src/battle/struct/btl_attack.erl b/src/battle/struct/btl_attack.erl index f0778f5..481e07f 100644 --- a/src/battle/struct/btl_attack.erl +++ b/src/battle/struct/btl_attack.erl @@ -1,5 +1,7 @@ -module(btl_attack). +% FIXME: this module is mostly mechanics, not structure. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -112,28 +114,40 @@ roll_parry (DefenderStatistics, DefenderLuck) -> shr_omnimods:type() ) -> non_neg_integer(). -get_damage (Precision, IsCritical, AtkModifier, ActualAtkOmni, ActualDefOmni) -> - S0DamageMultiplier = - case Precision of - misses -> 0; - grazes -> 0.5; - hits -> 1 - end, - - S1DamageMultiplier = - case IsCritical of - true -> (S0DamageMultiplier * 2); - _ -> S0DamageMultiplier - end, - - S2DamageMultiplier = (S1DamageMultiplier * AtkModifier), +get_damage +( + Precision, + IsCritical, + StartingDamageMultiplier, + AttackerOmnimods, + DefenderOmnimods +) -> + ActualDamageMultiplier = + ( + StartingDamageMultiplier + * + ( + case Precision of + misses -> 0; + grazes -> 0.5; + hits -> 1 + end + ) + * + ( + case IsCritical of + true -> 2; + _ -> 1 + end + ) + ), ActualDamage = shr_omnimods:get_attack_damage ( - S2DamageMultiplier, - ActualAtkOmni, - ActualDefOmni + ActualDamageMultiplier, + AttackerOmnimods, + DefenderOmnimods ), ActualDamage. @@ -141,8 +155,8 @@ get_damage (Precision, IsCritical, AtkModifier, ActualAtkOmni, ActualDefOmni) -> -spec effect_of_attack ( order(), - btl_character_current_data:type(), - btl_character_current_data:type(), + shr_character:type(), + shr_character:type(), boolean(), integer(), integer() @@ -151,57 +165,63 @@ get_damage (Precision, IsCritical, AtkModifier, ActualAtkOmni, ActualDefOmni) -> effect_of_attack ( Order, - AtkCurrData, - DefCurrData, + Attacker, + Defender, CanParry, AttackerLuck, DefenderLuck ) -> - DefStats = btl_character_current_data:get_statistics(DefCurrData), + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%% Roll parry to see if the roles have to be swapped. %%%%%%%%%%%%%%%%%%%%% + DefenderStats = shr_character:get_statistics(Defender), {ParryIsSuccessful, ParryPositiveLuckMod, ParryNegativeLuckMod} = case CanParry of - true -> roll_parry(DefStats, DefenderLuck); + true -> roll_parry(DefenderStats, DefenderLuck); false -> {false, 0, 0} end, { - ActualAtkData, - ActualDefData, - ActualAtkLuck, - ActualDefLuck + ActualAttacker, + ActualDefender, + ActualAttackerLuck, + ActualDefenderLuck } = case ParryIsSuccessful of - true -> {DefCurrData, AtkCurrData, DefenderLuck, AttackerLuck}; - false -> {AtkCurrData, DefCurrData, AttackerLuck, DefenderLuck} + true -> {Defender, Attacker, DefenderLuck, AttackerLuck}; + false -> {Attacker, Defender, AttackerLuck, DefenderLuck} end, - ActualAtkStats = btl_character_current_data:get_statistics(ActualAtkData), - ActualAtkOmni = btl_character_current_data:get_omnimods(ActualAtkData), - ActualDefStats = btl_character_current_data:get_statistics(ActualDefData), - ActualDefOmni = btl_character_current_data:get_omnimods(ActualDefData), + ActualAttackerStats = shr_character:get_statistics(ActualAttacker), + ActualAttackerOmnimods = shr_character:get_omnimods(ActualAttacker), + ActualDefenderStats = shr_character:get_statistics(ActualDefender), + ActualDefenderOmnimods = shr_character:get_omnimods(ActualDefender), + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {Precision, PrecisionPositiveLuckMod, PrecisionNegativeLuckMod} = roll_precision ( - ActualAtkStats, - ActualDefStats, - ActualDefLuck + ActualAttackerStats, + ActualDefenderStats, + ActualDefenderLuck ), {IsCritical, CriticalPositiveLuckMod, CriticalNegativeLuckMod} = - roll_critical_hit(ActualAtkStats, ActualAtkLuck), + roll_critical_hit(ActualAttackerStats, ActualAttackerLuck), + + ActualAttackerDamageModifier = + shr_statistics:get_damage_modifier(ActualAttackerStats), - AtkDamageModifier = shr_statistics:get_damage_modifier(ActualAtkStats), Damage = get_damage ( Precision, IsCritical, - AtkDamageModifier, - ActualAtkOmni, - ActualDefOmni + ActualAttackerDamageModifier, + ActualAttackerOmnimods, + ActualDefenderOmnimods ), {FinalAttackerLuckMod, FinalDefenderLuckMod} = @@ -311,8 +331,8 @@ encode_precision (misses) -> <<"m">>. -spec get_description_of ( step(), - btl_character_current_data:type(), - btl_character_current_data:type(), + shr_character:type(), + shr_character:type(), integer(), integer() ) @@ -320,36 +340,36 @@ encode_precision (misses) -> <<"m">>. get_description_of ( {first, CanParry}, - AtkCurrData, - DefCurrData, - AtkLuck, - DefLuck + Attacker, + Defender, + AttackerLuck, + DefenderLuck ) -> effect_of_attack ( first, - AtkCurrData, - DefCurrData, + Attacker, + Defender, CanParry, - AtkLuck, - DefLuck + AttackerLuck, + DefenderLuck ); get_description_of ( {second, CanParry}, - AtkCurrData, - DefCurrData, - AtkLuck, - DefLuck + Attacker, + Defender, + AttackerLuck, + DefenderLuck ) -> - AtkStats = btl_character_current_data:get_statistics(AtkCurrData), + AttackerStats = shr_character:get_statistics(Attacker), AttackerDoubleAttackChance = - shr_statistics:get_double_hits(AtkStats), + shr_statistics:get_double_hits(AttackerStats), {_Roll, IsSuccessful, PositiveModifier, NegativeModifier} = - shr_roll:percentage_with_luck(AttackerDoubleAttackChance, AtkLuck), + shr_roll:percentage_with_luck(AttackerDoubleAttackChance, AttackerLuck), - NewAtkLuck = (AtkLuck + PositiveModifier), - NewDefLuck = (DefLuck + NegativeModifier), + NewAttackerLuck = (AttackerLuck + PositiveModifier), + NewDefenderLuck = (DefenderLuck + NegativeModifier), case IsSuccessful of true -> @@ -357,11 +377,11 @@ get_description_of effect_of_attack ( second, - AtkCurrData, - DefCurrData, + Attacker, + Defender, CanParry, - NewAtkLuck, - NewDefLuck + NewAttackerLuck, + NewDefenderLuck ), Result#attack @@ -377,19 +397,19 @@ get_description_of get_description_of ( {counter, CanParry}, - AtkCurrData, - DefCurrData, - AtkLuck, - DefLuck + Attacker, + Defender, + AttackerLuck, + DefenderLuck ) -> effect_of_attack ( counter, - DefCurrData, - AtkCurrData, + Defender, + Attacker, CanParry, - DefLuck, - AtkLuck + DefenderLuck, + AttackerLuck ). -spec apply_to_healths_and_lucks diff --git a/src/battle/struct/btl_battle_action.erl b/src/battle/struct/btl_battle_action.erl deleted file mode 100644 index 2c7564b..0000000 --- a/src/battle/struct/btl_battle_action.erl +++ /dev/null @@ -1,105 +0,0 @@ --module(btl_battle_action). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - move, - { - path :: list(shr_direction:enum()) - } -). - --record -( - switch_weapon, - { - } -). - --record -( - attack, - { - target_ix :: non_neg_integer() - } -). - --type category() :: ('move' | 'switch_weapon' | 'attack' | 'nothing'). --opaque type() :: (#move{} | #switch_weapon{} | #attack{}). - --export_type([category/0, type/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - maybe_decode_move/1, - maybe_decode_weapon_switch/1, - maybe_decode_attack/1, - can_follow/2 - ] -). - --export -( - [ - get_path/1, - get_target_ix/1, - get_category/1 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec maybe_decode_move (list(shr_direction:type())) -> list(type()). -maybe_decode_move ([]) -> []; -maybe_decode_move (PathInBinary) -> - Path = lists:map(fun shr_direction:decode/1, PathInBinary), - - [#move { path = Path }]. - --spec maybe_decode_attack (integer()) -> list(type()). -maybe_decode_attack (TargetIX) when (TargetIX < 0) -> []; -maybe_decode_attack (TargetIX) -> [#attack { target_ix = TargetIX }]. - --spec maybe_decode_weapon_switch (boolean()) -> list(type()). -maybe_decode_weapon_switch (false) -> []; -maybe_decode_weapon_switch (true) -> [#switch_weapon{}]. - --spec can_follow (category(), category()) -> boolean(). -can_follow (nothing, attack) -> true; -can_follow (nothing, switch_weapon) -> true; -can_follow (nothing, move) -> true; -can_follow (move, switch_weapon) -> true; -can_follow (move, attack) -> true; -can_follow (_, _) -> false. - --spec get_path (type()) -> list(shr_direction:type()). -get_path (Action) when is_record(Action, move) -> - Action#move.path; -get_path (_) -> - []. - --spec get_target_ix (type()) -> non_neg_integer(). -get_target_ix (Action) when is_record(Action, attack) -> - Action#attack.target_ix; -get_target_ix (_) -> - []. - --spec get_category (type()) -> category(). -get_category (Action) when is_record(Action, attack) -> attack; -get_category (Action) when is_record(Action, move) -> move; -get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon; -get_category (Action) -> - io:format("How'd you get there?~p~n", [Action]), - true = Action. - diff --git a/src/battle/struct/btl_character_current_data.erl b/src/battle/struct/btl_character_current_data.erl deleted file mode 100644 index 3f25345..0000000 --- a/src/battle/struct/btl_character_current_data.erl +++ /dev/null @@ -1,113 +0,0 @@ --module(btl_character_current_data). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - character_current_data, - { - attributes :: shr_attributes:type(), - statistics :: shr_statistics:type(), - omnimods :: shr_omnimods:type() - } -). - --opaque type() :: #character_current_data{}. - --export_type([type/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_attributes/1, - get_statistics/1, - get_omnimods/1 - ] -). - --export -( - [ - new/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec location_to_omnimods - ( - {non_neg_integer(), non_neg_integer()}, - shr_map:type() - ) - -> shr_omnimods:type(). -location_to_omnimods (Location, Map) -> - TileInstance = shr_map:get_tile_instance(Location, Map), - TileClassID = shr_tile_instance:get_tile_id(TileInstance), - Tile = shr_tile:from_id(TileClassID), - - shr_tile:get_omnimods(Tile). - --spec weapon_id_to_omnimods (shr_weapon:id()) -> shr_omnimods:type(). -weapon_id_to_omnimods (WeaponID) -> - Weapon = shr_weapon:from_id(WeaponID), - - shr_weapon:get_omnimods(Weapon). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_omnimods (type()) -> shr_omnimods:type(). -get_omnimods (Char) -> Char#character_current_data.omnimods. - --spec get_attributes (type()) -> shr_attributes:type(). -get_attributes (Char) -> Char#character_current_data.attributes. - --spec get_statistics (type()) -> shr_statistics:type(). -get_statistics (Char) -> Char#character_current_data.statistics. - -%%%% Utils --spec new (btl_character:type(), shr_map:type()) -> type(). -new (Character, Map) -> - PermanentOmnimods = btl_character:get_permanent_omnimods(Character), - - {WeaponID, _} = btl_character:get_weapon_ids(Character), - WeaponOmnimods = weapon_id_to_omnimods(WeaponID), - - Location = btl_character:get_location(Character), - TileOmnimods = location_to_omnimods(Location, Map), - - CurrentOmnimods = - shr_omnimods:merge - ( - shr_omnimods:merge(WeaponOmnimods, TileOmnimods), - PermanentOmnimods - ), - - CurrentAttributes = - shr_omnimods:apply_to_attributes - ( - CurrentOmnimods, - shr_attributes:default() - ), - - CurrentStatistics = - shr_omnimods:apply_to_statistics - ( - CurrentOmnimods, - shr_statistics:new_raw(CurrentAttributes) - ), - - #character_current_data - { - attributes = CurrentAttributes, - statistics = CurrentStatistics, - omnimods = CurrentOmnimods - }. - -- cgit v1.2.3-70-g09d2