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
|
-module(shr_character).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
shr_char_ref,
{
name :: binary(),
equipment :: shr_equipment:unresolved(),
is_using_secondary :: boolean()
}
).
-record
(
shr_char,
{
name :: binary(),
equipment :: shr_equipment:type(),
is_using_secondary :: boolean(),
statistics :: shr_statistics:type(),
attributes :: shr_attributes:type(),
omnimods :: shr_omnimods:type(),
extra_omnimods :: shr_omnimods:type()
}
).
-opaque type() :: #shr_char{}.
-opaque unresolved() :: #shr_char_ref{}.
-type either() :: (type() | unresolved()).
-export_type([type/0, unresolved/0, either/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-export
(
[
get_name/1,
get_equipment/1,
get_attributes/1,
get_statistics/1,
get_active_weapon/1,
get_inactive_weapon/1,
get_omnimods/1,
set_name/2,
set_equipment/2,
dirty_set_equipment/2,
set_extra_omnimods/2,
dirty_set_extra_omnimods/2,
switch_weapons/1,
dirty_switch_weapons/1
]
).
-export
(
[
resolve/1,
to_unresolved/1
]
).
-export
(
[
validate/2
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec refresh_omnimods (type()) -> type().
refresh_omnimods (Char) -> Char.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-spec get_name (either()) -> binary().
get_name (#shr_char{ name = R }) -> R;
get_name (#shr_char_ref{ name = R }) -> R.
-spec set_name
(binary(), type()) -> type();
(binary(), unresolved()) -> unresolved().
set_name (Name, Char) when is_record(Char, shr_char) ->
Char#shr_char { name = Name };
set_name (Name, Char) when is_record(Char, shr_char_ref) ->
Char#shr_char_ref{ name = Name }.
-spec get_equipment
(type()) -> shr_equipment:type();
(unresolved()) -> shr_equipment:unresolved().
get_equipment (#shr_char{ equipment = R }) -> R;
get_equipment (#shr_char_ref{ equipment = R }) -> R.
-spec switch_weapons
(type()) -> type();
(unresolved()) -> unresolved().
switch_weapons (Char) when is_record(Char, shr_char) ->
refresh_omnimods
(
Char#shr_char
{
is_using_secondary = (not Char#shr_char.is_using_secondary)
}
);
switch_weapons (Char) when is_record(Char, shr_char_ref) ->
Char#shr_char_ref
{
is_using_secondary = (not Char#shr_char_ref.is_using_secondary)
}.
-spec dirty_switch_weapons
(type()) -> type();
(unresolved()) -> unresolved().
dirty_switch_weapons (Char) when is_record(Char, shr_char) ->
Char#shr_char
{
is_using_secondary = (not Char#shr_char.is_using_secondary)
};
dirty_switch_weapons (Char) when is_record(Char, shr_char_ref) ->
Char#shr_char_ref
{
is_using_secondary = (not Char#shr_char_ref.is_using_secondary)
}.
-spec get_active_weapon (either()) -> shr_weapon:type().
get_active_weapon (#shr_char{ is_using_secondary = B, equipment = E }) ->
case B of
true -> shr_equipment:get_secondary_weapon(E);
false -> shr_equipment:get_primary_weapon(E)
end;
get_active_weapon (#shr_char_ref{ is_using_secondary = B, equipment = E }) ->
case B of
true -> shr_equipment:get_secondary_weapon(E);
false -> shr_equipment:get_primary_weapon(E)
end.
-spec get_inactive_weapon (either()) -> shr_weapon:type().
get_inactive_weapon (#shr_char{ is_using_secondary = B, equipment = E }) ->
case B of
false -> shr_equipment:get_secondary_weapon(E);
true -> shr_equipment:get_primary_weapon(E)
end;
get_inactive_weapon (#shr_char_ref{ is_using_secondary = B, equipment = E }) ->
case B of
false -> shr_equipment:get_secondary_weapon(E);
true -> shr_equipment:get_primary_weapon(E)
end.
-spec get_attributes (type()) -> shr_attributes:type().
get_attributes (Char) -> Char#shr_char.attributes.
-spec get_statistics (type()) -> shr_statistics:type().
get_statistics (Char) -> Char#shr_char.statistics.
-spec get_omnimods (type()) -> shr_omnimods:type().
get_omnimods (Char) -> Char#shr_char.omnimods.
-spec set_extra_omnimods (shr_omnimods:type(), type()) -> type().
set_extra_omnimods (O, Char) ->
refresh_omnimods(Char#shr_char{ extra_omnimods = O }).
-spec dirty_set_extra_omnimods (shr_omnimods:type(), type()) -> type().
dirty_set_extra_omnimods (O, Char) -> Char#shr_char{ extra_omnimods = O }.
|