summaryrefslogtreecommitdiff
blob: 02938e2d2e4542689fefaf3ba15fb49707c62a1a (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
-module(shr_armor).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-opaque id() :: non_neg_integer().

-type category() :: 'kinetic' | 'leather' | 'chain' | 'plate'.

-record
(
   armor,
   {
      id :: id(),
      name :: binary(),
      category :: category(),
      coef :: float()
   }
).

-opaque type() :: #armor{}.

-export_type([type/0, id/0]).
-export_type ([category/0]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-export
(
   [
      get_id/1,
      get_name/1,
      get_coefficient/1,
      get_category/1
   ]
).

-export
(
   [
      random_id/0,
      from_id/1,
      apply_to_attributes/2,
      get_resistance_to/2
   ]
).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-spec get_id (type()) -> id().
get_id (Ar) -> Ar#armor.id.

-spec get_name (type()) -> binary().
get_name (Ar) -> Ar#armor.name.

-spec get_coefficient (type()) -> float().
get_coefficient (Ar) -> Ar#armor.coef.

-spec get_category (type()) -> category().
get_category (Ar) -> Ar#armor.category.

-spec from_id (id()) -> type().
m4_include(__MAKEFILE_DATA_DIR/armor/global.m4.conf)m4_dnl
__ARMOR_USE_ERLANG_STYLE
m4_include(__MAKEFILE_DATA_DIR/armor/basic.m4d)m4_dnl
from_id(_) ->
   from_id(0).

-spec random_id () -> id().
random_id () -> shr_roll:between(0, 4).

-spec apply_to_attributes
   (
      type(),
      shr_attributes:type()
   )
   -> shr_attributes:type().
apply_to_attributes (Ar, Att) ->
   Constitution = shr_attributes:get_constitution(Att),
   Dexterity = shr_attributes:get_dexterity(Att),
   Speed = shr_attributes:get_speed(Att),
   Strength = shr_attributes:get_strength(Att),
   Mind = shr_attributes:get_mind(Att),
   Impact = shr_math_util:ceil(20.0 * Ar#armor.coef),
   HalfImpact = shr_math_util:ceil(10.0 * Ar#armor.coef),
   Category = Ar#armor.category,

   case Category of
      kinetic -> shr_attributes:set_unsafe_mind((Mind - Impact), Att);
      leather ->
         shr_attributes:set_unsafe_constitution
         (
            (Constitution - HalfImpact),
            shr_attributes:set_unsafe_dexterity((Dexterity - HalfImpact), Att)
         );

      chain ->
         shr_attributes:set_unsafe_constitution
         (
            (Constitution - HalfImpact),
            shr_attributes:set_unsafe_dexterity
            (
               (Dexterity - HalfImpact),
               shr_attributes:set_unsafe_speed((Speed - Impact), Att)
            )
         );

      plate ->
         shr_attributes:set_unsafe_constitution
         (
            (Constitution - HalfImpact),
            shr_attributes:set_unsafe_dexterity
            (
               (Dexterity - HalfImpact),
               shr_attributes:set_unsafe_speed
               (
                  (Speed - Impact),
                  shr_attributes:set_unsafe_strength((Strength - Impact), Att)
               )
            )
         )
   end.

-spec get_resistance_to (shr_weapon:damage_type(), type()) -> non_neg_integer().
get_resistance_to (DamageType, Armor) ->
   ArmorCategory = Armor#armor.category,
   BaseResistance =
      case {DamageType, ArmorCategory} of
         {slash, kinetic} -> 0.0;
         {slash, leather} -> 20.0;
         {slash, chain} -> 30.0;
         {slash, plate} -> 30.0;
         {blunt, kinetic} -> 20.0;
         {blunt, leather} -> 20.0;
         {blunt, chain} -> 20.0;
         {blunt, plate} -> 20.0;
         {pierce, kinetic} -> 20.0;
         {pierce, leather} -> 20.0;
         {pierce, chain} -> 20.0;
         {pierce, plate} -> 30.0
      end,

   ArmorCoefficient = Armor#armor.coef,
   ActualResistance = (ArmorCoefficient * BaseResistance),

   shr_math_util:ceil(ActualResistance).