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
|
-module(character).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-opaque id() :: non_neg_integer().
-record
(
character,
{
id :: id(),
owner_id :: player:id(),
name :: binary(),
icon :: binary(),
portrait :: binary(),
attributes :: attributes:struct(),
statistics :: statistics:struct(),
weapon_ids :: {weapon:id(), weapon:id()}
}
).
-opaque struct() :: #character{}.
-export_type([struct/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-export
(
[
get_id/1,
get_owner_id/1,
get_name/1,
get_icon/1,
get_portrait/1,
get_attributes/1,
get_statistics/1,
get_weapon_ids/1,
set_weapon_ids/2,
set_statistics/2
]
).
-export
(
[
random/2
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-spec get_id (struct()) -> id().
get_id (Char) -> Char#character.id.
-spec get_owner_id (struct()) -> player:id().
get_owner_id (Char) -> Char#character.owner_id.
-spec get_name (struct()) -> binary().
get_name (Char) -> Char#character.name.
-spec get_icon (struct()) -> binary().
get_icon (Char) -> Char#character.icon.
-spec get_portrait (struct()) -> binary().
get_portrait (Char) -> Char#character.portrait.
-spec get_attributes (struct()) -> attributes:struct().
get_attributes (Char) -> Char#character.attributes.
-spec get_weapon_ids (struct()) -> {weapon:id(), weapon:id()}.
get_weapon_ids (Char) -> Char#character.weapon_ids.
-spec get_statistics (struct()) -> statistics:struct().
get_statistics (Char) -> Char#character.statistics.
-spec set_weapon_ids
(
{weapon:id(), weapon:id()},
struct()
)
-> struct().
set_weapon_ids (WeaponIDs, Char) ->
Char#character
{
weapon_ids = WeaponIDs
}.
-spec set_statistics
(
statistics:struct(),
struct()
)
-> struct().
set_statistics (Stats, Char) ->
Char#character
{
statistics = Stats
}.
-spec random
(
id(),
player:id()
)
-> struct().
random (ID, OwnerID) ->
WeaponIDs = {weapon:random_id(), weapon:random_id()},
Attributes = attributes:random(),
Statistics = statistics:new(Attributes, WeaponIDs),
IDAsListString = integer_to_list(ID),
IDAsBinaryString = list_to_binary(IDAsListString),
#character
{
id = ID,
owner_id = OwnerID,
name = list_to_binary("Char" ++ IDAsListString),
icon = IDAsBinaryString,
portrait = IDAsBinaryString,
attributes = Attributes,
weapon_ids = WeaponIDs,
statistics = Statistics
}.
|