| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-06-07 13:27:04 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-06-07 13:27:04 +0200 | 
| commit | 54250bfbaf0eeeceaec86cde2df39797f83397fd (patch) | |
| tree | 3803d1202d7babaec8f6af6d3098d6d33ddc7cdc | |
| parent | 9b55ecea81edbc12196a5818077fd38421f8f1a8 (diff) | |
Adding server-side armors data.
Will remove weapon and armor data from the client, as the relevant
equipment's data will be sent by load_state queries.
| -rw-r--r-- | src/shared/struct/sh_armor.erl | 144 | ||||
| -rw-r--r-- | src/shared/struct/sh_attributes.erl | 65 | 
2 files changed, 190 insertions, 19 deletions
diff --git a/src/shared/struct/sh_armor.erl b/src/shared/struct/sh_armor.erl new file mode 100644 index 0000000..4156016 --- /dev/null +++ b/src/shared/struct/sh_armor.erl @@ -0,0 +1,144 @@ +-module(sh_armor). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-opaque id() :: non_neg_integer(). + +-type category() :: 'kinetic' | 'leather' | 'chain' | 'plate'. + +-record +( +   armor, +   { +      id :: id(), +      name :: binary(), +      category :: category(), +      coef :: float() +   } +). + +-opaque type() :: #armor{}. + +-export_type([type/0, id/0]). +-export_type ([category/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( +   [ +      get_id/1, +      get_name/1, +      get_coef/1, +      get_category/1 +   ] +). + +-export +( +   [ +      random_id/0, +      from_id/1, +      apply_to_attributes/2 +   ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-spec get_id (type()) -> id(). +get_id (Ar) -> Ar#armor.id. + +-spec get_name (type()) -> binary(). +get_name (Ar) -> Ar#armor.name. + +-spec get_coef (type()) -> float(). +get_coef (Ar) -> Ar#armor.coef. + +-spec get_category (type()) -> category(). +get_category (Ar) -> Ar#armor.category. + +-spec from_id (id()) -> type(). +from_id (0) -> +   #armor{ +      id = 0, +      name = <<"None">>, +      category = leather, +      coef = 0.0 +   }; +from_id (1) -> +   #armor{ +      id = 1, +      name = <<"Last Meal's Pelts">>, +      category = leather, +      coef = 0.5 +   }; +from_id (2) -> +   #armor{ +      id = 2, +      name = <<"Bits of Wall">>, +      category = plate, +      coef = 0.5 +   }; +from_id (3) -> +   #armor{ +      id = 3, +      name = <<"Garden Fence">>, +      category = chain, +      coef = 0.5 +   }; +from_id (4) -> +   #armor{ +      id = 4, +      name = <<"Morrigan's Pity">>, +      category = kinetic, +      coef = 0.5 +   }. + +-spec random_id () -> id(). +random_id () -> sh_roll:between(0, 24). + +-spec apply_to_attributes +   ( +      sh_attributes:type(), +      type() +   ) +   -> sh_attributes:type(). +apply_to_attributes (Att, Ar) -> +   Dexterity = sh_attributes:get_dexterity(Att), +   Speed = sh_attributes:get_speed(Att), +   Strength = sh_attributes:get_strength(Att), +   Mind = sh_attributes:get_mind(Att), +   Impact = erlang:ceil(-20.0 * Ar#armor.coef), +   Category = Ar#armor.category, + +   case Category of +      kinetic -> sh_attributes:set_unsafe_mind((Mind - Impact), Att); +      leather -> sh_attributes:set_unsafe_dexterity((Dexterity - Impact), Att); +      chain -> +         sh_attributes:set_unsafe_dexterity +         ( +            (Dexterity - Impact), +            sh_attributes:set_unsafe_speed((Speed - Impact), Att) +         ); + +      plate -> +         sh_attributes:set_unsafe_dexterity +         ( +            (Dexterity - Impact), +            sh_attributes:set_unsafe_speed +            ( +               (Speed - Impact), +               sh_attributes:set_unsafe_strength((Strength - Impact), Att) +            ) +         ) +   end. diff --git a/src/shared/struct/sh_attributes.erl b/src/shared/struct/sh_attributes.erl index 93dcfc6..9b4478f 100644 --- a/src/shared/struct/sh_attributes.erl +++ b/src/shared/struct/sh_attributes.erl @@ -7,12 +7,12 @@  (     attributes,     { -      constitution :: integer(), -      dexterity :: integer(), -      intelligence :: integer(), -      mind :: integer(), -      speed :: integer(), -      strength :: integer() +      constitution :: non_neg_integer(), +      dexterity :: non_neg_integer(), +      intelligence :: non_neg_integer(), +      mind :: non_neg_integer(), +      speed :: non_neg_integer(), +      strength :: non_neg_integer()     }  ). @@ -39,7 +39,14 @@        set_intelligence/2,        set_mind/2,        set_speed/2, -      set_strength/2 +      set_strength/2, + +      set_unsafe_constitution/2, +      set_unsafe_dexterity/2, +      set_unsafe_intelligence/2, +      set_unsafe_mind/2, +      set_unsafe_speed/2, +      set_unsafe_strength/2     ]  ). @@ -54,47 +61,67 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec make_safe (integer()) -> non_neg_integer(). +make_safe (Val) -> max(0, min(100, Val)).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%% Accessors --spec get_constitution (type()) -> integer(). +-spec get_constitution (type()) -> non_neg_integer().  get_constitution (Att) -> Att#attributes.constitution. --spec get_dexterity (type()) -> integer(). +-spec get_dexterity (type()) -> non_neg_integer().  get_dexterity (Att) -> Att#attributes.dexterity. --spec get_intelligence (type()) -> integer(). +-spec get_intelligence (type()) -> non_neg_integer().  get_intelligence (Att) -> Att#attributes.intelligence. --spec get_mind (type()) -> integer(). +-spec get_mind (type()) -> non_neg_integer().  get_mind (Att) -> Att#attributes.mind. --spec get_speed (type()) -> integer(). +-spec get_speed (type()) -> non_neg_integer().  get_speed (Att) -> Att#attributes.speed. --spec get_strength (type()) -> integer(). +-spec get_strength (type()) -> non_neg_integer().  get_strength (Att) -> Att#attributes.strength. --spec set_constitution (integer(), type()) -> type(). +-spec set_constitution (non_neg_integer(), type()) -> type().  set_constitution (Val, Att) -> Att#attributes{ constitution = Val }. --spec set_dexterity (integer(), type()) -> type(). +-spec set_dexterity (non_neg_integer(), type()) -> type().  set_dexterity (Val, Att) -> Att#attributes{ dexterity = Val }. --spec set_intelligence (integer(), type()) -> type(). +-spec set_intelligence (non_neg_integer(), type()) -> type().  set_intelligence (Val, Att) -> Att#attributes{ intelligence = Val }. --spec set_mind (integer(), type()) -> type(). +-spec set_mind (non_neg_integer(), type()) -> type().  set_mind (Val, Att) -> Att#attributes{ mind = Val }. --spec set_speed (integer(), type()) -> type(). +-spec set_speed (non_neg_integer(), type()) -> type().  set_speed (Val, Att) -> Att#attributes{ speed = Val }. --spec set_strength (integer(), type()) -> type(). +-spec set_strength (non_neg_integer(), type()) -> type().  set_strength (Val, Att) -> Att#attributes{ strength = Val }. +-spec set_unsafe_constitution (integer(), type()) -> type(). +set_unsafe_constitution (Val, Att) -> set_constitution(make_safe(Val), Att). + +-spec set_unsafe_dexterity (integer(), type()) -> type(). +set_unsafe_dexterity (Val, Att) -> set_dexterity(make_safe(Val), Att). + +-spec set_unsafe_intelligence (integer(), type()) -> type(). +set_unsafe_intelligence (Val, Att) -> set_intelligence(make_safe(Val), Att). + +-spec set_unsafe_mind (integer(), type()) -> type(). +set_unsafe_mind (Val, Att) -> set_mind(make_safe(Val), Att). + +-spec set_unsafe_speed (integer(), type()) -> type(). +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 () ->     #attributes  | 


