Repository navigation
Expand file tree
/
Copy pathItem.js
More file actions
94 lines (85 loc) · 2.95 KB
/
Copy pathItem.js
File metadata and controls
94 lines (85 loc) · 2.95 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class Item extends Entity {
constructor(x, y, id, type, owner, tiles) {
super(x, y, 0, tiles)
this.id = id;
this.type = type;
this.owner = owner;
this.name = Item.getItemInfo(type).name;
this.model = globalSpriteList.models.underberg;
}
draw(x, y) {
let newX = this.x + 4 - x;
let newY = this.y + 4 - y;
image(this.model, newX * TILE_WIDTH, newY * TILE_HEIGHT);
}
interact(newOwner) {
this.owner = newOwner;
//Find this items index number and remove it from list of world-entities
let index;
for (let i = 0; i < entities.length; i++) {
if (Object.is(this, entities[i])) {
index = i;
break;
}
}
entities.splice(index, 1);
//Clear tile
this.tile.setClear(true);
this.tile.occupant = null;
this.tile = null;
//Add to saved list of picked up items to prevent respawning.
addToPickedItems(this);
//Add to inventory of player.
this.owner.addItem(this);
dialogue.load([{ type: "timed", line: `Picked up ${this.name}.`, time: 1000 }]);
}
static getItemInfo(itemType) {
let info = { hasWorldUse: false, hasBattleUse: false, name: "Unknown" };
switch (itemType) {
case "ball_regular":
info.hasBattleUse = true;
info.hasWorldUse = false;
info.name = "Ball";
break;
case "potion":
info.hasBattleUse = true;
info.hasWorldUse = true;
info.name = "Potion";
break;
default:
break;
}
return info
}
static async useItem(itemType, index) {
switch (itemType) {
case "potion":
menu.loadedItem = { heal: 20 }
menu.lastState = state;
state = STATE.PAUSED;
menu.index = 0;
menu.menuState = MENU_STATES.MONSTER_MENU;
break;
case "ball_regular":
if (battle.activeEnemy.owner != "wild") {
await dialogue.load([{ type: "timed", line: "Thief! You can't steal a bojsemon.", time: 1000 }]);
battle.selectingItem = false;
return;
}
battle.selectingItem = false;
menu.index = 0;
menu.offset = 0;
menu.menuState = MENU_STATES.MAIN_MENU;
player.removeItem(index);
battle.draw();
await AnimationManager.throwBall();
if (battle.activeEnemy.catch(0)) {
await battle.caughtMonster();
} else {
await dialogue.load([{ type: "statement", line: "Oh no! it broke free!" }]);
}
default:
break;
}
}
}