-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslot_methods.gml
298 lines (267 loc) · 9.06 KB
/
slot_methods.gml
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// api_slot_clear()
// clear slot, setting item to "" count + health to 0 and resetting stats to empty
function sc_mod_api_slot_clear(slot_id) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
try {
if (slot_id != undefined && instance_exists(slot_id)) {
sc_slot_clear(slot_id);
return "Success";
}
} catch(ex) {
sc_mod_log(mod_name, "api_slot_clear", "Error: Failed To Clear Slot", ex.longMessage);
return undefined;
}
}
// api_slot_incr()
// add to slot amount, capped at 99
function sc_mod_api_slot_incr(slot_id, amount) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
try {
if (slot_id != undefined && instance_exists(slot_id)) {
if (amount == undefined) amount = 1;
slot_id.count += amount;
if (slot_id.count > 99) slot_id.count = 99;
return "Success";
}
} catch(ex) {
sc_mod_log(mod_name, "api_slot_incr", "Error: Failed To Increase Slot", ex.longMessage);
return undefined;
}
}
// api_slot_decr()
// remove from slot amount, clearing if 0 is left
function sc_mod_api_slot_decr(slot_id, amount) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
try {
if (slot_id != undefined && instance_exists(slot_id)) {
if (amount == undefined) amount = 1;
slot_id.count -= amount;
if (slot_id.count <= 0) {
sc_slot_clear(slot_id);
}
return "Success";
}
} catch(ex) {
sc_mod_log(mod_name, "api_slot_incr", "Error: Failed To Descrease Slot", ex.longMessage);
return undefined;
}
}
// api_slot_set()
// set a given slot with a given item
function sc_mod_api_slot_set(slot_id, item, amount, stats) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
try {
if (slot_id != undefined && instance_exists(slot_id)) {
var data = sc_util_create_item_data(item, amount, stats == undefined ? {} : stats);
sc_slot_set(slot_id, data.item, data.total, data.durability, data.durability, stats == undefined ? data.stats : stats);
return "Success";
}
} catch(ex) {
sc_mod_log(mod_name, "api_slot_set", "Error: Failed To Set Slot", ex.longMessage);
return undefined;
}
}
// api_slot_match()
// get the first slot with a match in the match list
function sc_mod_api_slot_match(menu_id, match, first) {
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id) && variable_instance_exists(menu_id, "slots")) {
var slots = [];
// convert datatype from array to list
var matches = ds_list_create();
for (var m = 0; m < array_length(match); m++) {
ds_list_add(matches, match[m]);
}
// check for ANY as match option
var match_any = ds_list_find_index(matches, "ANY") != -1;
for (var s = 0; s < ds_list_size(menu_id.slots); s++) {
var slot = menu_id.slots[| s];
// check match
if (match_any == true && slot.item != "" || ds_list_find_index(matches, slot.item) != -1) {
if (first == true) { // return first match if specified
ds_list_destroy(matches);
return {
id: slot.id,
index: slot.index+1,
item: slot.item,
count: slot.count,
current_health: slot.current_health,
total_health: slot.total_health,
stats: slot.stats
};
} else {
array_push(slots, {
id: slot.id,
index: slot.index+1,
item: slot.item,
count: slot.count,
current_health: slot.current_health,
total_health: slot.total_health,
stats: slot.stats
});
}
}
}
ds_list_destroy(matches);
if (first == true) return undefined;
return slots;
} else {
return undefined;
}
}
// api_slot_match_range()
// get the first slot with a match from a range
function sc_mod_api_slot_match_range(menu_id, match, range, first) {
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id) && variable_instance_exists(menu_id, "slots")) {
var slots = [];
// convert datatypes
var matches = ds_list_create();
for (var m = 0; m < array_length(match); m++) {
ds_list_add(matches, match[m]);
}
var match_any = ds_list_find_index(matches, "ANY") != -1;
var ranges = ds_list_create();
for (var r = 0; r < array_length(range); r++) {
ds_list_add(ranges, range[r]);
}
// check slots
for (var s = 0; s < ds_list_size(menu_id.slots); s++) {
var slot = menu_id.slots[| s];
if (ds_list_find_index(ranges, slot.index+1) != -1) {
if (match_any == true && slot.item != "" || ds_list_find_index(matches, slot.item) != -1) {
if (first == true) { // return first if specified
ds_list_destroy(matches);
ds_list_destroy(ranges);
return {
id: slot.id,
index: slot.index+1,
item: slot.item,
count: slot.count,
current_health: slot.current_health,
total_health: slot.total_health,
stats: slot.stats
};
} else {
array_push(slots, {
id: slot.id,
index: slot.index+1,
item: slot.item,
count: slot.count,
current_health: slot.current_health,
total_health: slot.total_health,
stats: slot.stats
});
}
}
}
}
// destroy temp data + return slots
ds_list_destroy(matches);
ds_list_destroy(ranges);
if (first == true) return undefined;
return slots;
} else {
return undefined;
}
}
// api_slot_fill()
// automatically start a slot fill event
function sc_mod_api_slot_fill(menu_id, slot_index) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id)) {
menu_id.filling = true;
menu_id.mod_fill = slot_index-1;
sc_menu_fill(menu_id, slot_index-1, 0);
return "Success";
} else {
sc_mod_log(mod_name, "api_slot_fill", "Error: Menu Instance Doesn't Exist", undefined);
return undefined;
}
}
// api_slot_drain()
// automatically start a slot drain event
function sc_mod_api_slot_drain(menu_id, slot_index) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id)) {
menu_id.draining = true;
menu_id.mod_drain = slot_index-1;
sc_menu_drain(menu_id, slot_index-1, 1);
return "Success"
} else {
sc_mod_log(mod_name, "api_slot_drain", "Error: Menu Instance Doesn't Exist", undefined);
return undefined;
}
}
// api_slot_set_inactive
// set a slot to be inactive, making it unable to be highlighted or clicked
function sc_mod_api_slot_set_inactive(slot_id, inactive) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
if (slot_id != undefined && instance_exists(slot_id)) {
slot_id.inactive = inactive;
return "Success";
} else {
sc_mod_log(mod_name, "api_slot_set_inactive", "Error: Slot Instance Doesn't Exist", undefined);
return undefined;
}
}
// api_slot_set_modded
// set a slot to be modded, making it able to be highlighted but cant be clicked
function sc_mod_api_slot_set_modded(slot_id, modded) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
if (slot_id != undefined && instance_exists(slot_id)) {
slot_id.modded = modded;
return "Success";
} else {
sc_mod_log(mod_name, "api_slot_set_modded", "Error: Slot Instance Doesn't Exist", undefined);
return undefined;
}
}
// api_slot_validate
// checks a slot can take a given item w/ stats
function sc_mod_api_slot_validate(slot_id, item, stats) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
if (slot_id != undefined && instance_exists(slot_id)) {
return sc_slot_validate(slot_id, item, stats);
} else {
sc_mod_log(mod_name, "api_slot_validate", "Error: Slot Instance Doesn't Exist", undefined);
return false;
}
}
// api_slot_item_id
// gets a slot item as a : id, i.e. bee:common or frame1:filled or axe1 etc
function sc_mod_api_slot_item_id(menu_id, slot_index) {
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id) && variable_instance_exists(menu_id, "slots")) {
var slot = menu_id.slots[| slot_index-1];
var item = slot.item;
if (item == "bee" && slot.stats != undefined) item += ":" + slot.stats.species;
if (contains(item, "frame")) {
if (slot.stats.uncapped == true) {
item += ":uncapped";
} else if (slot.stats.filled == true) {
item += ":filled";
}
}
return item;
} else {
return undefined;
}
}
// api_slot_draw
// re-draws a specific slot
function sc_mod_api_slot_redraw(slot_id) {
sc_mod_api_set_active(slot_id);
if (slot_id != undefined && instance_exists(slot_id)) {
sc_slot_draw(slot_id, false);
}
}