This repository has been archived by the owner on Jan 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
171 lines (135 loc) · 4.81 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
// vers 1.0.0b
const format = require('./format.js');
const BossId = [470, 1000]; // Manglemire
//ActionId: truth, lie
const BossActions = {
1171655820: {truth: 'Truth -> Break shield', lie: 'Lie -> Puddles (run away)'}, // "My shield will save me!" (shield)
1171655821: {truth: 'Truth -> Stay outside', lie: 'Lie -> Stay inside'}, // "I will kill you all!" (aoe around boss)
1171655826: {truth: 'Truth -> Stay outside', lie: 'Lie -> Stay inside'} // "One of you must die!" (aoe around player)
};
//AbnormalId: BossBuff
const BossAbnormals = {
470046: 3,
470047: 6,
470048: 9
};
module.exports = function MMGuide(dispatch) {
let enabled = true,
sendToParty = false,
boss = undefined,
bossBuffs = [],
meterValue = 0;
const chatHook = event => {
let command = format.stripTags(event.message).split(' ');
if (['!mm'].includes(command[0].toLowerCase())) {
toggleModule();
return false;
} else if (['!mm.party'].includes(command[0].toLowerCase())) {
toggleSentMessages();
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('mmn', args => toggleModule())
slash.on('mm.party', args => toggleSentMessages())
} catch (e) {
// do nothing because slash is optional
}
function toggleModule() {
enabled = !enabled;
systemMessage((enabled ? 'enabled' : 'disabled'));
}
function toggleSentMessages() {
sendToParty = !sendToParty;
systemMessage((sendToParty ? 'Messages will be sent to the party' : 'Only you will see messages'));
}
function bossHealth() {
return (boss.curHp / boss.maxHp);
}
function isTellingTruth() {
let ones = meterValue % 10;
let tens = Math.floor((meterValue % 100) / 10);
if (bossBuffs.includes(ones) || bossBuffs.includes(tens))
{
return false;
}
return true;
}
dispatch.hook('S_ABNORMALITY_BEGIN', 1, (event) => {
if (!enabled || !boss) return;
if (boss.id - event.target == 0) {
//console.log('\n S_ABNORMALITY_BEGIN -> ' + event.id);
if (BossAbnormals[event.id]) {
if (!bossBuffs.includes(BossAbnormals[event.id])) bossBuffs.push(BossAbnormals[event.id]);
}
}
})
dispatch.hook('S_ABNORMALITY_END', 1, (event) => {
if (!enabled || !boss) return;
if (boss.id - event.target == 0) {
//console.log('\n S_ABNORMALITY_END -> ' + event.id);
let index = bossBuffs.indexOf(BossAbnormals[event.id]);
if (index > -1) bossBuffs.splice(index, 1);
}
})
// dispatch.hook('S_ABNORMALITY_REFRESH', 1, (event) => {
// if (!enabled || !boss) return;
// if (boss.id - event.target == 0) {
// console.log('\n S_ABNORMALITY_REFRESH -> ' + event.id);
// }
// })
dispatch.hook('S_DUNGEON_EVENT_GAGE', 1, (event) => {
if (!enabled || !boss) return;
meterValue = event.value;
})
dispatch.hook('S_BOSS_GAGE_INFO', 2, (event) => {
if (!enabled) return;
if (event.huntingZoneId == BossId[0] && event.templateId == BossId[1]) {
boss = event;
}
if (boss) {
let bossHp = bossHealth();
if (bossHp == 0) boss = undefined;
if (bossHp == 0 || bossHp == 1) {
bossBuffs = [];
meterValue = 0;
}
}
})
dispatch.hook('S_ACTION_STAGE', 1, (event) => {
if (!enabled || !boss) return;
if (boss.id - event.source == 0) {
if (BossActions[event.skill]) {
sendMessage(isTellingTruth() ? BossActions[event.skill].truth : BossActions[event.skill].lie)
}
}
})
function sendMessage(msg) {
if (!enabled) return;
console.log(msg);
if (sendToParty) {
dispatch.toServer('C_CHAT', 1, {
channel: 1, //21 = p-notice, 1 = party
message: msg
});
} else {
dispatch.toClient('S_CHAT', 1, {
channel: 21, //21 = p-notice, 1 = party
authorName: 'DG-Guide',
message: msg
});
}
}
function systemMessage(msg) {
dispatch.toClient('S_CHAT', 1, {
channel: 24, //system channel
authorName: '',
message: ' (MM-Guide) ' + msg
});
}
}