summaryrefslogtreecommitdiff
blob: ee12dbd686f901a8980438f2001f00d1bf220417 (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
module Battle.Struct.Attributes exposing
   (
      Type,
      Category(..),
      get_constitution,
      get_dexterity,
      get_intelligence,
      get_mind,
      get_speed,
      get_strength,
      mod_constitution,
      mod_dexterity,
      mod_intelligence,
      mod_mind,
      mod_speed,
      mod_strength,
      mod,
      get,
      new,
      decode_category,
      default
   )

--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type Category =
   Constitution
   | Dexterity
   | Intelligence
   | Mind
   | Speed
   | Strength

type alias Type =
   {
      constitution : Int,
      dexterity : Int,
      intelligence : Int,
      mind : Int,
      speed : Int,
      strength : Int
   }

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
get_within_range : Int -> Int -> Int -> Int
get_within_range vmin vmax v = (min vmax (max vmin v))

get_within_att_range : Int -> Int
get_within_att_range v = (get_within_range 0 100 v)

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
get_constitution : Type -> Int
get_constitution t = t.constitution

get_dexterity : Type -> Int
get_dexterity t = t.dexterity

get_intelligence : Type -> Int
get_intelligence t = t.intelligence

get_mind : Type -> Int
get_mind t = t.mind

get_speed : Type -> Int
get_speed t = t.speed

get_strength : Type -> Int
get_strength t = t.strength

mod_constitution : Int -> Type -> Type
mod_constitution i t =
   {t |
      constitution = (get_within_att_range (i + t.constitution))
   }

mod_dexterity : Int -> Type -> Type
mod_dexterity i t =
   {t |
      dexterity = (get_within_att_range (i + t.dexterity))
   }

mod_intelligence : Int -> Type -> Type
mod_intelligence i t =
   {t |
      intelligence = (get_within_att_range (i + t.intelligence))
   }

mod_mind : Int -> Type -> Type
mod_mind i t =
   {t |
      mind = (get_within_att_range (i + t.mind))
   }

mod_speed : Int -> Type -> Type
mod_speed i t =
   {t |
      speed = (get_within_att_range (i + t.speed))
   }

mod_strength : Int -> Type -> Type
mod_strength i t =
   {t |
      strength = (get_within_att_range (i + t.strength))
   }

mod : Category -> Int -> Type -> Type
mod cat i t =
   case cat of
      Constitution -> (mod_constitution i t)
      Dexterity -> (mod_dexterity i t)
      Intelligence -> (mod_intelligence i t)
      Mind -> (mod_mind i t)
      Speed -> (mod_speed i t)
      Strength -> (mod_strength i t)

get : Category -> Type -> Int
get cat t =
   case cat of
      Constitution -> (get_constitution t)
      Dexterity -> (get_dexterity t)
      Intelligence -> (get_intelligence t)
      Mind -> (get_mind t)
      Speed -> (get_speed t)
      Strength -> (get_strength t)

new : (
      Int -> -- constitution
      Int -> -- dexterity
      Int -> -- intelligence
      Int -> -- mind
      Int -> -- speed
      Int -> -- strength
      Type
   )
new con dex int min spe str =
   {
      constitution = con,
      dexterity = dex,
      intelligence = int,
      mind = min,
      speed = spe,
      strength = str
   }

default : Type
default =
   {
      constitution = 50,
      dexterity = 50,
      intelligence = 50,
      mind = 50,
      speed = 50,
      strength = 50
   }

decode_category : String -> Category
decode_category str =
   case str of
      "con" -> Constitution
      "dex" -> Dexterity
      "int" -> Intelligence
      "min" -> Mind
      "spe" -> Speed
      _ -> Strength