From 9b424b11dbea33a41b2129daf232557515de9db1 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Tue, 28 Aug 2018 23:29:55 +0200 Subject: 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. --- src/shared/struct/shr_omnimods.erl | 55 +++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'src/shared/struct/shr_omnimods.erl') 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)} + ] + }. -- cgit v1.2.3-70-g09d2