aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-01-17 16:34:10 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-01-17 16:34:10 +0100
commit437d7bea7d2f018ba81741ae691dc543df535eeb (patch)
treec13b7a130ade07e1c66d5b6c89d898983a14c9ae
parent0cbf2c544d133ba32dc668d30b071cb033496ba3 (diff)
downloadtacticians-server-437d7bea7d2f018ba81741ae691dc543df535eeb.zip
tacticians-server-437d7bea7d2f018ba81741ae691dc543df535eeb.tar.bz2
Starting a new branch to add stats.
-rw-r--r--src/calc/calc_stats.erl29
-rw-r--r--src/type/character_instance.erl34
2 files changed, 61 insertions, 2 deletions
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).