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

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

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

type alias Ref = Int

type Category =
   Kinetic
   | Leather
   | Chain
   | Plate

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- 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) -> 0.5
               (Struct.Weapon.Slash, Chain) -> 1.0
               (Struct.Weapon.Slash, Plate) -> 1.0
               (Struct.Weapon.Blunt, Kinetic) -> 1.0
               (Struct.Weapon.Blunt, Leather) -> 0.5
               (Struct.Weapon.Blunt, Chain) -> 0.5
               (Struct.Weapon.Blunt, Plate) -> 0.5
               (Struct.Weapon.Pierce, Kinetic) -> 0.5
               (Struct.Weapon.Pierce, Leather) -> 0.5
               (Struct.Weapon.Pierce, Chain) -> 0.5
               (Struct.Weapon.Pierce, Plate) -> 1.0
         )
      )
   )

apply_to_attributes : Type -> Struct.Attributes.Type -> Struct.Attributes.Type
apply_to_attributes ar atts =
   case ar.category of
      Kinetic -> atts
      Leather -> atts
      Chain ->
         (Struct.Attributes.mod_dexterity
            -10
            (Struct.Attributes.mod_speed -10 atts)
         )

      Plate ->
         (Struct.Attributes.mod_dexterity
            -10
            (Struct.Attributes.mod_speed
               -10
               (Struct.Attributes.mod_strength
                  -10
                  atts
               )
            )
         )