Repository navigation
Expand file tree
/
Copy pathabnormalities.js
More file actions
74 lines (54 loc) · 1.52 KB
/
Copy pathabnormalities.js
File metadata and controls
74 lines (54 loc) · 1.52 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
const DEBUG = false
const handled = require('./config/abnormalities')
class AbnormalityPrediction {
constructor(dispatch) {
this.dispatch = dispatch
this.cid =
this.myAbnormals =
null
dispatch.hook('sLogin', event => {
this.cid = event.cid
this.myAbnormals = {}
})
let abnormalityUpdate = event => {
if(event.target.equals(this.cid)) {
if(DEBUG) console.log('<- Abnormality', event.id, event.duration, event.stacks)
if(handled[event.id]) return false
this.myAbnormals[event.id] = event.duration == 0x7fffffff ? Infinity : Date.now() + event.duration
}
}
dispatch.hook('sAbnormalityBegin', abnormalityUpdate)
dispatch.hook('sAbnormalityRefresh', abnormalityUpdate)
dispatch.hook('sAbnormalityEnd', event => {
if(event.target.equals(this.cid)) {
if(DEBUG) console.log('<- AbnormalityEnd', event.id)
if(handled[event.id]) return false
delete this.myAbnormals[event.id]
}
})
}
exists(id) {
return this.myAbnormals[id] > Date.now()
}
add(id, duration, stacks) {
if(DEBUG) console.log('<* Abnormality', id, duration, stacks)
this.dispatch.toClient(this.myAbnormals[id] ? 'sAbnormalityRefresh' : 'sAbnormalityBegin', {
target: this.cid,
source: this.cid,
id,
duration,
unk: 0,
stacks
})
this.myAbnormals[id] = Date.now() + duration
}
remove(id) {
if(DEBUG) console.log('<* AbnormalityEnd', id)
this.dispatch.toClient('sAbnormalityEnd', {
target: this.cid,
id
})
delete this.myAbnormals[id]
}
}
module.exports = AbnormalityPrediction