summaryrefslogtreecommitdiff
blob: 9847f1cff85f43751b49b5973f0b996b186904a4 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
module Battle.Struct.Statistics exposing
   (
      Type,
      Category(..),
      get_movement_points,
      get_max_health,
      get_dodges,
      get_parries,
      get_accuracy,
      get_double_hits,
      get_critical_hits,
      get_damage_modifier,
      decode_category,
      encode_category,
      mod,
      new_raw,
      is_percent
   )

-- Elm -------------------------------------------------------------------------
import List

-- Battle ----------------------------------------------------------------------
import Battle.Struct.Attributes

--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type Category =
   MovementPoints
   | MaxHealth
   | Dodges
   | Parries
   | Accuracy
   | DoubleHits
   | CriticalHits

type alias Type =
   {
      movement_points : Int,
      max_health : Int,
      dodges : Int,
      parries : Int,
      accuracy : Int,
      double_hits : Int,
      critical_hits : Int,
      damage_modifier : Float
   }

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
average : (List Int) -> Float
average l = ((toFloat (List.sum l)) / (toFloat (List.length l)))

float_to_int : Float -> Int
float_to_int f =
   (ceiling f)

gentle_squared_growth : Int -> Int
gentle_squared_growth v = (float_to_int (((toFloat v)^1.8)/20.0))

gentle_squared_growth_f : Float -> Int
gentle_squared_growth_f v = (float_to_int ((v^1.8)/20.0))

sudden_squared_growth : Int -> Int
sudden_squared_growth v = (float_to_int (((toFloat v)^2.5)/1000.0))

sudden_squared_growth_f : Float -> Int
sudden_squared_growth_f v = (float_to_int ((v^2.5)/1000.0))

sudden_exp_growth : Int -> Int
sudden_exp_growth v = (float_to_int (4.0^((toFloat v)/25.0)))

sudden_exp_growth_f : Float -> Int
sudden_exp_growth_f f = (float_to_int (4.0^(f/25.0)))

damage_base_mod : Float -> Float
damage_base_mod str = ((((str + 10) * 4)^1.5)/3000.0)

make_movement_points_safe : Int -> Int
make_movement_points_safe val = (clamp 0 200 val)

make_max_health_safe : Int -> Int
make_max_health_safe val = (max 1 val)

make_dodges_safe : Int -> Int
make_dodges_safe val = (clamp 0 100 val)

make_parries_safe : Int -> Int
make_parries_safe val = (clamp 0 75 val)

make_accuracy_safe : Int -> Int
make_accuracy_safe val = (clamp 0 100 val)

make_double_hits_safe : Int -> Int
make_double_hits_safe val = (clamp 0 100 val)

make_critical_hits_safe : Int -> Int
make_critical_hits_safe val = (clamp 0 100 val)

mod_movement_points : Int -> Type -> Type
mod_movement_points v t =
   {t |
      movement_points = (make_movement_points_safe (t.movement_points + v))
   }

mod_max_health : Int -> Type -> Type
mod_max_health v t =
   {t |
      max_health = (make_max_health_safe (t.max_health + v))
   }

mod_dodges : Int -> Type -> Type
mod_dodges v t = {t | dodges = (make_dodges_safe (t.dodges + v))}

mod_parries : Int -> Type -> Type
mod_parries v t = {t | parries = (make_parries_safe (t.parries + v))}

mod_accuracy : Int -> Type -> Type
mod_accuracy v t = {t | accuracy = (make_accuracy_safe (t.accuracy + v))}

mod_double_hits : Int -> Type -> Type
mod_double_hits v t =
   {t |
      double_hits = (make_double_hits_safe (t.double_hits + v))
   }

mod_critical_hits : Int -> Type -> Type
mod_critical_hits v t =
   {t |
      critical_hits = (make_critical_hits_safe (t.critical_hits + v))
   }

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
get_movement_points : Type -> Int
get_movement_points t = t.movement_points

get_max_health : Type -> Int
get_max_health t = t.max_health

get_dodges : Type -> Int
get_dodges t = t.dodges

get_parries : Type -> Int
get_parries t = t.parries

get_accuracy : Type -> Int
get_accuracy t = t.accuracy

get_double_hits : Type -> Int
get_double_hits t = t.double_hits

get_critical_hits : Type -> Int
get_critical_hits t = t.critical_hits

get_damage_modifier : Type -> Float
get_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)

new_raw : (Battle.Struct.Attributes.Type -> Type)
new_raw att =
   let
      constitution = (Battle.Struct.Attributes.get_effective_constitution att)
      dexterity = (Battle.Struct.Attributes.get_effective_dexterity att)
      intelligence = (Battle.Struct.Attributes.get_effective_intelligence att)
      mind = (Battle.Struct.Attributes.get_effective_mind att)
      speed = (Battle.Struct.Attributes.get_effective_speed att)
      strength = (Battle.Struct.Attributes.get_effective_strength att)
   in
      {
         movement_points =
            (gentle_squared_growth_f
               (average [mind, constitution, constitution, speed, speed, speed])
            ),
         max_health =
            (gentle_squared_growth_f
               (average [constitution, constitution, constitution, mind])
            ),
         dodges = (sudden_exp_growth_f (average [dexterity, mind, speed])),
         parries =
            (sudden_exp_growth_f
               (average [dexterity, intelligence, speed, strength])
            ),
         accuracy = (sudden_squared_growth dexterity),
         double_hits = (sudden_squared_growth_f (average [mind, speed])),
         critical_hits = (sudden_squared_growth intelligence),
         damage_modifier = (damage_base_mod (toFloat strength))
      }

decode_category : String -> Category
decode_category str =
   case str of
      "mheal" -> MaxHealth
      "mpts" -> MovementPoints
      "dodg" -> Dodges
      "pary" -> Parries
      "accu" -> Accuracy
      "dhit" -> DoubleHits
      _  -> 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"

is_percent : Category -> Bool
is_percent cat = ((cat /= MaxHealth) && (cat /= MovementPoints))