forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpullcounter.js
318 lines (286 loc) · 7.63 KB
/
pullcounter.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import '../../resources/common.js';
import { LocaleRegex } from '../../resources/translations.js';
import Regexes from '../../resources/regexes.js';
import UserConfig from '../../resources/user_config.js';
import ZoneId from '../../resources/zone_id.js';
const Options = {
Language: 'en',
};
// NOTE: do not add more fights to this data structure.
// These exist for testing pullcounter and for backwards compatibility
// with pullcounter keys. None of these were translated in the past,
// and so it's also not worth going back and adding these as there is
// no backwards compatibility issue for other languages.
const gBossFightTriggers = [
{
id: 'test',
zoneId: ZoneId.MiddleLaNoscea,
startRegex: /:You bow courteously to the striking dummy/,
countdownStarts: true,
preventAutoStart: true,
},
{
id: 'o1s',
zoneId: ZoneId.DeltascapeV10Savage,
},
{
id: 'o2s',
zoneId: ZoneId.DeltascapeV20Savage,
},
{
id: 'o3s',
zoneId: ZoneId.DeltascapeV30Savage,
},
{
id: 'o4s-exdeath',
zoneId: ZoneId.DeltascapeV40Savage,
startRegex: /:Exdeath uses Dualcast/,
preventAutoStart: true,
},
{
id: 'o4s-neo',
zoneId: ZoneId.DeltascapeV40Savage,
startRegex: /:Neo Exdeath uses Almagest/,
preventAutoStart: true,
},
{
id: 'Unending Coil',
zoneId: ZoneId.TheUnendingCoilOfBahamutUltimate,
},
{
id: 'Shinryu Ex',
zoneId: ZoneId.TheMinstrelsBalladShinryusDomain,
},
{
id: 'o5s',
zoneId: ZoneId.SigmascapeV10Savage,
},
{
id: 'o6s',
zoneId: ZoneId.SigmascapeV20Savage,
},
{
id: 'o7s',
zoneId: ZoneId.SigmascapeV30Savage,
},
{
id: 'o8s-kefka',
zoneId: ZoneId.SigmascapeV40Savage,
startRegex: / 15:........:Kefka:28C2:/,
preventAutoStart: true,
},
{
id: 'o8s-god kefka',
zoneId: ZoneId.SigmascapeV40Savage,
startRegex: / 15:........:Kefka:28EC:/,
preventAutoStart: true,
},
{
id: 'Byakko Ex',
zoneId: ZoneId.TheJadeStoaExtreme,
},
{
id: 'Tsukuyomi Ex',
zoneId: ZoneId.TheMinstrelsBalladTsukuyomisPain,
},
{
id: 'UwU',
zoneId: ZoneId.TheWeaponsRefrainUltimate,
},
{
id: 'Suzaku Ex',
zoneId: ZoneId.HellsKierExtreme,
},
{
id: 'Seiryu Ex',
zoneId: ZoneId.TheWreathOfSnakesExtreme,
},
{
id: 'o9s',
zoneId: ZoneId.AlphascapeV10Savage,
},
{
id: 'o10s',
zoneId: ZoneId.AlphascapeV20Savage,
},
{
id: 'o11s',
zoneId: ZoneId.AlphascapeV30Savage,
},
{
id: 'o12s-door',
zoneId: ZoneId.AlphascapeV40Savage,
startRegex: /:Omega-M:337D:/,
preventAutoStart: true,
},
{
id: 'o12s-final',
zoneId: ZoneId.AlphascapeV40Savage,
startRegex: /:Omega:336C:/,
preventAutoStart: true,
},
{
zoneId: ZoneId.TheBozjanSouthernFront,
countdownStarts: false,
preventAutoStart: true,
},
];
let gPullCounter;
class PullCounter {
constructor(element) {
this.element = element;
this.zoneName = null;
this.bossStarted = false;
this.party = [];
this.bosses = [];
this.resetRegex = Regexes.echo({ line: '.*pullcounter reset.*?' });
this.countdownEngageRegex = LocaleRegex.countdownEngage[Options.ParserLanguage] ||
LocaleRegex.countdownEngage['en'];
callOverlayHandler({
call: 'cactbotLoadData',
overlay: 'pullcounter',
}).then((data) => gPullCounter.SetSaveData(data));
this.ReloadTriggers();
}
OnFightStart(boss) {
this.pullCounts[boss.id] = (this.pullCounts[boss.id] || 0) + 1;
this.bossStarted = true;
this.ShowElementFor(boss.id);
this.SaveData();
}
ShowElementFor(id) {
this.element.innerText = this.pullCounts[id];
this.element.classList.remove('wipe');
}
SaveData() {
callOverlayHandler({
call: 'cactbotSaveData',
overlay: 'pullcounter',
data: JSON.stringify(this.pullCounts),
});
}
OnLogEvent(e) {
if (this.bossStarted)
return;
for (const log of e.detail.logs) {
if (this.resetRegex.test(log))
this.ResetPullCounter();
if (this.countdownEngageRegex.test(log)) {
if (this.countdownBoss)
this.OnFightStart(this.countdownBoss);
else
this.AutoStartBossIfNeeded();
return;
}
for (const boss of this.bosses) {
if (boss.startRegex && boss.startRegex.test(log)) {
this.OnFightStart(boss);
return;
}
}
}
}
OnChangeZone(e) {
this.element.innerText = '';
this.zoneName = e.zoneName;
this.zoneId = e.zoneID;
// Network log zone names that start with "the" are lowercase.
// Adjust this here to match saved pull counts for zones which
// do not have this property and originally used zone names
// coming from the ffxiv parser plugin.
// TODO: add some backwards compatible way to turn zone names into
// zone ids when we load that zone and a pull count exists?
// Proper-case zone names to match ACT.
this.zoneName = this.zoneName.split(' ').map((word) => {
if (!word || word.length === 0)
return '';
return word[0].toUpperCase() + word.substr(1);
}).join(' ');
this.ReloadTriggers();
}
ResetPullCounter() {
if (this.bosses.length > 0) {
for (const boss of this.bosses) {
const id = boss.id;
this.pullCounts[id] = 0;
console.log('resetting pull count of: ' + id);
this.ShowElementFor(id);
}
} else {
const id = this.zoneName;
console.log('resetting pull count of: ' + id);
this.ShowElementFor(id);
}
this.SaveData();
}
ReloadTriggers() {
this.bosses = [];
this.countdownBoss = null;
if (!this.zoneName || !this.pullCounts)
return;
for (const boss of gBossFightTriggers) {
if (this.zoneId !== boss.zoneId)
continue;
this.bosses.push(boss);
if (boss.countdownStarts) {
// Only one boss can be started with countdown in a zone.
if (this.countdownBoss)
console.error('Countdown boss conflict: ' + boss.id + ', ' + this.countdownBoss.id);
this.countdownBoss = boss;
}
}
}
OnInCombatChange(e) {
if (!e.detail.inGameCombat) {
this.bossStarted = false;
return;
}
this.AutoStartBossIfNeeded();
}
AutoStartBossIfNeeded() {
// Start an implicit boss fight for this zone in parties of 8 people
// unless there's a door fight that specifies otherwise.
if (this.bosses.length > 1)
return;
if (this.bossStarted)
return;
if (this.party.length !== 8)
return;
if (this.bosses.length === 1) {
const boss = this.bosses[0];
if (boss.preventAutoStart)
return;
this.OnFightStart(boss);
return;
}
this.OnFightStart({
id: this.zoneName,
countdownStarts: true,
});
}
OnPartyWipe() {
this.element.classList.add('wipe');
}
OnPartyChange(e) {
this.party = e.party;
}
SetSaveData(e) {
try {
if (e && e.data)
this.pullCounts = JSON.parse(e.data);
else
this.pullCounts = {};
} catch (err) {
console.error('onSendSaveData parse error: ' + err.message);
}
this.ReloadTriggers();
}
}
UserConfig.getUserConfigLocation('pullcounter', Options, () => {
gPullCounter = new PullCounter(document.getElementById('pullcounttext'));
addOverlayListener('onLogEvent', (e) => gPullCounter.OnLogEvent(e));
addOverlayListener('ChangeZone', (e) => gPullCounter.OnChangeZone(e));
addOverlayListener('onInCombatChangedEvent', (e) => gPullCounter.OnInCombatChange(e));
addOverlayListener('onPartyWipe', () => gPullCounter.OnPartyWipe());
addOverlayListener('PartyChanged', (e) => gPullCounter.OnPartyChange(e));
});