-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateItem.js
More file actions
73 lines (70 loc) · 1.7 KB
/
createItem.js
File metadata and controls
73 lines (70 loc) · 1.7 KB
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
function createItem(item) {
item = eval(`items.${item}`);
item.button.disabled = true;
var hasNeededMaterials = item.requirements.every((req) => {
const reqRef = eval(`items.${req.item}`);
const itemToUse = player.inventory.find((i) => i.item == reqRef);
if (itemToUse) {
if (itemToUse.count >= req.count) {
return true;
} else {
alert("not enough " + req.item);
item.button.disabled = false;
return false;
}
} else {
alert("not enough " + req.item);
item.button.disabled = false;
return false;
}
});
if (hasNeededMaterials == true) {
setTimeout(function () {
item.requirements.forEach((req) => {
const itemRef = eval(`items.${req.item}`);
const itemToUse = player.inventory.find((i) => i.item == itemRef);
itemToUse.count = itemToUse.count - req.count;
});
placeItemInInv(item);
item.button.disabled = false;
updateList();
}, item.cooldown);
}
}
function placeItemInInv(item) {
let itemToCraft = player.inventory.find((i) => i.item == item);
if (itemToCraft) {
itemToCraft.count++;
} else {
player.inventory.push({ item: item, count: 1 });
itemToCraft = player.inventory.find((i) => i.item == item);
}
}
actions = {
forage: {
cooldown: 10000,
items: [
[5, items.grass],
[5, items.leaf],
[5, items.stick]
]
},
excavate: {
cooldown: 10000,
items: [
[5, items.dirt],
[5, items.rock]
]
},
hunt: {
cooldown: 10000,
items: [
[5, items.feather]
]
}
}
function forage() {
setTimeout(function () {
placeItemInInv(items.grass);
}, actions.forage.cooldown)
}