| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/struct/shr_attributes.erl | 110 | ||||
| -rw-r--r-- | src/shared/struct/shr_damage_type.erl | 2 | ||||
| -rw-r--r-- | src/shared/struct/shr_omnimods.erl | 115 | 
3 files changed, 169 insertions, 58 deletions
| diff --git a/src/shared/struct/shr_attributes.erl b/src/shared/struct/shr_attributes.erl index cd3aedf..44d2e04 100644 --- a/src/shared/struct/shr_attributes.erl +++ b/src/shared/struct/shr_attributes.erl @@ -1,5 +1,7 @@  -module(shr_attributes). +-include("tacticians/attributes.hrl"). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -9,18 +11,36 @@     {        movement_points :: non_neg_integer(),        health :: non_neg_integer(), -      dodges :: integer(), -      parries :: integer(), +      dodge_chance :: integer(), +      parry_chance :: integer(),        accuracy :: integer(), -      double_hits :: integer(), -      critical_hits :: integer(), +      double_hit_chance :: integer(), +      critical_hit_chance :: integer(),        damage_modifier :: integer()     }  ).  -opaque type() :: #attributes{}. - --export_type([type/0]). +-type enum() :: +   ( +      ?ATTRIBUTE_ACCURACY +      | ?ATTRIBUTE_CRITICAL_HIT_CHANCE +      | ?ATTRIBUTE_DAMAGE_MODIFIER +      | ?ATTRIBUTE_DODGE_CHANCE +      | ?ATTRIBUTE_DOUBLE_HIT_CHANCE +      | ?ATTRIBUTE_HEALTH +      | ?ATTRIBUTE_MOVEMENT_POINTS +      | ?ATTRIBUTE_PARRY_CHANCE +   ). + +-type meta_enum() :: +   ( +      enum() +      | ?ATTRIBUTE_ATTACK_SCORE +      | ?ATTRIBUTE_DEFENSE_SCORE +   ). + +-export_type([type/0,enum/0,meta_enum/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -31,11 +51,11 @@     [        get_movement_points/1,        get_health/1, -      get_dodges/1, -      get_parries/1, +      get_dodge_chance/1, +      get_parry_chance/1,        get_accuracy/1, -      get_double_hits/1, -      get_critical_hits/1, +      get_double_hit_chance/1, +      get_critical_hit_chance/1,        get_damage_modifier/1,        get_damage_multiplier/1, @@ -64,25 +84,25 @@ mod_movement_points (Mod, Atts) ->  mod_health (Mod, Atts) ->     Atts#attributes{ health = (Atts#attributes.health + Mod) }. --spec mod_dodges (integer(), type()) -> type(). -mod_dodges (Mod, Atts) -> -   Atts#attributes{ dodges = (Atts#attributes.dodges + Mod) }. +-spec mod_dodge_chance (integer(), type()) -> type(). +mod_dodge_chance (Mod, Atts) -> +   Atts#attributes{ dodge_chance = (Atts#attributes.dodge_chance + Mod) }. --spec mod_parries (integer(), type()) -> type(). -mod_parries (Mod, Atts) -> -   Atts#attributes{ parries = (Atts#attributes.parries + Mod) }. +-spec mod_parry_chance (integer(), type()) -> type(). +mod_parry_chance (Mod, Atts) -> +   Atts#attributes{ parry_chance = (Atts#attributes.parry_chance + Mod) }.  -spec mod_accuracy (integer(), type()) -> type().  mod_accuracy (Mod, Atts) ->     Atts#attributes{ accuracy = (Atts#attributes.accuracy + Mod) }. --spec mod_double_hits (integer(), type()) -> type(). -mod_double_hits (Mod, Atts) -> -   Atts#attributes{ double_hits = (Atts#attributes.double_hits + Mod) }. +-spec mod_double_hit_chance (integer(), type()) -> type(). +mod_double_hit_chance (Mod, Atts) -> +   Atts#attributes{ double_hit_chance = (Atts#attributes.double_hit_chance + Mod) }. --spec mod_critical_hits (integer(), type()) -> type(). -mod_critical_hits (Mod, Atts) -> -   Atts#attributes{ critical_hits = (Atts#attributes.critical_hits + Mod) }. +-spec mod_critical_hit_chance (integer(), type()) -> type(). +mod_critical_hit_chance (Mod, Atts) -> +   Atts#attributes{ critical_hit_chance = (Atts#attributes.critical_hit_chance + Mod) }.  -spec mod_damage_modifier (integer(), type()) -> type().  mod_damage_modifier (Mod, Atts) -> @@ -101,20 +121,20 @@ get_movement_points (Atts) -> max(0, Atts#attributes.movement_points).  -spec get_health (type()) -> non_neg_integer().  get_health (Atts) -> max(1, Atts#attributes.health). --spec get_dodges (type()) -> non_neg_integer(). -get_dodges (Atts) -> max(0, Atts#attributes.dodges). +-spec get_dodge_chance (type()) -> non_neg_integer(). +get_dodge_chance (Atts) -> max(0, Atts#attributes.dodge_chance). --spec get_parries (type()) -> non_neg_integer(). -get_parries (Atts) -> max(0, Atts#attributes.parries). +-spec get_parry_chance (type()) -> non_neg_integer(). +get_parry_chance (Atts) -> max(0, Atts#attributes.parry_chance).  -spec get_accuracy (type()) -> non_neg_integer().  get_accuracy (Atts) -> max(0, Atts#attributes.accuracy). --spec get_double_hits (type()) -> non_neg_integer(). -get_double_hits (Atts) -> max(0, Atts#attributes.double_hits). +-spec get_double_hit_chance (type()) -> non_neg_integer(). +get_double_hit_chance (Atts) -> max(0, Atts#attributes.double_hit_chance). --spec get_critical_hits (type()) -> non_neg_integer(). -get_critical_hits (Atts) -> max(0, Atts#attributes.critical_hits). +-spec get_critical_hit_chance (type()) -> non_neg_integer(). +get_critical_hit_chance (Atts) -> max(0, Atts#attributes.critical_hit_chance).  -spec get_damage_modifier (type()) -> non_neg_integer().  get_damage_modifier (Atts) -> max(0, Atts#attributes.damage_modifier). @@ -128,20 +148,24 @@ default () ->     {        movement_points = 0,        health = 1, -      dodges = 0, -      parries = 0, +      dodge_chance = 0, +      parry_chance = 0,        accuracy = 0, -      double_hits = 0, -      critical_hits = 0, +      double_hit_chance = 0, +      critical_hit_chance = 0,        damage_modifier = 100     }. --spec apply_mod (atom(), integer(), type()) -> type(). -apply_mod(mheal, Value, Atts) -> mod_health(Value, Atts); -apply_mod(mpts, Value, Atts) -> mod_movement_points(Value, Atts); -apply_mod(dodg, Value, Atts) -> mod_dodges(Value, Atts); -apply_mod(pary, Value, Atts) -> mod_parries(Value, Atts); -apply_mod(accu, Value, Atts) -> mod_accuracy(Value, Atts); -apply_mod(dhit, Value, Atts) -> mod_double_hits(Value, Atts); -apply_mod(crit, Value, Atts) -> mod_critical_hits(Value, Atts); -apply_mod(dmgm, Value, Atts) -> mod_damage_modifier(Value, Atts). +-spec apply_mod (enum(), integer(), type()) -> type(). +apply_mod(?ATTRIBUTE_HEALTH, Mod, Atts) -> mod_health(Mod, Atts); +apply_mod(?ATTRIBUTE_DODGE_CHANCE, Mod, Atts) -> mod_dodge_chance(Mod, Atts); +apply_mod(?ATTRIBUTE_PARRY_CHANCE, Mod, Atts) -> mod_parry_chance(Mod, Atts); +apply_mod(?ATTRIBUTE_ACCURACY, Mod, Atts) -> mod_accuracy(Mod, Atts); +apply_mod(?ATTRIBUTE_MOVEMENT_POINTS, Mod, Atts) -> +   mod_movement_points(Mod, Atts); +apply_mod(?ATTRIBUTE_DOUBLE_HIT_CHANCE, Mod, Atts) -> +   mod_double_hit_chance(Mod, Atts); +apply_mod(?ATTRIBUTE_CRITICAL_HIT_CHANCE, Mod, Atts) -> +   mod_critical_hit_chance(Mod, Atts); +apply_mod(?ATTRIBUTE_DAMAGE_MODIFIER, Mod, Atts) -> +   mod_damage_modifier(Mod, Atts). diff --git a/src/shared/struct/shr_damage_type.erl b/src/shared/struct/shr_damage_type.erl index 9bcd79f..d739514 100644 --- a/src/shared/struct/shr_damage_type.erl +++ b/src/shared/struct/shr_damage_type.erl @@ -1,6 +1,6 @@  -module(shr_damage_type). --include("damage_types.hrl"). +-include("tacticians/damage_types.hrl").  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl index 7602e1f..e4993c8 100644 --- a/src/shared/struct/shr_omnimods.erl +++ b/src/shared/struct/shr_omnimods.erl @@ -3,22 +3,36 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type entry() :: {atom(), integer()}. --type mods() :: dict:dict(atom(), integer()). +-type attribute_entry() :: {shr_attributes:enum(), integer()}. +-type attribute_mods() :: dict:dict(shr_attributes:enum(), integer()). + +-type damage_type_entry() :: {shr_damage_type:type(), integer()}. +-type damage_type_mods() :: dict:dict(shr_damage_type:type(), integer()). + +-type entry() :: (attribute_entry() | damage_type_entry()). +-type mods() :: (attribute_mods() | damage_type_mods()).  -record  (     omnimods,     { -      attmods :: mods(), -      atkmods :: mods(), -      defmods :: mods() +      attmods :: attribute_mods(), +      atkmods :: damage_type_mods(), +      defmods :: damage_type_mods()     }  ).  -opaque type() :: #omnimods{}. --export_type([type/0, entry/0]). +-export_type +( +   [ +      type/0, +      attribute_entry/0, +      damage_type_entry/0, +      entry/0 +   ] +).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -27,7 +41,7 @@  -export  (     [ -      default/0, +      new/0,        new/3     ]  ). @@ -37,7 +51,10 @@  (     [        merge/2, -      apply_coefficient/2 +      apply_coefficient/2, +      set_attribute_modifiers/2, +      set_attack_modifiers/2, +      set_defense_modifiers/2     ]  ). @@ -46,7 +63,13 @@  (     [        apply_to_attributes/2, -      get_attack_damage/3 +      get_attack_damage/3, +      get_attribute_modifier/2, +      get_attack_modifier/2, +      get_defense_modifier/2, +      get_attribute_modifiers/1, +      get_attack_modifiers/1, +      get_defense_modifiers/1     ]  ). @@ -61,11 +84,15 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec apply_coefficient_to_mods (float(), mods()) -> mods(). +-spec apply_coefficient_to_mods +   (float(), attribute_mods()) -> attribute_mods(); +   (float(), damage_type_mods()) -> damage_type_mods().  apply_coefficient_to_mods (Coef, Mods) ->     dict:map(fun (_Name, Val) -> shr_math_util:ceil(Coef * Val) end, Mods). --spec merge_mods (mods(), mods()) -> mods(). +-spec merge_mods +   (attribute_mods(), attribute_mods()) -> attribute_mods(); +   (damage_type_mods(), damage_type_mods()) -> damage_type_mods().  merge_mods (ModsA, ModsB) ->     dict:merge(fun (_Name, ValA, ValB) -> (ValA + ValB) end, ModsA, ModsB). @@ -88,7 +115,13 @@ encode_mods (Mods) ->  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%% Creation --spec new (list(entry()), list(entry()), list(entry())) -> type(). +-spec new +   ( +      list(attribute_entry()), +      list(damage_type_entry()), +      list(damage_type_entry()) +   ) +   -> type().  new (AttributeMods, AttackMods, DefenseMods) ->     #omnimods     { @@ -97,8 +130,8 @@ new (AttributeMods, AttackMods, DefenseMods) ->        defmods = dict:from_list(DefenseMods)     }. --spec default () -> type(). -default () -> new([], [], []). +-spec new () -> type(). +new () -> new([], [], []).  %%% Modification  -spec merge (type(), type()) -> type(). @@ -119,6 +152,28 @@ apply_coefficient (Coef, Omnimods) ->        defmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.defmods)     }. +-spec set_attribute_modifiers (list(attribute_entry()), type()) -> type(). +set_attribute_modifiers (NewAttributeModifiers, Omnimods) -> +   Omnimods#omnimods +   { +      attmods = dict:from_list(NewAttributeModifiers) +   }. + +-spec set_defense_modifiers (list(damage_type_entry()), type()) -> type(). +set_defense_modifiers (NewDefenseModifiers, Omnimods) -> +   Omnimods#omnimods +   { +      defmods = dict:from_list(NewDefenseModifiers) +   }. + +-spec set_attack_modifiers (list(damage_type_entry()), type()) -> type(). +set_attack_modifiers (NewAttackModifiers, Omnimods) -> +   Omnimods#omnimods +   { +      atkmods = dict:from_list(NewAttackModifiers) +   }. + +%%%% Access  -spec apply_to_attributes     (        type(), @@ -133,6 +188,7 @@ apply_to_attributes (Omnimods, Attributes) ->        Omnimods#omnimods.attmods     ). +% FIXME: 'base' is no longer used.  -spec get_attack_damage (float(), type(), type()) -> non_neg_integer().  get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) ->     AttackerOmnimodsAttmods = AttackerOmnimods#omnimods.atkmods, @@ -191,6 +247,37 @@ get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) ->     Result. +-spec get_attribute_modifier (shr_attributes:enum(), type()) -> integer(). +get_attribute_modifier (Attribute, Omnimods) -> +   case dict:find(Attribute, Omnimods#omnimods.attmods) of +      {ok, Value} -> Value; +      error -> 0 +   end. + +-spec get_attack_modifier (shr_damage_type:type(), type()) -> integer(). +get_attack_modifier (DamageType, Omnimods) -> +   case dict:find(DamageType, Omnimods#omnimods.atkmods) of +      {ok, Value} -> Value; +      error -> 0 +   end. + +-spec get_defense_modifier (shr_damage_type:type(), type()) -> integer(). +get_defense_modifier (DamageType, Omnimods) -> +   case dict:find(DamageType, Omnimods#omnimods.defmods) of +      {ok, Value} -> Value; +      error -> 0 +   end. + +-spec get_attribute_modifiers (type()) -> list(attribute_entry()). +get_attribute_modifiers (Omnimods) -> lists:to_list(Omnimods#omnimods.attmods). + +-spec get_attack_modifiers (type()) -> list(damage_type_entry()). +get_attack_modifiers (Omnimods) -> lists:to_list(Omnimods#omnimods.atkmods). + +-spec get_defense_modifiers (type()) -> list(damage_type_entry()). +get_defense_modifiers (Omnimods) -> lists:to_list(Omnimods#omnimods.defmods). + +  %%% Export  -spec encode (type()) -> {list(any())}.  encode (Omnimods) -> | 


