-
Notifications
You must be signed in to change notification settings - Fork 8
/
player-events.js
80 lines (65 loc) · 2.06 KB
/
player-events.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
'use strict';
module.exports = {
listeners: {
attributeUpdate: state => function () {
updateAttributes.call(this);
},
login: state => function () {
this.socket.command('sendData', 'quests', this.questTracker.serialize().active);
const effects = this.effects.entries().filter(effect => !effect.config.hidden).map(effect => effect.serialize());
this.socket.command('sendData', 'effects', effects);
updateAttributes.call(this);
},
combatantAdded: state => function () {
updateTargets.call(this);
},
combatantRemoved: state => function () {
updateTargets.call(this);
},
updateTick: state => function () {
const effects = this.effects.entries().filter(effect => !effect.config.hidden).map(effect => ({
name: effect.name,
elapsed: effect.elapsed,
remaining: effect.remaining,
config: {
duration: effect.config.duration
}
}));
if (effects.length) {
this.socket.command('sendData', 'effects', effects);
}
if (!this.isInCombat()) {
return;
}
updateTargets.call(this);
},
effectRemoved: state => function () {
if (!this.effects.size) {
this.socket.command('sendData', 'effects', []);
}
},
questProgress: state => function () {
this.socket.command('sendData', 'quests', this.questTracker.serialize().active);
},
}
};
function updateAttributes() {
// example of sending player data to a websocket client. This data is not sent to the default telnet socket
let attributes = {};
for (const [name, attribute] of this.attributes) {
attributes[name] = {
current: this.getAttribute(name),
max: this.getMaxAttribute(name),
};
}
this.socket.command('sendData', 'attributes', attributes);
}
function updateTargets() {
this.socket.command('sendData', 'targets', [...this.combatants].map(target => ({
name: target.name,
health: {
current: target.getAttribute('health'),
max: target.getMaxAttribute('health'),
},
})));
}