aboutsummaryrefslogtreecommitdiff
blob: 792886258b32b85fc4c8212133bdc1deb832757e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
-module(shr_attributes).

-include("tacticians/attributes.hrl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
   attributes,
   {
      movement_points :: non_neg_integer(),
      health :: non_neg_integer(),
      dodge_chance :: integer(),
      parry_chance :: integer(),
      accuracy :: integer(),
      double_hit_chance :: integer(),
      critical_hit_chance :: integer(),
      damage_modifier :: integer()
   }
).

-opaque type() :: #attributes{}.
-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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-export
(
   [
      get_movement_points/1,
      get_health/1,
      get_dodge_chance/1,
      get_parry_chance/1,
      get_accuracy/1,
      get_double_hit_chance/1,
      get_critical_hit_chance/1,
      get_damage_modifier/1,
      get_damage_multiplier/1,

      apply_mod/3
   ]
).

-export
(
   [
      default/0
   ]
).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec mod_movement_points (integer(), type()) -> type().
mod_movement_points (Mod, Atts) ->
   Atts#attributes
   {
      movement_points = (Atts#attributes.movement_points + Mod)
   }.

-spec mod_health (integer(), type()) -> type().
mod_health (Mod, Atts) ->
   Atts#attributes{ health = (Atts#attributes.health + Mod) }.

-spec mod_dodge_chance (integer(), type()) -> type().
mod_dodge_chance (Mod, Atts) ->
   Atts#attributes{ dodge_chance = (Atts#attributes.dodge_chance + 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_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_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) ->
   Atts#attributes
   {
      damage_modifier = (Atts#attributes.damage_modifier + Mod)
   }.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-spec get_movement_points (type()) -> non_neg_integer().
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_dodge_chance (type()) -> non_neg_integer().
get_dodge_chance (Atts) -> max(0, Atts#attributes.dodge_chance).

-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_hit_chance (type()) -> non_neg_integer().
get_double_hit_chance (Atts) -> max(0, Atts#attributes.double_hit_chance).

-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).

-spec get_damage_multiplier (type()) -> float().
get_damage_multiplier (Atts) -> (get_damage_modifier(Atts) / 100).

-spec default () -> type().
default () ->
   #attributes
   {
      movement_points = 0,
      health = 1,
      dodge_chance = 0,
      parry_chance = 0,
      accuracy = 0,
      double_hit_chance = 0,
      critical_hit_chance = 0,
      damage_modifier = 100
   }.

-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).