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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
-module(btl_player).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
player,
{
ix :: non_neg_integer(),
id :: shr_player:id(),
character_ix :: non_neg_integer(),
timeline :: list(any()),
is_active :: boolean(),
luck :: integer(),
summary_ix :: non_neg_integer(),
summary_category :: shr_battle_summary:category()
}
).
-opaque type() :: #player{}.
-export_type([type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
[
get_id/1,
get_index/1,
get_luck/1,
get_summary_index/1,
get_summary_category/1,
get_character_index/1,
get_timeline/1,
get_is_active/1,
set_is_active/2,
ataxia_set_is_active/2,
set_luck/2,
ataxia_set_luck/2,
add_to_timeline/2,
ataxia_add_to_timeline/2,
reset_timeline/1,
ataxia_reset_timeline/1,
get_timeline_field/0,
get_luck_field/0,
get_is_active_field/0
]
).
-export
(
[
new/5
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec get_id (type()) -> shr_player:id().
get_id (Player) -> Player#player.id.
-spec get_index (type()) -> non_neg_integer().
get_index (Player) -> Player#player.ix.
-spec get_luck (type()) -> integer().
get_luck (Player) -> Player#player.luck.
-spec get_summary_index (type()) -> non_neg_integer().
get_summary_index (Player) -> Player#player.summary_ix.
-spec get_summary_category (type()) -> shr_battle_summary:category().
get_summary_category (Player) -> Player#player.summary_category.
-spec get_character_index (type()) -> non_neg_integer().
get_character_index (Player) -> Player#player.character_ix.
-spec get_timeline (type()) -> list(any()).
get_timeline (Player) -> Player#player.timeline.
-spec get_is_active (type()) -> boolean().
get_is_active (Player) -> Player#player.is_active.
-spec set_is_active (boolean(), type()) -> type().
set_is_active (Val, Player) -> Player#player{ is_active = Val }.
-spec ataxia_set_is_active (boolean(), type()) -> {type(), ataxic:basic()}.
ataxia_set_is_active (Val, Player) ->
{
Player#player{ is_active = Val },
ataxic:update_field
(
get_is_active_field(),
ataxic:constant(Val)
)
}.
-spec set_luck (integer(), type()) -> type().
set_luck (Val, Player) -> Player#player{ luck = Val }.
-spec ataxia_set_luck (integer(), type()) -> {type(), ataxic:basic()}.
ataxia_set_luck (Val, Player) ->
{
Player#player{ luck = Val },
ataxic:update_field
(
get_luck_field(),
ataxic:constant(Val)
)
}.
-spec add_to_timeline (list(any()), type()) -> type().
add_to_timeline (NewEvents, Player) ->
Player#player
{
timeline = (NewEvents ++ Player#player.timeline)
}.
-spec ataxia_add_to_timeline (list(any()), type()) -> {type(), ataxic:basic()}.
ataxia_add_to_timeline (NewEvents, Player) ->
{
Player#player{ timeline = (NewEvents ++ Player#player.timeline) },
ataxic:update_field
(
get_timeline_field(),
ataxic:apply_function
(
lists,
append,
[
ataxic:constant(NewEvents),
ataxic:current_value()
]
)
)
}.
-spec reset_timeline (type()) -> type().
reset_timeline (Player) -> Player#player{ timeline = [] }.
-spec ataxia_reset_timeline (type()) -> {type(), ataxic:basic()}.
ataxia_reset_timeline (Player) ->
{
Player#player{ timeline = [] },
ataxic:update_field
(
get_timeline_field(),
ataxic:constant([])
)
}.
-spec new
(
non_neg_integer(),
non_neg_integer(),
shr_player:id(),
non_neg_integer(),
shr_battle_summary:category()
) -> type().
new (IX, CharacterIX, ID, SummaryIX, SummaryCategory) ->
#player
{
ix = IX,
character_ix = CharacterIX,
id = ID,
is_active = true,
timeline = [],
luck = 0,
summary_ix = SummaryIX,
summary_category = SummaryCategory
}.
-spec get_timeline_field () -> non_neg_integer().
get_timeline_field () -> #player.timeline.
-spec get_luck_field () -> non_neg_integer().
get_luck_field () -> #player.luck.
-spec get_is_active_field () -> non_neg_integer().
get_is_active_field () -> #player.is_active.
|