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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
module Battle.Struct.Attributes exposing
(
Type,
Category(..),
get_movement_points,
get_max_health,
get_dodges,
get_parries,
get_accuracy,
get_double_hits,
get_critical_hits,
get_damage_modifier,
get_damage_multiplier,
get_true_movement_points,
get_true_max_health,
get_true_dodges,
get_true_parries,
get_true_accuracy,
get_true_double_hits,
get_true_critical_hits,
get_true_damage_modifier,
decode_category,
encode_category,
mod,
default,
is_percent
)
-- Elm -------------------------------------------------------------------------
import List
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type Category =
MovementPoints
| MaxHealth
| Dodges
| Parries
| Accuracy
| DoubleHits
| CriticalHits
| DamageModifier
type alias Type =
{
movement_points : Int,
max_health : Int,
dodges : Int,
parries : Int,
accuracy : Int,
double_hits : Int,
critical_hits : Int,
damage_modifier : Int
}
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
mod_movement_points : Int -> Type -> Type
mod_movement_points v t =
{t |
movement_points = (t.movement_points + v)
}
mod_max_health : Int -> Type -> Type
mod_max_health v t =
{t |
max_health = (t.max_health + v)
}
mod_dodges : Int -> Type -> Type
mod_dodges v t = {t | dodges = (t.dodges + v)}
mod_parries : Int -> Type -> Type
mod_parries v t = {t | parries = (t.parries + v)}
mod_accuracy : Int -> Type -> Type
mod_accuracy v t = {t | accuracy = (t.accuracy + v)}
mod_double_hits : Int -> Type -> Type
mod_double_hits v t = {t | double_hits = (t.double_hits + v)}
mod_critical_hits : Int -> Type -> Type
mod_critical_hits v t = {t | critical_hits = (t.critical_hits + v)}
mod_damage_modifier : Int -> Type -> Type
mod_damage_modifier v t = {t | damage_modifier = (t.damage_modifier + v)}
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
get_movement_points : Type -> Int
get_movement_points t = (max 0 t.movement_points)
get_max_health : Type -> Int
get_max_health t = (max 1 t.max_health)
get_dodges : Type -> Int
get_dodges t = (max 0 t.dodges)
get_parries : Type -> Int
get_parries t = (max 0 t.parries)
get_accuracy : Type -> Int
get_accuracy t = (max 0 t.accuracy)
get_double_hits : Type -> Int
get_double_hits t = (max 0 t.double_hits)
get_critical_hits : Type -> Int
get_critical_hits t = (max 0 t.critical_hits)
get_damage_modifier : Type -> Int
get_damage_modifier t = (max 0 t.damage_modifier)
get_damage_multiplier : Type -> Float
get_damage_multiplier t = ((toFloat (max 0 t.damage_modifier)) / 100.0)
get_true_movement_points : Type -> Int
get_true_movement_points t = t.movement_points
get_true_max_health : Type -> Int
get_true_max_health t = t.max_health
get_true_dodges : Type -> Int
get_true_dodges t = t.dodges
get_true_parries : Type -> Int
get_true_parries t = t.parries
get_true_accuracy : Type -> Int
get_true_accuracy t = t.accuracy
get_true_double_hits : Type -> Int
get_true_double_hits t = t.double_hits
get_true_critical_hits : Type -> Int
get_true_critical_hits t = t.critical_hits
get_true_damage_modifier : Type -> Int
get_true_damage_modifier t = t.damage_modifier
mod : Category -> Int -> Type -> Type
mod cat v t =
case cat of
MaxHealth -> (mod_max_health v t)
MovementPoints -> (mod_movement_points v t)
Dodges -> (mod_dodges v t)
Parries -> (mod_parries v t)
Accuracy -> (mod_accuracy v t)
DoubleHits -> (mod_double_hits v t)
CriticalHits -> (mod_critical_hits v t)
DamageModifier -> (mod_damage_modifier v t)
-- TODO: Link this to the server using tacticians-data.
default : Type
default =
{
movement_points = 8,
max_health = 1,
dodges = 0,
parries = 0,
accuracy = 0,
double_hits = 0,
critical_hits = 0,
damage_modifier = 0
}
decode_category : String -> Category
decode_category str =
case str of
"mheal" -> MaxHealth
"mpts" -> MovementPoints
"dodg" -> Dodges
"pary" -> Parries
"accu" -> Accuracy
"dhit" -> DoubleHits
"dmgm" -> DamageModifier
_ -> CriticalHits
encode_category : Category -> String
encode_category cat =
case cat of
MaxHealth -> "mheal"
MovementPoints -> "mpts"
Dodges -> "dodg"
Parries -> "pary"
Accuracy -> "accu"
DoubleHits -> "dhit"
CriticalHits -> "crit"
DamageModifier -> "dmgm"
is_percent : Category -> Bool
is_percent cat = ((cat /= MaxHealth) && (cat /= MovementPoints))
|