From 9d45e68f8daa748c58e28c77434b1377c508e32f Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 10 Aug 2019 14:49:13 +0200 Subject: Statistics -> Attributes. --- src/battle/mechanic/action/btl_action_attack.erl | 46 +++---- src/battle/mechanic/action/btl_action_move.erl | 4 +- src/battle/struct/btl_character.erl | 8 +- src/shared/struct/shr_attributes.erl | 147 +++++++++++++++++++++++ src/shared/struct/shr_character.erl | 32 ++--- src/shared/struct/shr_omnimods.erl | 28 ++--- src/shared/struct/shr_statistics.erl | 147 ----------------------- 7 files changed, 206 insertions(+), 206 deletions(-) create mode 100644 src/shared/struct/shr_attributes.erl delete mode 100644 src/shared/struct/shr_statistics.erl (limited to 'src') diff --git a/src/battle/mechanic/action/btl_action_attack.erl b/src/battle/mechanic/action/btl_action_attack.erl index 56524af..04becc8 100644 --- a/src/battle/mechanic/action/btl_action_attack.erl +++ b/src/battle/mechanic/action/btl_action_attack.erl @@ -18,14 +18,14 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec roll_precision_modifier ( - shr_statistics:type(), - shr_statistics:type(), + shr_attributes:type(), + shr_attributes:type(), integer() ) -> {float(), integer(), integer()}. -roll_precision_modifier (Statistics, TargetStatistics, TargetLuck) -> - TargetDodges = shr_statistics:get_dodges(TargetStatistics), - Accuracy = shr_statistics:get_accuracy(Statistics), +roll_precision_modifier (Attributes, TargetAttributes, TargetLuck) -> + TargetDodges = shr_attributes:get_dodges(TargetAttributes), + Accuracy = shr_attributes:get_accuracy(Attributes), MissChance = max(0, (TargetDodges - Accuracy)), {Roll, _IsSuccess, PositiveModifier, NegativeModifier} = @@ -43,12 +43,12 @@ roll_precision_modifier (Statistics, TargetStatistics, TargetLuck) -> -spec roll_critical_modifier ( - shr_statistics:type(), + shr_attributes:type(), integer() ) -> {float(), integer(), integer()}. -roll_critical_modifier (Statistics, Luck) -> - CriticalHitChance = shr_statistics:get_critical_hits(Statistics), +roll_critical_modifier (Attributes, Luck) -> + CriticalHitChance = shr_attributes:get_critical_hits(Attributes), {_Roll, IsSuccess, PositiveModifier, NegativeModifier} = shr_roll:percentage_with_luck(CriticalHitChance, Luck), @@ -63,12 +63,12 @@ roll_critical_modifier (Statistics, Luck) -> -spec roll_parry ( - shr_statistics:type(), + shr_attributes:type(), integer() ) -> {boolean(), integer(), integer()}. -roll_parry (DefenderStatistics, DefenderLuck) -> - DefenderParryChance = shr_statistics:get_parries(DefenderStatistics), +roll_parry (DefenderAttributes, DefenderLuck) -> + DefenderParryChance = shr_attributes:get_parries(DefenderAttributes), {_Roll, IsSuccess, PositiveModifier, NegativeModifier} = shr_roll:percentage_with_luck(DefenderParryChance, DefenderLuck), @@ -265,12 +265,12 @@ effect_of_attack {ParryIsSuccessful, ParryPositiveLuckMod, ParryNegativeLuckMod} = case TargetCanParry of true -> - TargetStatistics = - shr_character:get_statistics + TargetAttributes = + shr_character:get_attributes ( btl_character:get_base_character(TargetCharacter) ), - roll_parry(TargetStatistics, TargetLuck); + roll_parry(TargetAttributes, TargetLuck); false -> {false, 0, 0} end, @@ -282,20 +282,20 @@ effect_of_attack end, AttackerBaseCharacter = btl_character:get_base_character(Attacker), - AttackerStatistics = shr_character:get_statistics(AttackerBaseCharacter), + AttackerAttributes = shr_character:get_attributes(AttackerBaseCharacter), DefenderBaseCharacter = btl_character:get_base_character(S0Defender), - DefenderStatistics = shr_character:get_statistics(DefenderBaseCharacter), + DefenderAttributes = shr_character:get_attributes(DefenderBaseCharacter), {PrecisionModifier, PrecisionPositiveLuckMod, PrecisionNegativeLuckMod} = roll_precision_modifier ( - AttackerStatistics, - DefenderStatistics, + AttackerAttributes, + DefenderAttributes, S0DefenderLuck ), {CriticalModifier, CriticalPositiveLuckMod, CriticalNegativeLuckMod} = - roll_critical_modifier(AttackerStatistics, S0AttackerLuck), + roll_critical_modifier(AttackerAttributes, S0AttackerLuck), Damage = shr_omnimods:get_attack_damage @@ -303,7 +303,7 @@ effect_of_attack ( PrecisionModifier * CriticalModifier - * shr_statistics:get_damage_modifier(AttackerStatistics) + * shr_attributes:get_damage_modifier(AttackerAttributes) ), shr_character:get_omnimods(AttackerBaseCharacter), shr_character:get_omnimods(DefenderBaseCharacter) @@ -513,12 +513,12 @@ handle_attack_sequence ) of true -> - Statistics = - shr_character:get_statistics + Attributes = + shr_character:get_attributes ( btl_character:get_base_character(S0Character) ), - DoubleAttackChance = shr_statistics:get_double_hits(Statistics), + DoubleAttackChance = shr_attributes:get_double_hits(Attributes), {_Roll, IsSuccessful, PositiveModifier, NegativeModifier} = shr_roll:percentage_with_luck(DoubleAttackChance, S0PlayerLuck), diff --git a/src/battle/mechanic/action/btl_action_move.erl b/src/battle/mechanic/action/btl_action_move.erl index 643912c..ebc79db 100644 --- a/src/battle/mechanic/action/btl_action_move.erl +++ b/src/battle/mechanic/action/btl_action_move.erl @@ -369,9 +369,9 @@ get_path_cost_and_destination (CharacterIX, Character, Update, Path) -> get_movement_points (Action, Character) -> case btl_action:get_movement_points(Action) of -1 -> - shr_statistics:get_movement_points + shr_attributes:get_movement_points ( - shr_character:get_statistics + shr_character:get_attributes ( btl_character:get_base_character(Character) ) diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 790c809..f5f7ee0 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -111,10 +111,10 @@ -> {boolean(), integer()}. handle_max_health_change (OldBaseChar, NewBaseChar, OldHealth) -> OldMaxHealth = - shr_statistics:get_health(shr_character:get_statistics(OldBaseChar)), + shr_attributes:get_health(shr_character:get_attributes(OldBaseChar)), NewMaxHealth = - shr_statistics:get_health(shr_character:get_statistics(NewBaseChar)), + shr_attributes:get_health(shr_character:get_attributes(NewBaseChar)), case (OldMaxHealth == NewMaxHealth) of true -> {false, OldHealth}; @@ -427,14 +427,14 @@ new Location, Base ) -> - Statistics = shr_character:get_statistics(Base), + Attributes = shr_character:get_attributes(Base), #btl_char { player_ix = PlayerIX, rank = Rank, location = Location, - current_health = shr_statistics:get_health(Statistics), + current_health = shr_attributes:get_health(Attributes), is_active = (PlayerIX == 0), is_defeated = false, base = Base diff --git a/src/shared/struct/shr_attributes.erl b/src/shared/struct/shr_attributes.erl new file mode 100644 index 0000000..cd3aedf --- /dev/null +++ b/src/shared/struct/shr_attributes.erl @@ -0,0 +1,147 @@ +-module(shr_attributes). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + attributes, + { + movement_points :: non_neg_integer(), + health :: non_neg_integer(), + dodges :: integer(), + parries :: integer(), + accuracy :: integer(), + double_hits :: integer(), + critical_hits :: integer(), + damage_modifier :: integer() + } +). + +-opaque type() :: #attributes{}. + +-export_type([type/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_movement_points/1, + get_health/1, + get_dodges/1, + get_parries/1, + get_accuracy/1, + get_double_hits/1, + get_critical_hits/1, + get_damage_modifier/1, + get_damage_multiplier/1, + + apply_mod/3 + ] +). + +-export +( + [ + default/0 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec mod_movement_points (integer(), type()) -> type(). +mod_movement_points (Mod, Atts) -> + Atts#attributes + { + movement_points = (Atts#attributes.movement_points + Mod) + }. + +-spec mod_health (integer(), type()) -> type(). +mod_health (Mod, Atts) -> + Atts#attributes{ health = (Atts#attributes.health + Mod) }. + +-spec mod_dodges (integer(), type()) -> type(). +mod_dodges (Mod, Atts) -> + Atts#attributes{ dodges = (Atts#attributes.dodges + Mod) }. + +-spec mod_parries (integer(), type()) -> type(). +mod_parries (Mod, Atts) -> + Atts#attributes{ parries = (Atts#attributes.parries + Mod) }. + +-spec mod_accuracy (integer(), type()) -> type(). +mod_accuracy (Mod, Atts) -> + Atts#attributes{ accuracy = (Atts#attributes.accuracy + Mod) }. + +-spec mod_double_hits (integer(), type()) -> type(). +mod_double_hits (Mod, Atts) -> + Atts#attributes{ double_hits = (Atts#attributes.double_hits + Mod) }. + +-spec mod_critical_hits (integer(), type()) -> type(). +mod_critical_hits (Mod, Atts) -> + Atts#attributes{ critical_hits = (Atts#attributes.critical_hits + Mod) }. + +-spec mod_damage_modifier (integer(), type()) -> type(). +mod_damage_modifier (Mod, Atts) -> + Atts#attributes + { + damage_modifier = (Atts#attributes.damage_modifier + Mod) + }. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-spec get_movement_points (type()) -> non_neg_integer(). +get_movement_points (Atts) -> max(0, Atts#attributes.movement_points). + +-spec get_health (type()) -> non_neg_integer(). +get_health (Atts) -> max(1, Atts#attributes.health). + +-spec get_dodges (type()) -> non_neg_integer(). +get_dodges (Atts) -> max(0, Atts#attributes.dodges). + +-spec get_parries (type()) -> non_neg_integer(). +get_parries (Atts) -> max(0, Atts#attributes.parries). + +-spec get_accuracy (type()) -> non_neg_integer(). +get_accuracy (Atts) -> max(0, Atts#attributes.accuracy). + +-spec get_double_hits (type()) -> non_neg_integer(). +get_double_hits (Atts) -> max(0, Atts#attributes.double_hits). + +-spec get_critical_hits (type()) -> non_neg_integer(). +get_critical_hits (Atts) -> max(0, Atts#attributes.critical_hits). + +-spec get_damage_modifier (type()) -> non_neg_integer(). +get_damage_modifier (Atts) -> max(0, Atts#attributes.damage_modifier). + +-spec get_damage_multiplier (type()) -> float(). +get_damage_multiplier (Atts) -> (get_damage_modifier(Atts) / 100). + +-spec default () -> type(). +default () -> + #attributes + { + movement_points = 0, + health = 1, + dodges = 0, + parries = 0, + accuracy = 0, + double_hits = 0, + critical_hits = 0, + damage_modifier = 100 + }. + +-spec apply_mod (atom(), integer(), type()) -> type(). +apply_mod(mheal, Value, Atts) -> mod_health(Value, Atts); +apply_mod(mpts, Value, Atts) -> mod_movement_points(Value, Atts); +apply_mod(dodg, Value, Atts) -> mod_dodges(Value, Atts); +apply_mod(pary, Value, Atts) -> mod_parries(Value, Atts); +apply_mod(accu, Value, Atts) -> mod_accuracy(Value, Atts); +apply_mod(dhit, Value, Atts) -> mod_double_hits(Value, Atts); +apply_mod(crit, Value, Atts) -> mod_critical_hits(Value, Atts); +apply_mod(dmgm, Value, Atts) -> mod_damage_modifier(Value, Atts). diff --git a/src/shared/struct/shr_character.erl b/src/shared/struct/shr_character.erl index c2155cf..869a742 100644 --- a/src/shared/struct/shr_character.erl +++ b/src/shared/struct/shr_character.erl @@ -24,7 +24,7 @@ name :: binary(), equipment :: shr_equipment:type(), is_using_secondary :: boolean(), - statistics :: shr_statistics:type(), + attributes :: shr_attributes:type(), equipment_but_weapons_omnimods :: shr_omnimods:type(), extra_omnimods :: shr_omnimods:type(), omnimods :: shr_omnimods:type() @@ -45,7 +45,7 @@ [ get_name/1, get_equipment/1, - get_statistics/1, + get_attributes/1, get_active_weapon/1, get_inactive_weapon/1, get_omnimods/1, @@ -169,15 +169,15 @@ set_equipment (Eq, Char) when is_record(Char, shr_char) -> Char#shr_char.extra_omnimods ), - NewStatistics = - shr_omnimods:apply_to_statistics(NewOmnimods, shr_statistics:default()), + NewAttributes = + shr_omnimods:apply_to_attributes(NewOmnimods, shr_attributes:default()), Char#shr_char { equipment = Eq, equipment_but_weapons_omnimods = EquipmentButWeaponsOmnimods, omnimods = NewOmnimods, - statistics = NewStatistics + attributes = NewAttributes }; set_equipment (EqRef, CharRef) when is_record(CharRef, shr_char_ref) -> CharRef#shr_char_ref{ equipment = EqRef }. @@ -232,14 +232,14 @@ switch_weapons (Char) when is_record(Char, shr_char) -> ActiveWeaponOmnimods ), - NewStatistics = - shr_omnimods:apply_to_statistics(NewOmnimods, shr_statistics:default()), + NewAttributes = + shr_omnimods:apply_to_attributes(NewOmnimods, shr_attributes:default()), Char#shr_char { is_using_secondary = (not Char#shr_char.is_using_secondary), omnimods = NewOmnimods, - statistics = NewStatistics + attributes = NewAttributes }; switch_weapons (Char) when is_record(Char, shr_char_ref) -> Char#shr_char_ref @@ -284,8 +284,8 @@ get_inactive_weapon (#shr_char_ref{ is_using_secondary = B, equipment = E }) -> true -> shr_equipment:get_primary_weapon(E) end. --spec get_statistics (type()) -> shr_statistics:type(). -get_statistics (Char) -> Char#shr_char.statistics. +-spec get_attributes (type()) -> shr_attributes:type(). +get_attributes (Char) -> Char#shr_char.attributes. -spec get_omnimods (type()) -> shr_omnimods:type(). get_omnimods (Char) -> Char#shr_char.omnimods. @@ -303,14 +303,14 @@ set_extra_omnimods (O, Char) -> O ), - NewStatistics = - shr_omnimods:apply_to_statistics(NewOmnimods, shr_statistics:default()), + NewAttributes = + shr_omnimods:apply_to_attributes(NewOmnimods, shr_attributes:default()), Char#shr_char { extra_omnimods = O, omnimods = NewOmnimods, - statistics = NewStatistics + attributes = NewAttributes }. -spec resolve (shr_omnimods:type(), unresolved()) -> type(). @@ -330,8 +330,8 @@ resolve (LocalOmnimods, CharRef) -> LocalOmnimods ), - NewStatistics = - shr_omnimods:apply_to_statistics(NewOmnimods, shr_statistics:default()), + NewAttributes = + shr_omnimods:apply_to_attributes(NewOmnimods, shr_attributes:default()), #shr_char { @@ -339,7 +339,7 @@ resolve (LocalOmnimods, CharRef) -> equipment_but_weapons_omnimods = EquipmentButWeaponsOmnimods, equipment = Eq, is_using_secondary = CharRef#shr_char_ref.is_using_secondary, - statistics = NewStatistics, + attributes = NewAttributes, omnimods = NewOmnimods, extra_omnimods = LocalOmnimods }. diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl index fd35a94..7602e1f 100644 --- a/src/shared/struct/shr_omnimods.erl +++ b/src/shared/struct/shr_omnimods.erl @@ -10,7 +10,7 @@ ( omnimods, { - stamods :: mods(), + attmods :: mods(), atkmods :: mods(), defmods :: mods() } @@ -45,7 +45,7 @@ -export ( [ - apply_to_statistics/2, + apply_to_attributes/2, get_attack_damage/3 ] ). @@ -89,10 +89,10 @@ encode_mods (Mods) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Creation -spec new (list(entry()), list(entry()), list(entry())) -> type(). -new (StatisticMods, AttackMods, DefenseMods) -> +new (AttributeMods, AttackMods, DefenseMods) -> #omnimods { - stamods = dict:from_list(StatisticMods), + attmods = dict:from_list(AttributeMods), atkmods = dict:from_list(AttackMods), defmods = dict:from_list(DefenseMods) }. @@ -105,7 +105,7 @@ default () -> new([], [], []). merge (OmniA, OmniB) -> OmniA#omnimods { - stamods = merge_mods(OmniA#omnimods.stamods, OmniB#omnimods.stamods), + attmods = merge_mods(OmniA#omnimods.attmods, OmniB#omnimods.attmods), atkmods = merge_mods(OmniA#omnimods.atkmods, OmniB#omnimods.atkmods), defmods = merge_mods(OmniA#omnimods.defmods, OmniB#omnimods.defmods) }. @@ -114,23 +114,23 @@ merge (OmniA, OmniB) -> apply_coefficient (Coef, Omnimods) -> Omnimods#omnimods { - stamods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.stamods), + attmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.attmods), atkmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.atkmods), defmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.defmods) }. --spec apply_to_statistics +-spec apply_to_attributes ( type(), - shr_statistics:type() + shr_attributes:type() ) - -> shr_statistics:type(). -apply_to_statistics (Omnimods, Statistics) -> + -> shr_attributes:type(). +apply_to_attributes (Omnimods, Attributes) -> dict:fold ( - fun shr_statistics:apply_mod/3, - Statistics, - Omnimods#omnimods.stamods + fun shr_attributes:apply_mod/3, + Attributes, + Omnimods#omnimods.attmods ). -spec get_attack_damage (float(), type(), type()) -> non_neg_integer(). @@ -196,7 +196,7 @@ get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) -> encode (Omnimods) -> { [ - {<<"stam">>, encode_mods(Omnimods#omnimods.stamods)}, + {<<"attm">>, encode_mods(Omnimods#omnimods.attmods)}, {<<"atkm">>, encode_mods(Omnimods#omnimods.atkmods)}, {<<"defm">>, encode_mods(Omnimods#omnimods.defmods)} ] diff --git a/src/shared/struct/shr_statistics.erl b/src/shared/struct/shr_statistics.erl deleted file mode 100644 index a5ba69f..0000000 --- a/src/shared/struct/shr_statistics.erl +++ /dev/null @@ -1,147 +0,0 @@ --module(shr_statistics). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - statistics, - { - movement_points :: non_neg_integer(), - health :: non_neg_integer(), - dodges :: integer(), - parries :: integer(), - accuracy :: integer(), - double_hits :: integer(), - critical_hits :: integer(), - damage_modifier :: integer() - } -). - --opaque type() :: #statistics{}. - --export_type([type/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_movement_points/1, - get_health/1, - get_dodges/1, - get_parries/1, - get_accuracy/1, - get_double_hits/1, - get_critical_hits/1, - get_damage_modifier/1, - get_damage_multiplier/1, - - apply_mod/3 - ] -). - --export -( - [ - default/0 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec mod_movement_points (integer(), type()) -> type(). -mod_movement_points (Mod, Stats) -> - Stats#statistics - { - movement_points = (Stats#statistics.movement_points + Mod) - }. - --spec mod_health (integer(), type()) -> type(). -mod_health (Mod, Stats) -> - Stats#statistics{ health = (Stats#statistics.health + Mod) }. - --spec mod_dodges (integer(), type()) -> type(). -mod_dodges (Mod, Stats) -> - Stats#statistics{ dodges = (Stats#statistics.dodges + Mod) }. - --spec mod_parries (integer(), type()) -> type(). -mod_parries (Mod, Stats) -> - Stats#statistics{ parries = (Stats#statistics.parries + Mod) }. - --spec mod_accuracy (integer(), type()) -> type(). -mod_accuracy (Mod, Stats) -> - Stats#statistics{ accuracy = (Stats#statistics.accuracy + Mod) }. - --spec mod_double_hits (integer(), type()) -> type(). -mod_double_hits (Mod, Stats) -> - Stats#statistics{ double_hits = (Stats#statistics.double_hits + Mod) }. - --spec mod_critical_hits (integer(), type()) -> type(). -mod_critical_hits (Mod, Stats) -> - Stats#statistics{ critical_hits = (Stats#statistics.critical_hits + Mod) }. - --spec mod_damage_modifier (integer(), type()) -> type(). -mod_damage_modifier (Mod, Stats) -> - Stats#statistics - { - damage_modifier = (Stats#statistics.damage_modifier + Mod) - }. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_movement_points (type()) -> non_neg_integer(). -get_movement_points (Stats) -> max(0, Stats#statistics.movement_points). - --spec get_health (type()) -> non_neg_integer(). -get_health (Stats) -> max(1, Stats#statistics.health). - --spec get_dodges (type()) -> non_neg_integer(). -get_dodges (Stats) -> max(0, Stats#statistics.dodges). - --spec get_parries (type()) -> non_neg_integer(). -get_parries (Stats) -> max(0, Stats#statistics.parries). - --spec get_accuracy (type()) -> non_neg_integer(). -get_accuracy (Stats) -> max(0, Stats#statistics.accuracy). - --spec get_double_hits (type()) -> non_neg_integer(). -get_double_hits (Stats) -> max(0, Stats#statistics.double_hits). - --spec get_critical_hits (type()) -> non_neg_integer(). -get_critical_hits (Stats) -> max(0, Stats#statistics.critical_hits). - --spec get_damage_modifier (type()) -> non_neg_integer(). -get_damage_modifier (Stats) -> max(0, Stats#statistics.damage_modifier). - --spec get_damage_multiplier (type()) -> float(). -get_damage_multiplier (Stats) -> (get_damage_modifier(Stats) / 100). - --spec default () -> type(). -default () -> - #statistics - { - movement_points = 0, - health = 1, - dodges = 0, - parries = 0, - accuracy = 0, - double_hits = 0, - critical_hits = 0, - damage_modifier = 100 - }. - --spec apply_mod (atom(), integer(), type()) -> type(). -apply_mod(mheal, Value, Stats) -> mod_health(Value, Stats); -apply_mod(mpts, Value, Stats) -> mod_movement_points(Value, Stats); -apply_mod(dodg, Value, Stats) -> mod_dodges(Value, Stats); -apply_mod(pary, Value, Stats) -> mod_parries(Value, Stats); -apply_mod(accu, Value, Stats) -> mod_accuracy(Value, Stats); -apply_mod(dhit, Value, Stats) -> mod_double_hits(Value, Stats); -apply_mod(crit, Value, Stats) -> mod_critical_hits(Value, Stats); -apply_mod(dmgm, Value, Stats) -> mod_damage_modifier(Value, Stats). -- cgit v1.2.3-70-g09d2