-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
219 lines (187 loc) · 7.38 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// vers 1.0.0
var fs = require('fs');
const format = require('./format.js');
module.exports = function BossSkillLogger(dispatch) {
let enabled = false,
//bossId = 0,
cid = null,
party = [],
writeLog = false, // Optionally write a log
logFolder = './../../boss_logs/'; // "TeraProxy base folder"
var stream;
const chatHook = event => {
let command = format.stripTags(event.message).split(' ');
if (['!bosslog'].includes(command[0].toLowerCase())) {
toggleModule();
return false;
}
}
dispatch.hook('C_CHAT', 1, chatHook)
dispatch.hook('C_WHISPER', 1, chatHook)
// slash support
try {
const Slash = require('slash')
const slash = new Slash(dispatch)
slash.on('bosslog', args => toggleModule())
} catch (e) {
// do nothing because slash is optional
}
function toggleModule() {
enabled = !enabled;
sendChat((enabled ? 'enabled' : 'disabled'));
if (writeLog) {
if (enabled) {
if (!fs.existsSync(logFolder))
{
fs.mkdirSync(logFolder);
}
let filename = logFolder + Date.now() + '.txt';
stream = fs.createWriteStream(filename);
} else {
if (stream) {
try {
stream.end();
} catch (e) {
console.log(e);
}
}
}
}
}
dispatch.hook('S_LOGIN', 2, (event) => {
cid = event.cid;
})
dispatch.hook('S_EXIT', 1, (event) => {
if (stream) {
try {
stream.end();
} catch (e) {
console.log(e);
}
}
})
dispatch.hook('S_PARTY_MEMBER_LIST', 4, (event) => {
party = event;
})
dispatch.hook('S_BOSS_GAGE_INFO', 2, (event) => {
if (!enabled) return;
//bossId = event.id;
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_BOSS_GAGE_INFO : ' + event.id +
' hntngZnId: ' + event.huntingZoneId +
' templateId: '+ event.templateId +
' cupHp: ' + event.curHp +
' maxHp: ' + event.maxHp +
' unk1: ' + event.unk1 +
' unk2(Enrage?): ' + event.unk2 +
' hpDiff: ' + event.hpDiff +
' unk3: ' + event.unk3 +
' hpPerc: ' + (event.curHp / event.maxHp));
})
dispatch.hook('S_ACTION_STAGE', 1, (event) => {
if (!enabled || (event.source - cid == 0)) return; // ignore self
for (let i in party.members) {
if (party.members[i].cID - event.source == 0) return; // ignore party
}
//if (event.source - bossId != 0) return; // ignore adds?
if (event.stage > 0) return; // (Optional) ignore additional stages, one is usually enough.
sendChat('S_ACT_STG: ' + event.skill + ' ' + event.stage);
//sendChat('S_ACT_STG: ' + event.skill + ' ' + event.stage + ' ' + event.source); // might be useful for adds
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_ACTION_STAGE : ' + event.source +
' model: ' + event.model +
' skill: ' + event.skill +
' stage: ' + event.stage +
' id: ' + event.id +
' unk: ' + event.unk +
' unk1: ' + event.unk1 +
' unk2: ' + event.unk2 +
' unk3: ' + event.unk3 +
' speed: ' + event.speed);
})
dispatch.hook('S_ACTION_END', 1, (event) => {
if (!enabled || (event.source - cid == 0)) return; // ignore self
for (let i in party.members) {
if (party.members[i].cID - event.source == 0) return; // ignore party
}
//if (event.source - bossId != 0) return; // ignore adds?
sendChat('S_ACT_END: ' + event.skill);
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_ACTION_END : ' + event.source +
' model: ' + event.model +
' skill: ' + event.skill +
' type: ' + event.type +
' id: ' + event.id);
})
dispatch.hook('S_CHAT', 1, (event) => {
if (!enabled) return;
if (event.channel == 1 || event.channel == 21 || event.channel == 0) {
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_CHAT : ' + event.authorName +
' : ' + event.message );
}
})
dispatch.hook('S_DUNGEON_EVENT_MESSAGE', 1, (event) => {
if (!enabled) return;
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_DUNGEON_EVENT_MESSAGE : ' + event.message);
})
dispatch.hook('C_MEET_BOSS_INFO', 1, (event) => {
if (!enabled) return;
sendChat('MEET_BOSS: ' + event.huntingZoneId + '-' + event.templateId);
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'C_MEET_BOSS_INFO' +
' huntingZoneId: ' + event.huntingZoneId +
' templateId: ' + event.templateId);
})
dispatch.hook('S_DUNGEON_EVENT_MESSAGE', 1, (event) => {
if (!enabled) return;
sendChat('DG_EVT_MSG: ' + event.message);
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_DUNGEON_EVENT_MESSAGE ' + event.message);
})
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.toClient('S_CHAT', 1, {
channel: 1,
authorName: 'Boss',
message: (getTime() + ' ' + msg)
});
}
/*
dispatch.hook('S_NPC_STATUS', 1, (event) => {
if (!enabled) return;
sendChat('Status: ' + event.message)
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_NPC_STATUS : ' + event.message);
})
dispatch.hook('S_NPC_SITUATION', 1, (event) => {
if (!enabled) return;
sendChat('NPC SIT....: ' + event.unk);
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_NPC_SITUATION : ' + event.cid +
' unk: ' + event.unk);
})
dispatch.hook('S_NPC_AI_EVENT', 1, (event) => {
if (!enabled) return;
sendChat('AI Event : ' + event.event);
if (writeLog)
stream.write('\n' + new Date().toLocaleTimeString() +
'S_NPC_AI_EVENT : ' + event.npc +
' event: ' + event.event);
})
*/
}