-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_inv.6.js
40 lines (37 loc) · 1007 Bytes
/
sort_inv.6.js
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
async function sortBank(pack)
{
var inv = character.bank?.[pack];
if (!inv) log(`No item in bank of ${pack}`);
const promises = [];
const invLength = inv.length;
for (let i = 0; i < invLength - 1; i++) {
for (let j = i + 1; j < invLength; j++) {
const lhs = inv[i];
const rhs = inv[j];
if (rhs === null) continue;
if (lhs === null) {
const temp = inv[i];
inv[i] = inv[j];
inv[j] = temp;
promises.push(bank_swap(pack, i, j));
continue;
}
if (lhs.name.localeCompare(rhs.name) === -1) {
const temp = inv[i];
inv[i] = inv[j];
inv[j] = temp;
promises.push(bank_swap(pack, i, j));
continue;
}
if (lhs.name === rhs.name) {
if ((lhs?.level ?? 0) < (rhs?.level ?? 0)) {
const temp = inv[i];
inv[i] = inv[j];
inv[j] = temp;
promises.push(bank_swap(pack, i, j));
};
}
}
}
return Promise.all(promises);
}