Repository navigation
Expand file tree
/
Copy pathparser.js
More file actions
642 lines (566 loc) · 33.8 KB
/
Copy pathparser.js
File metadata and controls
642 lines (566 loc) · 33.8 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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
// EQL Overlay - log parser + fight tracker
// Works in both Node (tests) and the Electron renderer.
// Line formats verified against a real EverQuest Legends log (Aug 2026).
(function (root, factory) {
if (typeof module === 'object' && module.exports) module.exports = factory();
else root.EQLParser = factory();
})(typeof self !== 'undefined' ? self : this, function () {
// ---------- timestamp ----------
const MONTHS = { Jan:0, Feb:1, Mar:2, Apr:3, May:4, Jun:5, Jul:6, Aug:7, Sep:8, Oct:9, Nov:10, Dec:11 };
const RE_TS = /^\[\w{3} (\w{3}) (\d{2}) (\d{2}):(\d{2}):(\d{2}) (\d{4})\] (.*)$/;
// ---------- combat lines ----------
const VERBS = '(?:hits?|slash(?:es)?|pierc(?:es|e)|crush(?:es)?|bash(?:es)?|kick(?:s)?|punch(?:es)?|backstab(?:s)?|bit(?:es|e)|claw(?:s)?|gor(?:es|e)|maul(?:s)?|reav(?:es|e)|cleav(?:es|e)|sting(?:s)?|strik(?:es|e)|shoot(?:s)?|smit(?:es|e)|smash(?:es)?|slic(?:es|e)|rend(?:s)?|frenz(?:ies|y)(?: on)?)';
// "You hit Drelzna for 222 points of magic damage by Spirit Tap." (Critical)
const RE_SPELL = new RegExp('^(.+?) hit (.+?) for (\\d+) points? of ([\\w-]+) damage by (.+?)\\.(?: \\((.+?)\\))?$');
// "You slash Drelzna for 49 points of damage." / "Drelzna pierces YOU for 28 points of damage." (Critical)
const RE_MELEE = new RegExp('^(.+?) ' + VERBS + ' (.+?) for (\\d+) points? of damage\\.(?: \\((.+?)\\))?$');
// "Drelzna has taken 22 damage from Tainted Breath by Gabn."
const RE_DOT = /^(.+?) has taken (\d+) damage from (.+?) by (.+?)\.(?: \((.+?)\))?$/;
// "A shin ghoul knight has taken 25 damage from your Heart Flutter."
const RE_DOT_YOURS = /^(.+?) has taken (\d+) damage from your (.+?)\.(?: \((.+?)\))?$/;
// "You have taken 15 damage from Blood Claw by Drelzna."
const RE_DOT_ON_YOU = /^You have taken (\d+) damage from (.+?) by (.+?)\.(?: \((.+?)\))?$/;
// "YOU are burned by a skeleton's flames for 7 points of non-melee damage!"
const RE_NONMELEE = /^(.+?) (?:is|are) \w+ by (.+?) for (\d+) points? of non-melee damage[.!]$/;
// "You healed Maeel for 222 hit points by Spirit Tap." / "... for 0 (20) hit points by Courage."
const RE_HEAL = /^(.+?) healed (.+?) for (\d+)(?: \((\d+)\))? hit points?(?: by (.+?))?\.$/;
// misses: "You try to reave Drelzna, but miss!" / "Drelzna tries to pierce YOU, but YOU parry!"
const RE_MISS = new RegExp('^(.+?) tr(?:ies|y) to ' + VERBS.replace('(?: on)?', '') + ' (.+?), but .+?[.!](?: \\((.+?)\\))?$');
const RE_SLAIN_BY_YOU = /^You have slain (.+?)!$/;
const RE_SLAIN = /^(.+?) ha(?:s|ve) been slain by (.+?)!$/;
const RE_YOU_SLAIN = /^You have been slain by (.+?)!$/;
// "You begin casting Spirit Tap." / "A dread skeleton begins casting Alacrity."
const RE_CAST = /^(.+?) begins? casting (.+?)\.$/;
// All corpse- and container-loot variants:
// "--You have looted a Lizard Tail from a lizard justicar's corpse.--" (kept)
// "--You have looted 2 Phosphorous Powder from a ghoul savant's corpse.--" (stack)
// "You looted a Bloodstained Key from Drelzna's corpse and sold it for 1 copper."
// "You looted a Necromancer Blood from a necromancer's corpse and stored it in your Dragon Hoard"
// "You looted a Stiletto of the Bloodclaw +4 from Drelzna's corpse to create ..."
// "You looted a Carmine Trinket +4 from Reward Chest and sold it for free." (container: no 's corpse)
const RE_LOOT = /^-{0,2}You (?:have )?looted (?:(\d+) )?(.+?) from (.+?)(?:'s corpse)?\.?(?:\s+(?:and sold it for (.+?)\.|and stored it\b.*|to create\b.*))?-{0,2}$/;
// "--You have looted a Rusty Sword.--" (no corpse name in line)
const RE_LOOT_SIMPLE = /^-{0,2}You (?:have )?looted (?:(\d+) )?(.+?)\.-{0,2}$/;
// "You receive 7 silver and 5 copper from the corpse."
const RE_COIN = /^You receive (.+?) from the corpse\.$/;
// "You received 3 platinum, 5 gold, 7 silver and 1 copper from that item." (destroying an item for coin)
const RE_COIN_ITEM = /^You received (.+?) from that item\.$/;
// "You receive 5 gold from Kanio Paerk for the Rusty Long Sword(1)." (vendor sale)
const RE_VENDOR = /^You receive (.+?) from (.+?) for the (.+?)\((\d+)\)\.$/;
// "You successfully destroyed 1 Pearl Necklace +1."
const RE_DESTROYED = /^You successfully destroyed (\d+) (.+?)\.$/;
// "Fright scowls at you, ready to attack -- looks like it would wipe the floor with you! (Lvl: 55)"
const RE_CONSIDER = /^(.+?) (?:scowls|glares|glowers|regards|looks|judges|scoffs|considers)\b.*\(Lvl: (\d+)\)[.!]?$/;
// Hit suffixes stack modifiers: "(Riposte Critical)", "(Critical Double Bow Shot)",
// "(Finishing Blow)"... Only the word Critical makes it a crit.
const isCrit = (mods) => !!mods && /\bCritical\b/.test(mods);
const COIN_VALUES = { platinum: 1000, gold: 100, silver: 10, copper: 1 };
function parseCoins(str) {
let total = 0, m;
const re = /(\d+) (platinum|gold|silver|copper)/g;
while ((m = re.exec(str))) total += +m[1] * COIN_VALUES[m[2]];
return total; // in copper
}
// "a Stiletto of the Bloodclaw +4" -> "Stiletto of the Bloodclaw"
const normItem = (n) => n.replace(/^(?:a|an|the) /i, '').replace(/ \+\d+$/, '');
const YOU = 'You';
const isYou = (n) => n === 'You' || n === 'YOU' || n === 'you';
// "yourself" (Cannibalization etc.) - self-inflicted, not an enemy
const isSelf = (n) => /^(?:your|him|her|it)self$/i.test(n);
// "a skeleton's flames" -> "a skeleton"
const stripPossessive = (n) => { const m = /^(.+?)'s .+$/.exec(n); return m ? m[1] : n; };
function parseLine(line) {
const ts = RE_TS.exec(line);
if (!ts) return null;
const when = new Date(+ts[6], MONTHS[ts[1]] ?? 0, +ts[2], +ts[3], +ts[4], +ts[5]).getTime();
const msg = ts[7];
let m;
if ((m = RE_SPELL.exec(msg))) {
// "You hit yourself for 80 points of unresistable damage by Cannibalization."
if (isSelf(m[2]))
return { type: 'selfdamage', when, attacker: isYou(m[1]) ? YOU : m[1],
amount: +m[3], spell: m[5], kind: 'spell' };
return { type: 'damage', when, attacker: isYou(m[1]) ? YOU : m[1], target: isYou(m[2]) ? YOU : m[2],
amount: +m[3], spell: m[5], crit: isCrit(m[6]), kind: 'spell' };
}
if ((m = RE_MELEE.exec(msg))) {
if (isSelf(m[2]))
return { type: 'selfdamage', when, attacker: isYou(m[1]) ? YOU : m[1],
amount: +m[3], kind: 'melee' };
return { type: 'damage', when, attacker: isYou(m[1]) ? YOU : m[1], target: isYou(m[2]) ? YOU : m[2],
amount: +m[3], crit: isCrit(m[4]), mods: m[4] || '', kind: 'melee' };
}
if ((m = RE_DOT_ON_YOU.exec(msg)))
return { type: 'damage', when, attacker: m[3], target: YOU, amount: +m[1], spell: m[2], crit: isCrit(m[4]), kind: 'dot' };
if ((m = RE_DOT_YOURS.exec(msg)))
return { type: 'damage', when, attacker: YOU, target: isYou(m[1]) ? YOU : m[1], amount: +m[2], spell: m[3], crit: isCrit(m[4]), kind: 'dot' };
if ((m = RE_DOT.exec(msg)))
return { type: 'damage', when, attacker: isYou(m[4]) ? YOU : m[4], target: isYou(m[1]) ? YOU : m[1],
amount: +m[2], spell: m[3], crit: isCrit(m[5]), kind: 'dot' };
// "A spiroc banisher has taken 188 damage by Drifting Death." (no caster named)
// "You have taken 188 damage by Drifting Death."
if ((m = /^(.+?) ha(?:s|ve) taken (\d+) damage by (.+?)\.(?: \((.+?)\))?$/.exec(msg)))
return { type: 'damage', when, attacker: '(unknown)', target: isYou(m[1]) ? YOU : m[1],
amount: +m[2], spell: m[3], crit: isCrit(m[4]), kind: 'dot' };
// unnamed damage on you: "You were hit by non-melee for 52 damage." (counts as taken + death recap)
if ((m = /^You were hit by non-melee for (\d+) damage\.$/.exec(msg)))
return { type: 'damage', when, attacker: '(unknown)', target: YOU, amount: +m[1], spell: 'non-melee', kind: 'spell' };
if ((m = RE_NONMELEE.exec(msg))) {
// "... burned by YOUR flames ..." = your damage shield;
// "... pierced by a ghoul knight's thorns ..." = someone else's
const src = m[2];
const attacker = /^YOUR\b/i.test(src) ? YOU : stripPossessive(src);
return { type: 'damage', when, attacker, target: isYou(m[1]) ? YOU : m[1],
amount: +m[3], kind: 'proc' };
}
if ((m = RE_HEAL.exec(msg)))
return { type: 'heal', when, healer: isYou(m[1]) ? YOU : m[1], target: isYou(m[2]) ? YOU : m[2],
amount: +m[3], potential: m[4] ? +m[4] : +m[3], spell: m[5] };
// "The Nektropos Library Key has been added to your key ring."
if ((m = /^(?:The )?(.+?) has been added to your key ring\.$/.exec(msg)))
return { type: 'keyring', when, item: m[1] };
// "You have completed achievement: Be Our Guest"
if ((m = /^You have completed achievement: (.+?)\.?$/.exec(msg)))
return { type: 'achievement', when, name: m[1] };
if ((m = RE_MISS.exec(msg)))
return { type: 'miss', when, attacker: isYou(m[1]) ? YOU : m[1], target: isYou(m[2]) ? YOU : m[2] };
// XP: Legends prints the percent of the CURRENT level's bar each kill
// gave you — "You gain experience! (3.288%)". At the level cap there is
// no bar, so the line prints with no percent. Party = a groupmate's kill.
if ((m = /^You gain (party )?experience!*\s*(?:\((\d+(?:\.\d+)?)%\))?$/.exec(msg)))
return { type: 'exp', when, party: !!m[1], pct: m[2] !== undefined ? +m[2] : undefined };
if ((m = /^You have gained a level! Welcome to level (\d+)!$/.exec(msg)))
return { type: 'levelup', when, level: +m[1] };
// "You have gained 2 ability points! You now have 145 ability points."
// the real lines (EQ Legends): "You have gained an ability point! You now have 145 ability points."
// and "You have gained 2 ability point(s)! You now have 147 ability point(s)." (two spaces)
if ((m = /^You have gained (an|\d+) ability point(?:s|\(s\))?!\s+You now have (\d+) ability point(?:s|\(s\))?[.!]?$/.exec(msg)))
return { type: 'aa', when, gained: m[1] === 'an' ? 1 : +m[1], total: +m[2] };
// death recap: going down. "knocked unconscious" comes first, then either
// "You have been slain by X!" or (a DoT/no-killer death) "You died."
if (msg === 'You have been knocked unconscious!') return { type: 'ko', when };
if (msg === 'You died.') return { type: 'death', when, target: YOU, killer: null };
// stances (EQ Legends): "You assume a striker stance." / "an evasive stance"
if ((m = /^You assume an? (.+?) stance\.$/.exec(msg))) return { type: 'stance', when, stance: m[1] };
if ((m = RE_SLAIN_BY_YOU.exec(msg)))
return { type: 'death', when, target: m[1], killer: YOU };
if ((m = RE_YOU_SLAIN.exec(msg)))
return { type: 'death', when, target: YOU, killer: m[1] };
if ((m = RE_SLAIN.exec(msg)))
return { type: 'death', when, target: m[1], killer: m[2] };
if ((m = RE_CAST.exec(msg)))
return { type: 'cast', when, caster: isYou(m[1]) ? YOU : m[1], spell: m[2] };
// casts that fail: these cancel manual spell timers
if ((m = /^Your (.+?) spell is interrupted\.$/.exec(msg)))
return { type: 'castfail', when, spell: m[1], reason: 'interrupted' };
if ((m = /^(.+?) resisted your (.+?)!$/.exec(msg)))
return { type: 'castfail', when, spell: m[2], reason: 'resisted', target: m[1] };
if ((m = /^Your (.+?) spell did not take hold\./.exec(msg)))
return { type: 'castfail', when, spell: m[1], reason: 'did not take hold' };
if (/^Your spell fizzles!$/.test(msg))
return { type: 'castfail', when, spell: null, reason: 'fizzled' };
// AE mez lands one line PER TARGET: "a spiroc expulser has been mesmerized."
if ((m = /^(.+?) has been mesmerized\.$/.exec(msg)))
return { type: 'mezzed', when, target: m[1] };
// mez broken by damage: "A spiroc expulser has been awakened by Maeel."
if ((m = /^(.+?) has been awakened by (.+?)\.$/.exec(msg)))
return { type: 'awakened', when, target: m[1], by: m[2] };
// charm landing: "a spiroc banisher has been charmed."
if ((m = /^(.+?) has been charmed\.$/.exec(msg)))
return { type: 'charmed', when, target: m[1] };
// "Your Cajoling Whispers spell has worn off of a zol ghoul knight."
if ((m = /^Your (.+?) spell has worn off of (.+?)\.$/.exec(msg)))
return { type: 'wornoff', when, spell: m[1], target: m[2] };
// "Your pet's Inner Fire spell has worn off."
if ((m = /^Your pet's (.+?) spell has worn off\.$/.exec(msg)))
return { type: 'wornoffpet', when, spell: m[1] };
// "Your Invisibility spell has worn off." (self-buff, no target)
if ((m = /^Your (.+?) spell has worn off\.$/.exec(msg)))
return { type: 'wornoffself', when, spell: m[1] };
// invisibility ending: warning first, then the drop
if (/^You feel yourself starting to appear\.$/.test(msg))
return { type: 'invisfade', when };
if (/^You appear\.$/.test(msg))
return { type: 'invisdrop', when };
// EQ Legends uses a uniform fade format for effects ending on you:
// "The cool breeze fades." / "Your strength fades." / "The spirit of the puma departs."
if ((m = /^(?:The|Your) (.+) (fades|departs)\.$/.exec(msg)))
return { type: 'bufffade', when, effect: m[1], verb: m[2] };
if ((m = RE_LOOT.exec(msg)))
// sold = the loot filter auto-sold it ("and sold it for 3 silver." /
// "and sold it for free."): never in your bags, nothing to vendor.
// Kept separate from soldFor because "free" is a sale worth 0 coin.
return { type: 'loot', when, item: normItem(m[2]), rawItem: m[2], mob: m[3],
count: m[1] ? +m[1] : 1, sold: !!m[4], soldFor: m[4] ? parseCoins(m[4]) : 0 };
if ((m = RE_LOOT_SIMPLE.exec(msg)))
return { type: 'loot', when, item: normItem(m[2]), rawItem: m[2], mob: null,
count: m[1] ? +m[1] : 1, sold: false, soldFor: 0 };
if ((m = RE_COIN.exec(msg)))
return { type: 'coin', when, copper: parseCoins(m[1]) };
if ((m = RE_COIN_ITEM.exec(msg)))
return { type: 'coin', when, copper: parseCoins(m[1]), fromItem: true };
if ((m = RE_VENDOR.exec(msg)))
return { type: 'vendored', when, copper: parseCoins(m[1]), vendor: m[2],
item: normItem(m[3]), count: +m[4] };
if ((m = RE_DESTROYED.exec(msg)))
return { type: 'destroyed', when, count: +m[1], item: normItem(m[2]) };
if ((m = RE_CONSIDER.exec(msg))) {
// "Tormentor Utzain - a rare creature - scowls at you, ready to attack --
// looks like he would wipe the floor with you! (Lvl: 54)"
let mob = m[1], rare = false;
const rm = /^(.+?) - a rare creature -$/.exec(mob);
if (rm) { mob = rm[1]; rare = true; }
const body = msg.slice(m[1].length + 1).replace(/\s*\(Lvl: \d+\)[.!]?$/, '');
const cut = body.indexOf(' -- ');
let attitude = (cut >= 0 ? body.slice(0, cut) : body).trim();
let difficulty = cut >= 0 ? body.slice(cut + 4).trim() : '';
if (!difficulty && /^looks like /i.test(attitude)) { difficulty = attitude; attitude = ''; }
return { type: 'consider', when, mob, level: +m[2], rare, attitude, difficulty,
aggro: /ready to attack|threateningly|scowls/i.test(attitude) };
}
if (/^You cannot loot this item no room in your inventory\.$/.test(msg))
return { type: 'lootfull', when };
// pet speech addresses you as Master - covers summoned AND charmed pets:
// "Xonektik says, 'Sorry, Master... calming down.'"
// "A wan ghoul knight told you, 'Attacking a ghoul savant Master.'"
if ((m = /^(.+?) (says|tells you|told you),? '(?:Attacking .+ [Mm]aster|At your service|Sorry,? [Mm]aster|I am unable to wake|Following you|Guarding with my life|As you wish|Changing position|Waiting here|I live again|Consider it done|It will be done|By your command)[^']*'\.?$/.exec(msg)))
// direct = a tell to YOU (only your own pet does that); "says" is heard by everyone nearby
return { type: 'petsay', when, name: m[1], direct: m[2] !== 'says' };
if ((m = /^You have entered (.+?)\.$/.exec(msg)) && !/^an area\b|^the Arena\b/i.test(m[1])) {
// "Temple of Cazic-Thule 4 (Refined)": the number is an instance id
// (discard), the parenthetical is the DIFFICULTY tier (keep separately)
const vm = /\(([^)]+)\)\s*$/.exec(m[1]);
let variant = vm ? vm[1].trim() : '';
const noParen = m[1].replace(/\s*\([^)]*\)\s*$/, '');
const hadId = /\s+\d+\s*$/.test(noParen); // "Temple of Cazic-Thule 4" = instance id
let zone = noParen.replace(/\s+\d+\s*$/, '').trim();
// instance-mode suffix: "The Plane of Fear - Solo". Only known mode
// words strip - real dash names like "Neriak - Commons" stay intact.
const mm = /\s+-\s+(Solo|Duo|Trio|Group|Raid|Party|Heroic|Event)$/i.exec(zone);
if (mm) {
variant = variant ? variant + ', ' + mm[1] : mm[1];
zone = zone.slice(0, mm.index).trim();
}
// instance id, difficulty tier or mode suffix = an instanced copy
return { type: 'zone', when, zone, variant, inst: !!(hadId || variant) };
}
// "Your Location is -168.90, -240.49, 3.75" (north-south, east-west, elevation)
if ((m = /^Your Location is (-?[\d.]+), (-?[\d.]+), (-?[\d.]+)/.exec(msg)))
return { type: 'loc', when, ns: +m[1], ew: +m[2], z: +m[3] };
// /who output includes the zone's short name:
// "[50 SHD/DRU/BRD] Maeel (Dark Elf) <Guild> ZONE: The Feerrott (feerrott)"
// "... ZONE: Nagafen's Lair 1160 (soldungb_1160)" (instanced)
// The player name matters: YOUR OWN row is also the only reliable zone
// signal when a zone logs no entry line (the planes) or the log was
// cleared mid-session — a plain /who row for yourself says where you are.
if ((m = /ZONE: (.+?)(?: \d+)? \(([a-z0-9]+?)(?:_(\d+))?\)/i.exec(msg))) {
// the level/trio bracket: "[50 SHD/DRU/BRD] Maeel (Dark Elf) ..."
const pm = /^\[\s*(\d+)?\s*([A-Z]{3}(?:\/[A-Z]{3}){0,2})?[^\]]*\]\s+(\w+)/.exec(msg);
return { type: 'zonemap', when, longName: m[1].trim(), shortName: m[2].toLowerCase(),
inst: !!m[3], player: pm ? pm[3] : null,
level: pm && pm[1] ? +pm[1] : null,
trio: pm && pm[2] ? pm[2].split('/') : null };
}
// progress: "You have become better at Fishing! (11)"
if ((m = /^You have become better at (.+?)! \((\d+)\)$/.exec(msg)))
return { type: 'skillup', when, skill: m[1], value: +m[2] };
// "Your faction standing with Host of Nektropos has been adjusted by -2."
// "... could not possibly get any better." / "... any worse."
if ((m = /^Your faction standing with (.+?) has been adjusted by (-?\d+)\.$/.exec(msg)))
return { type: 'faction', when, faction: m[1], delta: +m[2] };
if ((m = /^Your faction standing with (.+?) could not possibly get any (better|worse)\.$/.exec(msg)))
return { type: 'faction', when, faction: m[1], delta: 0, capped: m[2] };
// chat (v2.6 history): tells, group, guild, raid, says, shouts, OOC, auction, channels
if ((m = /^(.+?) tells you, '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: 'tell', from: m[1], text: m[2] };
if ((m = /^You told (.+?), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: 'tell', from: YOU, to: m[1], text: m[2] };
if ((m = /^(.+?) tells the (group|guild|raid), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: m[2], from: m[1], text: m[3] };
if ((m = /^You tell (?:your|the) (party|group|guild|raid), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: m[1] === 'party' ? 'group' : m[1], from: YOU, text: m[2] };
if ((m = /^You say to your guild, '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: 'guild', from: YOU, text: m[1] };
if ((m = /^(.+?) tells ([A-Za-z][A-Za-z0-9]*):(\d+), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: 'chan', chan: m[2] + ':' + m[3], from: isYou(m[1]) ? YOU : m[1], text: m[4] };
if ((m = /^You tell ([A-Za-z][A-Za-z0-9]*):(\d+), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: 'chan', chan: m[1] + ':' + m[2], from: YOU, text: m[3] };
if ((m = /^(.+?) (says|shouts|auctions), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: m[2] === 'says' ? 'say' : m[2] === 'shouts' ? 'shout' : 'auction', from: m[1], text: m[3] };
if ((m = /^(.+?) says out of character, '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: 'ooc', from: m[1], text: m[2] };
if ((m = /^You (say|shout|auction), '([\s\S]*)'$/.exec(msg)))
return { type: 'chat', when, channel: m[1] === 'say' ? 'say' : m[1] === 'shout' ? 'shout' : 'auction', from: YOU, text: m[2] };
return null;
}
// ------------------------------------------------------------------
// FightTracker: groups events into fights separated by idle gaps.
// ------------------------------------------------------------------
const FIGHT_GAP_MS = 8000;
// Normalize NPC article capitalization: "A necromancer" === "a necromancer"
const normName = (n) => n.replace(/^(A|An|The) /, (m) => m.toLowerCase());
function newFight(when) {
return {
start: when, lastCombat: when,
events: [], // damage events (attacker, target, amount, crit)
misses: new Map(), // attacker -> miss count (vs non-you targets)
missesOn: new Map(), // attacker + '\u0001' + target -> misses on that mob (meter target filter)
healingBy: new Map(), // name -> actual healing
enemies: new Set(), // entities you attacked or that attacked you
kills: []
};
}
const CAST_WINDOW_MS = 15000; // spell damage within 15s of its cast = cast, not proc
class FightTracker {
constructor() {
this.current = null;
this.last = null;
this.lastFeedWallclock = 0;
this.casts = new Map(); // "caster|spell" -> last cast timestamp
this.history = []; // ended fights, newest first (fight history view)
}
_isProc(ev) {
if (ev.kind !== 'spell' || !ev.spell) return false;
const t = this.casts.get(ev.attacker + '|' + ev.spell);
return !(t && ev.when - t <= CAST_WINDOW_MS);
}
_maybeEnd(when) {
if (this.current && when - this.current.lastCombat > FIGHT_GAP_MS) this.end();
}
end() {
if (!this.current) return;
const hadEvents = this.current.events.length > 0;
if (hadEvents) {
this.last = this.current;
this.history.unshift(this.current);
if (this.history.length > 25) this.history.length = 25;
}
this.current = null;
if (hadEvents && this.onFightEnd) this.onFightEnd(this.summary());
}
feed(line) {
const ev = typeof line === 'string' ? parseLine(line) : line;
if (!ev) return null;
if (ev.type === 'damage') {
this._maybeEnd(ev.when);
let attacker = ev.attacker === YOU ? YOU : normName(ev.attacker);
const target = ev.target === YOU ? YOU : normName(ev.target);
// another player's charmed mob (2.7, charms.js): its damage is THAT player's
let petOf = null;
if (attacker !== YOU && this.petOwners && this.petOwners.has(attacker) && !(this.petNames && this.petNames.has(attacker))) {
petOf = attacker; attacker = this.petOwners.get(attacker);
}
// Bystander filter: other groups fighting nearby must not start
// fights for you or stretch your fight's clock. Combat matters only
// when it involves You, your pet, or a mob already in this fight.
const mine = attacker === YOU || target === YOU ||
!!(this.petNames && (this.petNames.has(attacker) || this.petNames.has(target)));
const inFight = !!this.current &&
(this.current.enemies.has(attacker) || this.current.enemies.has(target));
if (!mine && !inFight) return ev;
if (!this.current) this.current = newFight(ev.when);
const f = this.current;
f.lastCombat = ev.when;
this.lastFeedWallclock = Date.now();
const proc = this._isProc(ev);
const source = petOf ? 'Pet: ' + petOf :
ev.kind === 'melee' ? 'Melee' :
ev.kind === 'proc' ? 'Damage Shield' :
(ev.spell || 'Unknown');
f.events.push({ t: ev.when, attacker, target, amount: ev.amount, crit: !!ev.crit,
source, kind: ev.kind, proc,
pet: !!(this.petNames && this.petNames.has(attacker)) });
// build the enemy set: whoever you attack, or attacks you, is an enemy
if (attacker === YOU) f.enemies.add(target);
if (target === YOU && attacker !== '(unknown)') f.enemies.add(attacker);
} else if (ev.type === 'selfdamage') {
// Cannibalization etc. - never starts a fight, never an enemy.
// If a fight is live, count it as damage you took (helps healing math).
if (this.current && ev.attacker === YOU)
this.current.events.push({ attacker: YOU, target: YOU, amount: ev.amount,
crit: false, source: ev.spell || 'Self', kind: ev.kind, proc: false });
} else if (ev.type === 'heal' && this.current) {
const healer = ev.healer === YOU ? YOU : normName(ev.healer);
this.current.healingBy.set(healer, (this.current.healingBy.get(healer) || 0) + ev.amount);
} else if (ev.type === 'miss' && this.current && ev.target !== YOU) {
let attacker = ev.attacker === YOU ? YOU : normName(ev.attacker);
if (attacker !== YOU && this.petOwners && this.petOwners.has(attacker) && !(this.petNames && this.petNames.has(attacker))) attacker = this.petOwners.get(attacker);
const target = normName(ev.target);
// same bystander rule: only swings at this fight's mobs count
if (attacker === YOU || (this.petNames && this.petNames.has(attacker)) ||
this.current.enemies.has(target))
{
this.current.misses.set(attacker, (this.current.misses.get(attacker) || 0) + 1);
const mk = attacker + '\u0001' + target, mo = this.current.missesOn;
if (mo) mo.set(mk, (mo.get(mk) || 0) + 1);
}
} else if (ev.type === 'death' && this.current) {
this.current.kills.push(ev.target);
} else if (ev.type === 'cast') {
const caster = ev.caster === YOU ? YOU : normName(ev.caster);
this.casts.set(caster + '|' + ev.spell, ev.when);
if (this.casts.size > 500) { // prune oldest
const cutoff = ev.when - CAST_WINDOW_MS * 4;
for (const [k, t] of this.casts) if (t < cutoff) this.casts.delete(k);
}
}
return ev;
}
// wall-clock check: ends a live fight when the log goes quiet
tick() {
if (this.current && this.lastFeedWallclock && Date.now() - this.lastFeedWallclock > FIGHT_GAP_MS) this.end();
}
// How long a mob took to kill (2.7): seconds from the first hit your side
// landed on it in this fight to `when` (its death). null when unknown.
// the other players who hit an enemy in the current/last fight (not you,
// not pets, not mobs): empty = you killed it solo (2.7 kill records)
othersInFight() {
const f = this.current || this.last;
if (!f) return [];
const s = new Set();
for (const e of f.events) {
if (e.attacker === YOU || e.pet || f.enemies.has(e.attacker) || !f.enemies.has(e.target)) continue;
if (/^[A-Z][a-z]+$/.test(e.attacker)) s.add(e.attacker);
}
return [...s];
}
engagedSecs(target, when) {
const f = this.current || this.last;
if (!f || !target) return null;
const t = normName(target);
for (const e of f.events) {
if (e.target !== t || e.target === YOU) continue;
if (f.enemies.has(e.attacker) && e.attacker !== YOU && !e.pet) continue;
const s = Math.round((when - e.t) / 1000);
return s >= 0 && s <= 3600 ? s : null;
}
return null;
}
// Per-source damage for ANY attacker in the current/last fight
// (powers the click-to-expand rows on the meter).
attackerSources(name, fx, target) {
const f = fx || this.current || this.last;
if (!f) return [];
const bySource = new Map();
for (const e of f.events) {
if (e.attacker !== name || e.target === YOU || !f.enemies.has(e.target)) continue;
if (target && e.target !== target) continue; // one mob only (meter target filter)
let s = bySource.get(e.source);
if (!s) bySource.set(e.source, s = { source: e.source, total: 0, count: 0, crits: 0, max: 0 });
s.total += e.amount;
s.count += 1;
if (e.crit) s.crits += 1;
if (e.amount > s.max) s.max = e.amount;
}
const rows = [...bySource.values()].sort((a, b) => b.total - a.total);
const grand = rows.reduce((s, r) => s + r.total, 0) || 1;
for (const r of rows) { r.pct = r.total / grand; r.avg = r.total / r.count; }
return rows;
}
// summary of the live/last fight, or of an older one from this.history.
// target (2.7): only damage dealt to that one mob — rates over the time it was
// being fought, so "who did what to Lord Rikantus vs the golems" in one fight
summary(fx, target) {
const f = fx || this.current || this.last;
if (!f) return null;
const live = !fx && !!this.current;
// every mob hit in this fight, biggest first (always the whole fight)
const allTargets = new Map();
for (const e of f.events) {
if (e.target === YOU || !f.enemies.has(e.target)) continue;
if (f.enemies.has(e.attacker) && e.attacker !== YOU && !e.pet) continue;
const t = allTargets.get(e.target) || { name: e.target, total: 0, first: e.t, last: e.t };
t.total += e.amount;
if (e.t < t.first) t.first = e.t;
if (e.t > t.last) t.last = e.t;
allTargets.set(e.target, t);
}
const tgGrand = [...allTargets.values()].reduce((a, t) => a + t.total, 0) || 1;
const targetList = [...allTargets.values()].sort((a, b) => b.total - a.total)
.map(t => ({ name: t.name, total: t.total, pct: t.total / tgGrand }));
const only = target && allTargets.has(target) ? target : null;
const missesOf = (name) => only
? ((f.missesOn && f.missesOn.get(name + '\u0001' + only)) || 0)
: (f.misses.get(name) || 0);
const onlyT = only ? allTargets.get(only) : null;
const durS = onlyT && onlyT.first && onlyT.last
? Math.max(1, (onlyT.last - onlyT.first) / 1000)
: Math.max(1, (f.lastCombat - f.start) / 1000);
// Meter rows: only damage dealt TO enemies (excludes enemy hits on allies).
const byAttacker = new Map();
const byTarget = new Map();
let youTaken = 0;
for (const e of f.events) {
if (e.target === YOU) { if (!only || e.attacker === only) youTaken += e.amount; continue; }
if (!f.enemies.has(e.target)) continue; // ally took a hit - not meter damage
if (only && e.target !== only) continue;
// enemy-on-enemy noise - EXCEPT damage flagged as pet's when it happened
if (f.enemies.has(e.attacker) && e.attacker !== YOU && !e.pet) continue;
let a = byAttacker.get(e.attacker);
if (!a) byAttacker.set(e.attacker, a = { total: 0, maxHit: 0, crits: 0, hits: 0 });
a.total += e.amount;
a.hits += 1;
if (e.amount > a.maxHit) a.maxHit = e.amount;
if (e.crit) a.crits += 1;
byTarget.set(e.target, (byTarget.get(e.target) || 0) + e.amount);
}
const rows = [...byAttacker.entries()]
.map(([name, a]) => ({
name, total: a.total, dps: a.total / durS, maxHit: a.maxHit,
crits: a.crits, hits: a.hits, misses: missesOf(name)
}))
.sort((x, y) => y.total - x.total);
const grand = rows.reduce((s, r) => s + r.total, 0) || 1;
rows.forEach(r => r.pct = r.total / grand);
const targets = [...byTarget.entries()].sort((x, y) => y[1] - x[1]).map(t => t[0]);
const you = rows.find(r => r.name === YOU) || { total: 0, dps: 0, maxHit: 0, crits: 0, hits: 0, misses: 0 };
// Your damage by source (spell/melee/proc breakdown)
const bySource = new Map();
let youSwings = missesOf(YOU); // melee swings = melee hits + misses
for (const e of f.events) {
if (e.attacker !== YOU || e.target === YOU || !f.enemies.has(e.target)) continue;
if (only && e.target !== only) continue;
if (e.kind === 'melee') youSwings += 1;
let s = bySource.get(e.source);
if (!s) bySource.set(e.source, s = { source: e.source, total: 0, count: 0, crits: 0, max: 0, proc: !!e.proc });
s.total += e.amount;
s.count += 1;
if (e.crit) s.crits += 1;
if (e.amount > s.max) s.max = e.amount;
if (!e.proc) s.proc = false; // any cast-confirmed use un-flags proc
}
const youBySource = [...bySource.values()].sort((a, b) => b.total - a.total);
const youGrand = youBySource.reduce((s, r) => s + r.total, 0) || 1;
for (const r of youBySource) {
r.pct = r.total / youGrand;
r.avg = r.total / r.count;
if (r.proc && youSwings > 0) r.procRate = r.count / youSwings;
}
// pet damage aggregated from events flagged at the time they happened
// (immune to charms breaking/dying before the fight ends)
const petAgg = new Map();
for (const e of f.events) {
if (!e.pet || e.target === YOU || !f.enemies.has(e.target)) continue;
if (only && e.target !== only) continue;
let p = petAgg.get(e.attacker);
if (!p) petAgg.set(e.attacker, p = { name: e.attacker, total: 0, hits: 0, crits: 0, maxHit: 0 });
p.total += e.amount; p.hits += 1;
if (e.crit) p.crits += 1;
if (e.amount > p.maxHit) p.maxHit = e.amount;
}
const petRows = [...petAgg.values()].sort((a, b) => b.total - a.total);
return {
petRows, youBySource, youSwings,
live, durS,
title: only || (targets.length ? targets[0] + (targets.length > 1 ? ` +${targets.length - 1}` : '') : '—'),
target: only, targets: targetList,
rows, you,
youTaken,
youHealed: f.healingBy.get(YOU) || 0,
kills: f.kills.length,
start: f.start, end: f.lastCombat
};
}
}
return { parseLine, FightTracker, YOU };
});