-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-inventory.js
142 lines (128 loc) · 4.16 KB
/
02-inventory.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
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
/* eslint-disable no-undef, no-console, max-len, no-plusplus, no-unused-vars */
function MyFood(id, name, qty) {
this.id = id;
this.name = name;
this.qty = qty;
this.MAX = 6969696969;
}
function allOfTypeInItems(t) {
return items.filter((i) => i.type === t);
}
function allCraftingItems() {
return items.filter((i) => items[i].craftingID !== undefined);
}
function allOfTypeInBank(t) {
return bank.filter((i) => (i.type === t && !i.locked));
}
function itemInBank(id) {
return bank.filter((i) => i.id === id).pop();
}
function sellAllOfType(t) {
const things = allOfTypeInBank(t);
things.forEach((thing) => {
try {
sellItem(thing.id);
} catch (err) {
console.error(`oops! hit an error when selling an item: ${err}`);
}
});
}
function sellAllOfNameSubstring(s) {
const things = bank.filter((i) => i.name.includes(s));
things.forEach((thing) => {
try {
sellItem(thing.id);
} catch (err) {
console.error(`oops! hit an error when selling an item: ${err}`);
}
});
}
function learnTokens() {
const tokens = allOfTypeInBank('Token');
tokens.forEach((token) => {
for (let i = 0; i < token.qty; i++) {
try {
claimBankToken(currentBank, token.id);
} catch (err) {
console.error(`oops! hit an error when learning a token: ${err}`);
}
}
});
}
function buryBones() {
const bones = allOfTypeInBank('Bones');
bones.forEach((bone) => {
if (bone.qty >= 10) {
cname = bone.name.replaceAll(' ', '_');
try {
buryItem(currentBank, CONSTANTS.item[cname], 6969696969);
} catch (err) {
console.error(`oops! hit an error when burying bones: ${err}`);
}
}
});
}
function haveMaterialsForCrafting(item) {
const required = [];
let haveAllRequired;
item.craftReq.forEach((req) => {
required.push(checkBankForItem(req.id));
});
if (required.some((thing) => thing === false)) {
haveAllRequired = false;
} else {
haveAllRequired = true;
}
/* eslint-disable object-shorthand */
return { haveAllRequired: haveAllRequired, forItem: item };
/* eslint-enable object-shorthand */
}
function findFood() {
const foodList = [];
const allFoodItems = allOfTypeInBank('Food');
allFoodItems.forEach((food) => {
foodList.push(new MyFood(food.id, food.name, food.qty));
});
return foodList;
}
function isOutOfEquippedFood() {
return equippedFood[0].itemID === equippedFood[1].itemID && equippedFood[0].itemID === equippedFood[2].itemID;
}
function getEquippedFoodCount() { return equippedFood[currentCombatFood].qty; }
function equipNextFood() {
for (let i = 0; i < equippedFood.length; i++) {
try {
if (equippedFood[i].qty > 0) {
selectEquippedFood(i);
return true;
}
} catch (err) {
console.error(`oops! we hit an error equipping next food: ${err}`);
}
}
return false;
}
function foodTracker() {
if (!isInCombat) return; // we're not in combat, don't need to watch food
if (getEquippedFoodCount() > 0) return; // we have equipped food to eat
const foodList = findFood();
if (isOutOfEquippedFood() && foodList.length === 0) { // completely out of food
try {
stopCombat(false, true, true); // death, stopDungeon, runAway
console.log(`Dropped out of combat due to lack of food at ${new Date()}`);
} catch (err) {
console.error(`oops! hit an error when stopping combat: ${err}`);
}
} else if (equipNextFood()) { // we have food in pocket, but need to equip it
/* eslint-disable no-useless-return */
return; // We successfully swapped to equipped food
/* eslint-enable no-useless-return */
} else {
const f = foodList.pop();
try {
equipFood(currentBank, f.id, f.qty);
} catch (err) {
console.error(`oops! hit an error when equipping food from bank: ${err}`);
}
}
}