forked from mozilla/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathitem.js
44 lines (37 loc) · 1.1 KB
/
item.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
var Entity = require('./entity');
module.exports = Item = Entity.extend({
init: function (id, kind, x, y) {
this._super(id, 'item', kind, x, y);
this.isStatic = false;
this.isFromChest = false;
},
handleDespawn: function (params) {
var self = this;
this.blinkTimeout = setTimeout(function () {
params.blinkCallback();
self.despawnTimeout = setTimeout(params.despawnCallback, params.blinkingDuration);
}, params.beforeBlinkDelay);
},
destroy: function () {
if (this.blinkTimeout) {
clearTimeout(this.blinkTimeout);
}
if (this.despawnTimeout) {
clearTimeout(this.despawnTimeout);
}
if (this.isStatic) {
this.scheduleRespawn(30000);
}
},
scheduleRespawn: function (delay) {
var self = this;
setTimeout(function () {
if (self.respawnCallback) {
self.respawnCallback();
}
}, delay);
},
onRespawn: function (callback) {
this.respawnCallback = callback;
}
});