From 437d7bea7d2f018ba81741ae691dc543df535eeb Mon Sep 17 00:00:00 2001 From: nsensfel Date: Wed, 17 Jan 2018 16:34:10 +0100 Subject: Starting a new branch to add stats. --- src/calc/calc_stats.erl | 29 +++++++++++++++++++++++++++++ src/type/character_instance.erl | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/calc/calc_stats.erl diff --git a/src/calc/calc_stats.erl b/src/calc/calc_stats.erl new file mode 100644 index 0000000..65a3aec --- /dev/null +++ b/src/calc/calc_stats.erl @@ -0,0 +1,29 @@ +-module(calc_stats). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + weapon_min_damage/2, + weapon_hit_chances/1 + ] +). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +weapon_min_damage (WeaponProf) -> + +weapon_hit_chances (WeaponProf) -> + HitChance = 50 + trunc(math:ceil(WeaponProf / 2)), + case HitChance of + % Not a satisfactory way to handle double hits, as it does not allow + % the players to specialize their characters for it. + N when N > 75 -> {HitChance, 75 - HitChance}; + _ -> {HitChance, 0} + end. diff --git a/src/type/character_instance.erl b/src/type/character_instance.erl index ee50460..3fc7171 100644 --- a/src/type/character_instance.erl +++ b/src/type/character_instance.erl @@ -10,7 +10,12 @@ x, y, health, - team + team, + active_wp, + min_dmg, + max_dmg, + hit_chance, + double_hit_chance } ). @@ -34,6 +39,7 @@ ( [ new_instance_of/3, + switch_weapon/2, is_dead/1 % is_alive is reserved. ] ). @@ -41,6 +47,16 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +get_new_weapon(CharInst, Char) -> + case CharInst#character_instance.active_wp of + 0 -> + {_, Weapon} = character:get_weapons(Char), + {1, Weapon}; + + 1 -> + {Weapon, _} = character:get_weapons(Char), + {0, Weapon} + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -80,7 +96,21 @@ new_instance_of (Char, Owner, {X, Y}) -> x = X, y = Y, health = character:get_max_health(Char), - team = Owner + team = Owner, + active_wp = 0 + }. + +switch_weapon (CharInst, Char) -> + {NewWpIndex, Weapon} = get_new_weapon(CharInst, Char), + WeaponProf = character:get_proficiency(Char, weapon:get_type(Weapon)), + {HitChance, DoubleHitChance} = calc_stats:weapon_hit_chances(WeaponProf), + CharInst#character_instance + { + active_wp = NewWpIndex, + min_dmg = calc_stats:weapon_min_damage(Weapon, WeaponProf), + max_dmg = weapon:get_max_damage(Weapon), + hit_chance = HitChance, + double_hit_chance = DoubleHitChance }. is_dead (CharInst) -> (CharInst#character_instance.health == 0). -- cgit v1.2.3-70-g09d2