summaryrefslogtreecommitdiff
blob: ccd32d79c857fdaa61b2c335df2481c844d82742 (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 Struct.Armor exposing
   (
      Type,
      Ref,
      Category(..),
      new,
      get_id,
      get_name,
      get_category,
      get_resistance_to,
      get_image_id,
      decoder,
      none,
      apply_to_attributes
   )

-- Elm -------------------------------------------------------------------------
import Json.Decode
import Json.Decode.Pipeline

-- Battlemap -------------------------------------------------------------------
import Struct.Attributes
import Struct.Weapon

--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type alias PartiallyDecoded =
   {
      id : Int,
      nam : String,
      ct : String,
      cf : Float
   }

type alias Type =
   {
      id : Int,
      name : String,
      category : Category,
      coef : Float
   }

type alias Ref = Int

type Category =
   Kinetic
   | Leather
   | Chain
   | Plate

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
finish_decoding : PartiallyDecoded -> Type
finish_decoding add_armor =
   {
      id = add_armor.id,
      name = add_armor.nam,
      category =
         (
            case add_armor.ct of
               "k" -> Kinetic
               "c" -> Chain
               "p" -> Plate
               _   -> Leather
         ),
      coef = add_armor.cf
   }

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
new : Int -> String -> Category -> Float -> Type
new id name category coef =
   {
      id = id,
      name = name,
      category = category,
      coef = coef
   }

get_id : Type -> Ref
get_id ar = ar.id

get_name : Type -> String
get_name ar = ar.name

get_category : Type -> String
get_category ar = ar.name

get_image_id : Type -> String
get_image_id ar = (toString ar.id)

get_resistance_to : Struct.Weapon.DamageType -> Type -> Int
get_resistance_to dmg_type ar =
   (ceiling
      (
         ar.coef
         *
         (
            case (dmg_type, ar.category) of
               (Struct.Weapon.Slash, Kinetic) -> 0.0
               (Struct.Weapon.Slash, Leather) -> 20.0
               (Struct.Weapon.Slash, Chain) -> 30.0
               (Struct.Weapon.Slash, Plate) -> 30.0
               (Struct.Weapon.Blunt, Kinetic) -> 30.0
               (Struct.Weapon.Blunt, Leather) -> 20.0
               (Struct.Weapon.Blunt, Chain) -> 20.0
               (Struct.Weapon.Blunt, Plate) -> 20.0
               (Struct.Weapon.Pierce, Kinetic) -> 20.0
               (Struct.Weapon.Pierce, Leather) -> 20.0
               (Struct.Weapon.Pierce, Chain) -> 20.0
               (Struct.Weapon.Pierce, Plate) -> 30.0
         )
      )
   )

apply_to_attributes : Type -> Struct.Attributes.Type -> Struct.Attributes.Type
apply_to_attributes ar atts =
   let
      impact = (ceiling (-20.0 * ar.coef))
      half_impact = (ceiling (-10.0 * ar.coef))
   in
      case ar.category of
         Kinetic -> (Struct.Attributes.mod_mind impact atts)
         Leather ->
            (Struct.Attributes.mod_constitution
               half_impact
               (Struct.Attributes.mod_dexterity
                  half_impact
                  atts
               )
            )

         Chain ->
            (Struct.Attributes.mod_constitution
               half_impact
               (Struct.Attributes.mod_dexterity
                  half_impact
                  (Struct.Attributes.mod_speed impact atts)
               )
            )

         Plate ->
            (Struct.Attributes.mod_constitution
               half_impact
               (Struct.Attributes.mod_dexterity
                  half_impact
                  (Struct.Attributes.mod_speed
                     impact
                     (Struct.Attributes.mod_strength impact atts)
                  )
               )
            )

decoder : (Json.Decode.Decoder Type)
decoder =
   (Json.Decode.map
      (finish_decoding)
      (Json.Decode.Pipeline.decode
         PartiallyDecoded
         |> (Json.Decode.Pipeline.required "id" Json.Decode.int)
         |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
         |> (Json.Decode.Pipeline.required "ct" Json.Decode.string)
         |> (Json.Decode.Pipeline.required "cf" Json.Decode.float)
      )
   )

none : Type
none =
   (new
      0
      "None"
      Leather
      0.0
   )