forked from teralove/boss-skill-logger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
111 lines (96 loc) · 2.69 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
String.prototype.clr = function (hexColor) { return `<font color="#${hexColor}">${this}</font>` };
const format = require('./format.js');
const path = require('path');
const fs = require('fs');
const config = require('./config.json');
const logFolder = path.join(__dirname, 'boss_logs');
if (!fs.existsSync(logFolder)) fs.mkdirSync(logFolder);
module.exports = function BossSkillLogger(dispatch) {
let enabled = config.enabled,
writeLog = config.writeLog,
cid = null,
party = [],
bosshp;
var stream;
dispatch.command.add('bsl', () => {
enabled = !enabled;
dispatch.command.message('记录王的技能ID ' + (enabled ? '启用'.clr('56B4E9') : '禁用'.clr('E69F00')));
if (writeLog) {
if (enabled) {
let filename = path.join(logFolder, Date.now() + '.js');
stream = fs.createWriteStream(filename);
} else {
if (stream) {
try {
stream.end();
} catch (e) {
console.log(e);
}
}
}
}
})
dispatch.hook('S_LOGIN', 10, (event) => {
cid = event.gameId;
})
dispatch.hook('S_EXIT', 3, (event) => {
if (stream) {
try {
stream.end();
} catch (e) {
console.log(e);
}
}
})
/*
dispatch.hook('S_PARTY_MEMBER_LIST', 7, (event) => {
party = event;
})
*/
dispatch.hook('S_BOSS_GAGE_INFO', 3, (event) => {
bosshp = Math.floor((event.curHp / event.maxHp)*10000)/100;
})
dispatch.hook('S_DUNGEON_EVENT_MESSAGE', 2, (event) => {
if (!enabled) return;
sendChat('MSG: ' + `${event.message}`.clr('00FFFF'));
if (writeLog)
stream.write(
'\n' + new Date().toLocaleTimeString() +
' |S_DUNGEON_EVENT_MESSAGE|: ' + event.message
);
})
dispatch.hook('S_ACTION_STAGE', 8, (event) => {
if (!enabled || ((event.gameId - cid) == 0)) return;
// for (let i in party.members) {
// if (party.members[i].gameId - event.gameId == 0) return;
// }
if (event.templateId!=1000 && event.templateId!=2000 && event.templateId!=3000) return;
if (event.stage > 0) return;
sendChat(
'ACT: ' + `${event.skill}`.clr('E69F00') +
` ${event.skill.id}`.clr('56B4E9') +
` HP ${bosshp} %`.clr('00FFFF')
);
if (writeLog)
stream.write(
'\n' + new Date().toLocaleTimeString() +
' |S_ACTION_STAGE|: ' + event.gameId +
' skill: ' + event.skill +
' id: ' + event.id +
' stage: ' + event.stage +
' templateId: ' + event.templateId +
' HP: ' + bosshp
);
})
function getTime() {
var time = new Date();
var timeStr = ("0" + time.getHours()).slice(-2) + ":" + ("0" + time.getMinutes()).slice(-2) + ":" + ("0" + time.getSeconds()).slice(-2);
return timeStr;
}
function sendChat(msg) {
dispatch.command.message(
//getTime() + ' - ' + msg
msg
)
}
}