summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-08-28 23:29:55 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-08-28 23:29:55 +0200
commit9b424b11dbea33a41b2129daf232557515de9db1 (patch)
tree97cbe449c02e4273c79448859ceac722a06524b1 /src/shared
parent68d3f1d7fd3703a8aef68bd6e9f89a84eab5e539 (diff)
Still propagating the changes...
It'll require the attributes and statistics being recalculated every time a character is used, which isn't great. Can't exactly avoid it though: moving and changing weapon are both likely to alter them, and people rarely attack without doing one or the other.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/struct/shr_attributes.erl52
-rw-r--r--src/shared/struct/shr_omnimods.erl55
-rw-r--r--src/shared/struct/shr_statistics.erl155
-rw-r--r--src/shared/struct/shr_tile.erl.m42
4 files changed, 183 insertions, 81 deletions
diff --git a/src/shared/struct/shr_attributes.erl b/src/shared/struct/shr_attributes.erl
index 23824e4..c402e74 100644
--- a/src/shared/struct/shr_attributes.erl
+++ b/src/shared/struct/shr_attributes.erl
@@ -46,7 +46,9 @@
set_unsafe_intelligence/2,
set_unsafe_mind/2,
set_unsafe_speed/2,
- set_unsafe_strength/2
+ set_unsafe_strength/2,
+
+ apply_mod/3
]
).
@@ -54,7 +56,7 @@
-export
(
[
- random/0
+ default/0
]
).
@@ -64,6 +66,28 @@
-spec make_safe (integer()) -> non_neg_integer().
make_safe (Val) -> max(0, min(100, Val)).
+-spec mod_unsafe_constitution (integer(), type()) -> type().
+mod_unsafe_constitution (Val, Att) ->
+ set_constitution(make_safe(get_constitution(Att) + Val), Att).
+
+-spec mod_unsafe_dexterity (integer(), type()) -> type().
+mod_unsafe_dexterity (Val, Att) ->
+ set_dexterity(make_safe(get_dexterity(Att) + Val), Att).
+
+-spec mod_unsafe_intelligence (integer(), type()) -> type().
+mod_unsafe_intelligence (Val, Att) ->
+ set_intelligence(make_safe(get_intelligence(Att) + Val), Att).
+
+-spec mod_unsafe_mind (integer(), type()) -> type().
+mod_unsafe_mind (Val, Att) -> set_mind(make_safe(get_mind(Att) + Val), Att).
+
+-spec mod_unsafe_speed (integer(), type()) -> type().
+mod_unsafe_speed (Val, Att) -> set_speed(make_safe(get_speed(Att) + Val), Att).
+
+-spec mod_unsafe_strength (integer(), type()) -> type().
+mod_unsafe_strength (Val, Att) ->
+ set_strength(make_safe(get_strength(Att) + Val), Att).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -122,14 +146,22 @@ set_unsafe_speed (Val, Att) -> set_speed(make_safe(Val), Att).
-spec set_unsafe_strength (integer(), type()) -> type().
set_unsafe_strength (Val, Att) -> set_strength(make_safe(Val), Att).
--spec random () -> type().
-random () ->
+-spec default () -> type().
+default () ->
#attributes
{
- constitution = shr_roll:percentage(),
- dexterity = shr_roll:percentage(),
- intelligence = shr_roll:percentage(),
- mind = shr_roll:percentage(),
- speed = shr_roll:percentage(),
- strength = shr_roll:percentage()
+ constitution = 50,
+ dexterity = 50,
+ intelligence = 50,
+ mind = 50,
+ speed = 50,
+ strength = 50
}.
+
+-spec apply_mod (atom(), integer(), type()) -> type().
+apply_mod (con, Value, Att) -> mod_unsafe_constitution(Value, Att);
+apply_mod (dex, Value, Att) -> mod_unsafe_dexterity(Value, Att);
+apply_mod (int, Value, Att) -> mod_unsafe_intelligence(Value, Att);
+apply_mod (min, Value, Att) -> mod_unsafe_mind(Value, Att);
+apply_mod (spe, Value, Att) -> mod_unsafe_speed(Value, Att);
+apply_mod (str, Value, Att) -> mod_unsafe_strength(Value, Att).
diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl
index 03ec5af..31d61f2 100644
--- a/src/shared/struct/shr_omnimods.erl
+++ b/src/shared/struct/shr_omnimods.erl
@@ -24,6 +24,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
-export
(
[
@@ -32,7 +33,7 @@
]
).
-%%%% Accessors
+%%%% Modification
-export
(
[
@@ -41,15 +42,24 @@
]
).
+%%%% Access
-export
(
[
- apply_to_attributes/3,
- apply_to_statistics/3,
+ apply_to_attributes/2,
+ apply_to_statistics/2,
get_attack_damage/3
]
).
+%%%% Export
+-export
+(
+ [
+ encode/1
+ ]
+).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -69,6 +79,21 @@ apply_coefficient_to_mods (Coef, Mods) ->
merge_mods (ModsA, ModsB) ->
dict:merge(fun (_Name, ValA, ValB) -> (ValA + ValB) end, ModsA, ModsB).
+-spec encode_mods (mods()) -> list(any()).
+encode_mods (Mods) ->
+ lists:map
+ (
+ fun ({Name, Value}) ->
+ {
+ [
+ {<<"t">>, Name},
+ {<<"v">>, Value}
+ ]
+ }
+ end,
+ dict:to_list(Mods)
+ ).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -128,33 +153,31 @@ apply_coefficient (Coef, Omnimods) ->
defmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.defmods)
}.
-%%% Application
+%%% Access
-spec apply_to_attributes
(
- fun((atom(), integer(), shr_attributes:type()) -> shr_attributes:type()),
type(),
shr_attributes:type()
)
-> shr_attributes:type().
-apply_to_attributes (UpdateFun, Omnimods, Attributes) ->
+apply_to_attributes (Omnimods, Attributes) ->
dict:fold
(
- UpdateFun,
+ fun shr_attributes:apply_mod/3,
Attributes,
Omnimods#omnimods.attmods
).
-spec apply_to_statistics
(
- fun((atom(), integer(), shr_statistics:type()) -> shr_statistics:type()),
type(),
shr_statistics:type()
)
-> shr_statistics:type().
-apply_to_statistics (UpdateFun, Omnimods, Statistics) ->
+apply_to_statistics (Omnimods, Statistics) ->
dict:fold
(
- UpdateFun,
+ fun shr_statistics:apply_mod/3,
Statistics,
Omnimods#omnimods.attmods
).
@@ -187,3 +210,15 @@ get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) ->
),
Result.
+
+%%% Export
+-spec encode (type()) -> {list(any())}.
+encode (Omnimods) ->
+ {
+ [
+ {<<"attm">>, encode_mods(Omnimods#omnimods.attmods)},
+ {<<"stam">>, encode_mods(Omnimods#omnimods.stamods)},
+ {<<"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
index cf48d96..4249d52 100644
--- a/src/shared/struct/shr_statistics.erl
+++ b/src/shared/struct/shr_statistics.erl
@@ -11,11 +11,10 @@
health :: non_neg_integer(),
dodges :: non_neg_integer(),
parries :: non_neg_integer(),
- damage_min :: non_neg_integer(),
- damage_max :: non_neg_integer(),
accuracy :: non_neg_integer(),
double_hits :: non_neg_integer(),
- critical_hits :: non_neg_integer()
+ critical_hits :: non_neg_integer(),
+ damage_modifier :: float()
}
).
@@ -34,20 +33,19 @@
get_health/1,
get_dodges/1,
get_parries/1,
- get_damage_min/1,
- get_damage_max/1,
get_accuracy/1,
get_double_hits/1,
get_critical_hits/1,
+ get_damage_modifier/1,
- get_damages/1
+ apply_mod/3
]
).
-export
(
[
- new/3
+ new_raw/1
]
).
@@ -94,14 +92,76 @@ sudden_exp_growth (V) -> float_to_int(math:pow(4.0, V / 25.0)).
-spec damage_base_modifier (non_neg_integer()) -> float().
damage_base_modifier (Strength) -> ((math:pow(Strength, 1.8) / 2000.0) - 0.75).
--spec apply_damage_base_modifier
- (
- float(),
- non_neg_integer()
- )
- -> non_neg_integer().
-apply_damage_base_modifier (Modifier, BaseValue) ->
- max(0, float_to_int(BaseValue + (BaseValue * Modifier))).
+-spec make_movement_points_safe (non_neg_integer()) -> non_neg_integer().
+make_movement_points_safe (Val) -> min_max(0, 200, Val).
+
+-spec make_health_safe (non_neg_integer()) -> non_neg_integer().
+make_health_safe (Val) -> max(1, Val).
+
+-spec make_dodges_safe (non_neg_integer()) -> non_neg_integer().
+make_dodges_safe (Val) -> min_max(0, 100, Val).
+
+-spec make_parries_safe (non_neg_integer()) -> non_neg_integer().
+make_parries_safe (Val) -> min_max(0, 75, Val).
+
+-spec make_accuracy_safe (non_neg_integer()) -> non_neg_integer().
+make_accuracy_safe (Val) -> min_max(0, 100, Val).
+
+-spec make_double_hits_safe (non_neg_integer()) -> non_neg_integer().
+make_double_hits_safe (Val) -> min_max(0, 100, Val).
+
+-spec make_critical_hits_safe (non_neg_integer()) -> non_neg_integer().
+make_critical_hits_safe (Val) -> min_max(0, 100, Val).
+
+-spec mod_movement_points (integer(), type()) -> type().
+mod_movement_points (Mod, Stats) ->
+ Stats#statistics
+ {
+ movement_points =
+ make_movement_points_safe(get_movement_points(Stats) + Mod)
+ }.
+
+-spec mod_health (integer(), type()) -> type().
+mod_health (Mod, Stats) ->
+ Stats#statistics
+ {
+ health = make_health_safe(get_health(Stats) + Mod)
+ }.
+
+-spec mod_dodges (integer(), type()) -> type().
+mod_dodges (Mod, Stats) ->
+ Stats#statistics
+ {
+ dodges = make_dodges_safe(get_dodges(Stats) + Mod)
+ }.
+
+-spec mod_parries (integer(), type()) -> type().
+mod_parries (Mod, Stats) ->
+ Stats#statistics
+ {
+ parries = make_parries_safe(get_parries(Stats) + Mod)
+ }.
+
+-spec mod_accuracy (integer(), type()) -> type().
+mod_accuracy (Mod, Stats) ->
+ Stats#statistics
+ {
+ accuracy = make_accuracy_safe(get_accuracy(Stats) + Mod)
+ }.
+
+-spec mod_double_hits (integer(), type()) -> type().
+mod_double_hits (Mod, Stats) ->
+ Stats#statistics
+ {
+ double_hits = make_double_hits_safe(get_double_hits(Stats) + Mod)
+ }.
+
+-spec mod_critical_hits (integer(), type()) -> type().
+mod_critical_hits (Mod, Stats) ->
+ Stats#statistics
+ {
+ critical_hits = make_critical_hits_safe(get_critical_hits(Stats) + Mod)
+ }.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -119,12 +179,6 @@ get_dodges (Stats) -> Stats#statistics.dodges.
-spec get_parries (type()) -> non_neg_integer().
get_parries (Stats) -> Stats#statistics.parries.
--spec get_damage_min (type()) -> non_neg_integer().
-get_damage_min (Stats) -> Stats#statistics.damage_min.
-
--spec get_damage_max (type()) -> non_neg_integer().
-get_damage_max (Stats) -> Stats#statistics.damage_max.
-
-spec get_accuracy (type()) -> non_neg_integer().
get_accuracy (Stats) -> Stats#statistics.accuracy.
@@ -134,38 +188,17 @@ get_double_hits (Stats) -> Stats#statistics.double_hits.
-spec get_critical_hits (type()) -> non_neg_integer().
get_critical_hits (Stats) -> Stats#statistics.critical_hits.
--spec get_damages (type()) -> {non_neg_integer(), non_neg_integer()}.
-get_damages (Stats) ->
- {
- Stats#statistics.damage_min,
- Stats#statistics.damage_max
- }.
+-spec get_damage_modifier (type()) -> float().
+get_damage_modifier (Stats) -> Stats#statistics.damage_modifier.
--spec new
- (
- shr_attributes:type(),
- {shr_weapon:id(), shr_weapon:id()},
- shr_armor:id()
- )
- -> type().
-new (BaseAttributes, WeaponIDs, ArmorID) ->
- {ActiveWeaponID, _} = WeaponIDs,
- ActiveWeapon = shr_weapon:from_id(ActiveWeaponID),
- {MinDamage, MaxDamage} = shr_weapon:get_damages(ActiveWeapon),
- Armor = shr_armor:from_id(ArmorID),
- Attributes =
- shr_armor:apply_to_attributes
- (
- Armor,
- shr_weapon:apply_to_attributes(ActiveWeapon, BaseAttributes)
- ),
+-spec new_raw (shr_attributes:type()) -> type().
+new_raw (Attributes) ->
Constitution = shr_attributes:get_constitution(Attributes),
Dexterity = shr_attributes:get_dexterity(Attributes),
Intelligence = shr_attributes:get_intelligence(Attributes),
Mind = shr_attributes:get_mind(Attributes),
Speed = shr_attributes:get_speed(Attributes),
Strength = shr_attributes:get_strength(Attributes),
- DamageBaseModifier = damage_base_modifier(Strength),
#statistics
{
@@ -180,21 +213,23 @@ new (BaseAttributes, WeaponIDs, ArmorID) ->
average([Constitution, Constitution, Constitution, Mind])
),
dodges =
- min_max(0, 100, sudden_exp_growth(average([Dexterity, Mind, Speed]))),
+ sudden_exp_growth(average([Dexterity, Mind, Speed])),
parries =
- min_max
+ sudden_exp_growth
(
- 0,
- 75,
- sudden_exp_growth
- (
- average([Dexterity, Intelligence, Speed, Strength])
- )
+ average([Dexterity, Intelligence, Speed, Strength])
),
- damage_min = apply_damage_base_modifier(DamageBaseModifier, MinDamage),
- damage_max = apply_damage_base_modifier(DamageBaseModifier, MaxDamage),
- accuracy = min_max(0, 100, sudden_squared_growth(Dexterity)),
- double_hits =
- min_max(0, 100, sudden_squared_growth(average([Mind, Speed]))),
- critical_hits = min_max(0, 100, sudden_squared_growth(Intelligence))
+ accuracy = sudden_squared_growth(Dexterity),
+ double_hits = sudden_squared_growth(average([Mind, Speed])),
+ critical_hits = sudden_squared_growth(Intelligence),
+ damage_modifier = damage_base_modifier(Strength)
}.
+
+-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).
diff --git a/src/shared/struct/shr_tile.erl.m4 b/src/shared/struct/shr_tile.erl.m4
index 535bcde..750e59a 100644
--- a/src/shared/struct/shr_tile.erl.m4
+++ b/src/shared/struct/shr_tile.erl.m4
@@ -16,7 +16,7 @@
}
).
--opaque class_id() :: non_neg_integer().
+-type class_id() :: non_neg_integer().
-opaque instance() :: list(non_neg_integer()).
-opaque border() :: list(non_neg_integer()).