-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEarlyPull.lua
More file actions
803 lines (710 loc) · 26.1 KB
/
EarlyPull.lua
File metadata and controls
803 lines (710 loc) · 26.1 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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
local _, addon = ...
local L = addon.L
local GetSpellLink = C_Spell.GetSpellLink
-- Adapted/copied from Early Pull weakaura (https://wago.io/TyN8l9eWg/1)
local EARLY_PULL_PREFIX = 'earlyPullSync'
local sourceFlagMask = COMBATLOG_OBJECT_CONTROL_MASK
local sourceFlagFilter = COMBATLOG_OBJECT_CONTROL_PLAYER
local destFlagMask = bit.bor(COMBATLOG_OBJECT_CONTROL_MASK, COMBATLOG_OBJECT_REACTION_MASK)
local destFlagFilter1 = bit.bor(COMBATLOG_OBJECT_CONTROL_NPC, COMBATLOG_OBJECT_REACTION_HOSTILE)
local destFlagFilter2 = bit.bor(COMBATLOG_OBJECT_CONTROL_NPC, COMBATLOG_OBJECT_REACTION_NEUTRAL)
local negInfinity = -math.huge
local expectedPullTime = nil
local combatLog = {pos = 0, maxPos = 1000}
local threatLog = {pos = 0, maxPos = 100}
local targetLog = {pos = 0, maxPos = 100}
local bossLog = {pos = 0, maxPos = 100}
local syncLog = {pos = 0, maxPos = 100}
local pullContext = {}
local unitList = {}
local threatScanUnits = {}
local combatLogDamageEventTest, combatLogSwingEventTest, summons, summons2
local function init()
for i = 1, combatLog.maxPos do
combatLog[i] = {time = negInfinity, guid = nil, name = nil, event = nil, destGUID = nil, destName = nil, spellID = nil}
end
for i = 1, threatLog.maxPos do
threatLog[i] = {time = negInfinity, threatEntries = {count = 0}}
end
for i = 1, targetLog.maxPos do
targetLog[i] = {time = negInfinity, guid = nil, name = nil}
end
for i = 1, bossLog.maxPos do
bossLog[i] = {time = negInfinity, guid = nil}
end
for i = 1, syncLog.maxPos do
syncLog[i] = {time = negInfinity, message = nil}
end
unitList = {
raid = {},
raidpet = {},
party = {},
partypet = {},
boss = {},
bosstarget = {}
}
for i = 1, 40 do
unitList.raid[i] = 'raid'..i
unitList.raidpet[i] = 'raidpet'..i
end
for i = 1, 4 do
unitList.party[i] = 'party'..i
unitList.partypet[i] = 'partypet'..i
end
for i = 1, 5 do
unitList.boss[i] = 'boss'..i
unitList.bosstarget[i] = 'boss'..i..'target'
end
combatLogDamageEventTest = {
SPELL_DAMAGE = true,
SPELL_PERIODIC_DAMAGE = true,
SWING_DAMAGE = true,
RANGE_DAMAGE = true,
}
combatLogSwingEventTest = {
SWING_DAMAGE = true,
SWING_MISSED = true,
}
summons = {counter = 0}
summons2 = {counter = 0}
end
local function getAnnounceChannel(announceType)
if announceType == 1 then
return (addon.InInstance and not UnitIsDeadOrGhost('player')) and 'SAY' or 'PRINT'
elseif announceType == 2 then
return addon.GetInstanceChannel() or 'PRINT'
elseif announceType == 3 then
return 'OFFICER'
elseif announceType == 4 then
return 'PRINT'
end
end
local function classifyPull(pullTimeDiff)
local aType, pullDesc
if not pullTimeDiff then
aType = AstralRaidSettings.earlypull.announce.untimedPull
pullDesc = L['BOSS_PULLED']
elseif pullTimeDiff <= -0.005 then
aType = AstralRaidSettings.earlypull.announce.earlyPull
pullDesc = format(L['BOSS_PULLED_EARLY'], -pullTimeDiff)
elseif pullTimeDiff < 0.005 then
aType = AstralRaidSettings.earlypull.announce.onTimePull
pullDesc = L['BOSS_PULLED_ON_TIME']
else
aType = AstralRaidSettings.earlypull.announce.latePull
pullDesc = format(L['BOSS_PULLED_LATE'], pullTimeDiff)
end
return getAnnounceChannel(aType), pullDesc
end
local function maySendPullTimer(sender)
return UnitIsGroupLeader(sender) or UnitIsGroupAssistant(sender) or ((addon.InInstance) and UnitGroupRolesAssigned(sender) == 'TANK') or addon.IsOfficer()
end
local function advanceLog(log)
local pos = (log.pos % log.maxPos) + 1
log.pos = pos
return log[pos]
end
local function addThreatScanUnit(unit)
local guid = UnitGUID(unit)
if guid then
threatScanUnits[guid] = unit
end
end
local function scanThreat(mob)
wipe(threatScanUnits)
if IsInRaid() then
local raid = unitList.raid
local raidpet = unitList.raidpet
for i = 1, GetNumGroupMembers() do
addThreatScanUnit(raid[i])
addThreatScanUnit(raidpet[i])
end
else
if IsInGroup() then
local party = unitList.party
local partypet = unitList.partypet
for i = 1, GetNumSubgroupMembers() do
addThreatScanUnit(party[i])
addThreatScanUnit(partypet[i])
end
end
addThreatScanUnit('player')
addThreatScanUnit('pet')
end
addThreatScanUnit('target')
addThreatScanUnit('focus')
addThreatScanUnit('mouseover')
local entry = advanceLog(threatLog)
entry.time = GetTime()
local threatEntries = entry.threatEntries
local count = 0
for guid, unit in pairs(threatScanUnits) do
if UnitPlayerControlled(unit) then
local isTanking, state, scaledPercent, rawPercent, threatValue = UnitDetailedThreatSituation(unit, mob)
if state or threatValue then
count = count + 1
local threatEntry = threatEntries[count] or {}
threatEntries[count] = threatEntry
threatEntry.guid = guid
threatEntry.name = GetUnitName(unit, true)
threatEntry.isTanking = isTanking
threatEntry.threatValue = threatValue
end
end
end
threatEntries.count = count
end
local function scanBoss(unit, targetUnit)
local bossGUID = UnitGUID(unit)
if bossGUID then
local now = GetTime()
local bossEntry = advanceLog(bossLog)
bossEntry.time = now
bossEntry.guid = bossGUID
local targetGUID = UnitGUID(targetUnit)
if targetGUID and UnitPlayerControlled(targetUnit) then
local targetEntry = advanceLog(targetLog)
targetEntry.time = now
targetEntry.guid = targetGUID
targetEntry.name = GetUnitName(targetUnit, true)
end
end
end
local function scanAllBosses()
local boss, bossTarget = unitList.boss, unitList.bosstarget
for i = 1, 5 do
scanBoss(boss[i], bossTarget[i])
end
end
local function createSyncTable(encounterID)
return {addon.CLIENT_VERSION, encounterID, addon.GetGroupRank(), UnitName('player'), GetRealmName()}
end
local function deserializeSyncTable(d)
d = d:gsub(EARLY_PULL_PREFIX .. ' ', '')
local syncTable = {strsplit('\t', d)}
for i = 1, 5 do
if i == 2 or i == 3 then
syncTable[i] = tonumber(syncTable[i])
end
syncTable[i] = syncTable[i] or ''
end
return syncTable
end
local function compareSyncTables(a, b)
if a[3] < b[3] then return true elseif a[3] > b[3] then return false end
if a[4] > b[4] then return true elseif a[4] < b[4] then return false end
if a[5] > b[5] then return true elseif a[5] < b[5] then return false end
if a[1] < b[1] then return true elseif a[1] > b[1] then return false end
end
local function isMe(syncTable)
return syncTable[4] == UnitName('player') and syncTable[5] == GetRealmName()
end
local function sendSync(syncTable)
local channel = addon.GetInstanceChannel()
if not channel then return end
local msg = table.concat(syncTable, '\t')
AstralRaidComms:NewMessage(AstralRaidComms.PREFIX, EARLY_PULL_PREFIX .. ' ' .. msg, channel)
end
local function onSync(channel, msg, sender)
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
addon.PrintDebug(msg)
local entry = advanceLog(syncLog)
entry.time = GetTime()
entry.message = msg
end
-- relPos = pos shifted to be time-monotonic and 0-indexed
-- relPos = (pos - 1 - offset) % maxPos
-- pos = 1 + (relPos + offset) % maxPos
-- returns relPos of first entry.time >= time
-- first: relPos of lower search cutoff (inclusive)
local function binarySearchLogTime(log, time, first)
local offset = log.pos
local maxPos = log.maxPos
local floor = floor
local count = maxPos - first
local current
local step
while count > 0 do
step = floor(count / 2)
current = first + step
if log[1 + (current + offset) % maxPos].time < time then
first = current + 1
count = count - (step + 1)
else
count = step
end
end
return first
end
local function iterEmpty()
end
-- [1] = tbl, [2] = max
local function iterRange(state, i)
i = i + 1
if i <= state[2] then
return i, state[1][i]
end
end
-- [1] = tbl, [2] = j, [3] = max1, [4] = min2, [5] = max3
local function iterTwoRanges(state, i)
i = i + 1
local j = state[2]
if i <= state[j] then
return i, state[1][i]
elseif j == 3 then
i = state[4]
if i <= state[5] then
state[2] = 5
return i, state[1][i]
end
end
end
local function iterateLogWindow(log, beginTime, endTime)
local beginRelPos = binarySearchLogTime(log, beginTime, 0)
local endRelPos = binarySearchLogTime(log, endTime, beginRelPos)
if beginRelPos == endRelPos then
return iterEmpty
end
local offset = log.pos
local maxPos = log.maxPos
local beginPos = 1 + (beginRelPos + offset) % maxPos
local endPos = 1 + (endRelPos - 1 + offset) % maxPos -- inclusive
if beginPos <= endPos then
return iterRange, {log, endPos}, beginPos - 1
else
return iterTwoRanges, {log, 3, maxPos, 1, endPos}, beginPos - 1
end
end
local function findPetOwner(guid)
local summoner = summons[guid] or summons2[guid]
if summoner then return summoner end
if IsInRaid() then
local raid = unitList.raid
local raidpet = unitList.raidpet
for i = 1, GetNumGroupMembers() do
if UnitGUID(raidpet[i]) == guid then
return GetUnitName(raid[i])
end
end
else
if IsInGroup() then
local party = unitList.party
local partypet = unitList.partypet
for i = 1, GetNumSubgroupMembers() do
if UnitGUID(partypet[i]) == guid then
return GetUnitName(party[i])
end
end
end
if UnitGUID('pet') == guid then
return GetUnitName('player')
end
end
end
local function finalizeCandidate(cand)
if not cand then return end
local entry = cand.combatLogEntry
if entry then
cand.name = entry.name
if cand.combatLogScore >= 25 then
if combatLogSwingEventTest[entry.event] then
cand.spellID = 6603 -- auto attack
else
cand.spellID = entry.spellID
end
end
end
cand.name = cand.name
or (cand.threatEntry and cand.threatEntry.name)
or (cand.targetLogEntry and cand.targetLogEntry.name)
local guid = cand.guid
if not guid:find('^Player') then
cand.petOwner = findPetOwner(guid)
end
end
local function printCandidateDetails(cand, intro)
addon.Console(string.format('%s%s (spellID=%s, petOwner=%s); score=%.2f (log=%.2f, threat=%.2f, target=%.2f).',
intro, tostring(cand.name), tostring(cand.spellID), tostring(cand.petOwner),
cand.score, cand.combatLogScore, cand.threatScore, cand.targetScore))
end
local function printDetails()
local ctx = pullContext
if not ctx then return end
addon.Console(string.format('%s (id=%d) pulled %.3fs ago (%s) announce=%s.',
tostring(ctx.encounterName), ctx.encounterID, GetTime() - ctx.pullTime,
ctx.pullTimeDiff and format('%+.3fs', ctx.pullTimeDiff) or 'UNTIMED',
tostring(ctx.announceChannel)))
if ctx.bestCand then
printCandidateDetails(ctx.bestCand, 'Best pull candidate: ')
if ctx.secondCand then
printCandidateDetails(ctx.secondCand, 'Next best pull candidate: ')
end
else
addon.Console('No one to blame for pull.')
end
end
local function getBlameDesc(bestCand, bestScore, secondScore)
local blameDesc = ' by unknown cause'
if bestCand then
local name = bestCand.name or '<Unknown>'
local spellID = bestCand.spellID
local petOwner = bestCand.petOwner
if petOwner then
blameDesc = ' by ' .. petOwner .. "'s pet " .. name
else
blameDesc = ' by ' .. name
end
if spellID then
blameDesc = blameDesc .. ' ' .. (GetSpellLink(spellID) or ('<Spell ' .. spellID .. '>'))
end
if bestScore - secondScore < 50 then
blameDesc = blameDesc..' (?)'
end
end
return blameDesc
end
local function announce(channel, msg)
if channel == 'PRINT' then
addon.Console(msg)
elseif channel then
if AstralRaidSettings.earlypull.announce.onlyGuild and not IsInGuildGroup() then addon.Console('Not in guild group; not announcing pull.') return end
SendChatMessage(msg, channel)
end
end
local function afterPull()
local ctx = pullContext
local pullTime = ctx.pullTime
local cwBeginTime = pullTime - 1
local cwEndTime = pullTime + 1
local timelinessCenter = pullTime
local timelinessDecayRate = 3
local function getTimelinessPenalty(entry)
return 1 - timelinessDecayRate * math.abs(entry.time - timelinessCenter)
end
local candidates = {}
local function getCandidate(guid)
local cand = candidates[guid] or {guid = guid, combatLogScore = 0, threatScore = 0, targetScore = 0}
candidates[guid] = cand
return cand
end
-- boss log pass
local bosses = {}
for _, entry in iterateLogWindow(bossLog, cwBeginTime, cwEndTime) do
bosses[entry.guid] = true
end
-- combat log pass
for _, entry in iterateLogWindow(combatLog, cwBeginTime, cwEndTime) do
local score = 90 * getTimelinessPenalty(entry)
if not combatLogDamageEventTest[entry.event] then
score = score * 0.9
end
if entry.event == 'SPELL_CAST_SUCCESS' then
score = score * 0.7
end
if not bosses[entry.destGUID] then
score = score * 0.4
end
local cand = getCandidate(entry.guid)
if score > cand.combatLogScore then
cand.combatLogScore = score
cand.combatLogEntry = entry
end
end
-- threat log pass
local earliestThreatTable
for _, entry in iterateLogWindow(threatLog, cwBeginTime, cwEndTime) do
local threatEntries = entry.threatEntries
local count = threatEntries.count
if count > 0 then
earliestThreatTable = earliestThreatTable or entry.time
local highestThreatValue = 0
for j = 1, count do
highestThreatValue = max(highestThreatValue, threatEntries[j].threatValue or 0)
end
local notEarliestPenalty = (entry.time == earliestThreatTable) and 1 or 0.4
for j = 1, count do
local threatEntry = threatEntries[j]
local score = 100 * getTimelinessPenalty(entry) * notEarliestPenalty
if not threatEntry.isTanking then
if threatEntry.threatValue == highestThreatValue then
score = score * 0.8
else
score = score * 0.7
end
end
local cand = getCandidate(threatEntry.guid)
if score > cand.threatScore then
cand.threatScore = score
cand.threatEntry = threatEntry
end
end
end
end
-- target log pass
local earliestTarget
for _, entry in iterateLogWindow(targetLog, cwBeginTime, cwEndTime) do
earliestTarget = earliestTarget or entry.time
local notEarliestPenalty = (entry.time == earliestTarget) and 1 or 0.4
local score = 80 * getTimelinessPenalty(entry) * notEarliestPenalty
local cand = getCandidate(entry.guid)
if score > cand.targetScore then
cand.targetScore = score
cand.targetLogEntry = entry
end
end
-- candidates comparison
local bestScore, bestCand = 0, nil
local secondScore, secondCand = 0, nil
for _, cand in pairs(candidates) do
local score = cand.combatLogScore + cand.threatScore + cand.targetScore
cand.score = score
if score > bestScore then
secondScore, secondCand = bestScore, bestCand
bestScore, bestCand = score, cand
elseif score > secondScore then
secondScore, secondCand = score, cand
end
end
finalizeCandidate(bestCand)
finalizeCandidate(secondCand)
ctx.bestCand = bestCand
ctx.secondCand = secondCand
if AstralRaidSettings.earlypull.general.printResults then printDetails() end
-- sync log pass & announce
local bestSyncTable
for _, entry in iterateLogWindow(syncLog, cwBeginTime, cwEndTime) do
local syncTable = deserializeSyncTable(entry.message)
if syncTable[2] == ctx.encounterID and (not bestSyncTable or compareSyncTables(bestSyncTable, syncTable)) then
bestSyncTable = syncTable
end
end
if bestSyncTable then
addon.PrintDebug('bestSyncTable', bestSyncTable[3], bestSyncTable[4], bestSyncTable[5])
end
if (not bestSyncTable) or isMe(bestSyncTable) then
announce(ctx.announceChannel, ctx.pullDesc .. getBlameDesc(bestCand, bestScore, secondScore) .. '.')
end
if addon.Encounter then
addon.Encounter.whoPulled = bestCand
end
end
local function playerEnteringWorld()
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
scanAllBosses()
end
local function chatMsgAddon(prefix, msg, _, sender) -- get pull timer from boss mods
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
if prefix ~= 'D5' then return end
local _, _, ty, duration, instanceID, _ = strsplit('\t', msg)
if ty ~= 'PT' then return end
duration = tonumber(duration or 0)
instanceID = tonumber(instanceID)
if IsEncounterInProgress()
or (IsInGroup() and not maySendPullTimer(sender))
or (duration > 60 or (duration > 0 and duration < 3) or duration < 0)
or (instanceID and instanceID ~= select(8, GetInstanceInfo())) then
return
end
if duration == 0 then
expectedPullTime = nil
else
expectedPullTime = GetTime() + duration
end
end
local function unitThreatListUpdate(unit)
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
if unit and unit:find('^boss') then scanThreat(unit) end
end
local function unitTarget(unit)
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
if unit and unit:find('^boss') then scanBoss(unit, unit .. 'target') end
end
local function cleu(_, event, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, _, _, auraType)
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
if not addon.InInstance then return end
if event == 'SPELL_SUMMON' then -- summons are used for tracking pet owners, not pull detection
if not destGUID then return end
summons[destGUID] = sourceName
local counter = summons.counter + 1
if counter >= 1000 then
summons = summons2
summons2 = summons
wipe(summons)
summons.counter = 0
else
summons.counter = counter
end
elseif event == 'SPELL_DAMAGE' or event == 'SPELL_MISSED' or event == 'SPELL_PERIODIC_DAMAGE'
or event == 'SWING_DAMAGE' or event == 'RANGE_DAMAGE' or event == 'RANGE_MISSED'
or event == 'SPELL_AURA_APPLIED' or event == 'SPELL_CAST_SUCCESS' then
if not (sourceGUID and destGUID) or (event == 'SPELL_AURA_APPLIED' and auraType ~= 'DEBUFF') then return end
if bit.band(sourceFlags, sourceFlagMask) ~= sourceFlagFilter then return end
local destFlagsMasked = bit.band(destFlags, destFlagMask)
if destFlagsMasked ~= destFlagFilter1 and destFlagsMasked ~= destFlagFilter2 then return end
local entry = advanceLog(combatLog)
entry.time = GetTime()
entry.guid = sourceGUID
entry.name = sourceName
entry.event = event
entry.destGUID = destGUID
entry.destName = destName
entry.spellID = spellID
end
end
local function encounterStart(encounterID, encounterName)
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
if not encounterID then return end
local now = GetTime()
local pullTimeDiff = expectedPullTime and (now - expectedPullTime)
if pullTimeDiff and abs(pullTimeDiff) > 10 then
pullTimeDiff = nil
end
expectedPullTime = nil
local announceChannel, pullDesc = classifyPull(pullTimeDiff)
if announceChannel and announceChannel ~= 'PRINT' then
sendSync(createSyncTable(encounterID))
end
pullContext = {
pullTime = now,
pullTimeDiff = pullTimeDiff,
announceChannel = announceChannel,
pullDesc = pullDesc,
encounterID = encounterID,
encounterName = encounterName,
}
C_Timer.After(1, afterPull)
scanAllBosses()
end
local function instanceEncounterEngageUnit()
if not AstralRaidSettings.earlypull.general.isEnabled then return end
if not (IsInGroup() or IsInRaid()) then return end
scanAllBosses()
end
init()
AstralRaidEvents:Register('PLAYER_ENTERING_WORLD', playerEnteringWorld, 'EarlyPullPlayerEnteringWorld')
AstralRaidEvents:Register('CHAT_MSG_ADDON', chatMsgAddon, 'EarlyPullChatMsgAddon')
AstralRaidEvents:Register('UNIT_THREAT_LIST_UPDATE', unitThreatListUpdate, 'EarlyPullUnitThreatListUpdate')
AstralRaidEvents:Register('UNIT_TARGET', unitTarget, 'EarlyPullUnitTarget')
AstralRaidEvents:Register('COMBAT_LOG_EVENT_UNFILTERED', function() cleu(CombatLogGetCurrentEventInfo()) end, 'EarlyPullCLEU')
AstralRaidEvents:Register('ENCOUNTER_START', encounterStart, 'EarlyPullEncounterStart')
AstralRaidEvents:Register('INSTANCE_ENCOUNTER_ENGAGE_UNIT', instanceEncounterEngageUnit, 'EarlyPullInstanceEncounterEngageUnit')
AstralRaidComms:RegisterPrefix('RAID', EARLY_PULL_PREFIX, function(...) onSync('RAID', ...) end)
AstralRaidComms:RegisterPrefix('PARTY', EARLY_PULL_PREFIX, function(...) onSync('PARTY', ...) end)
AstralRaidComms:RegisterPrefix('INSTANCE_CHAT', EARLY_PULL_PREFIX, function(...) onSync('INSTANCE_CHAT', ...) end)
-- addon.AddDefaultSettings('earlypull', 'announce', {earlyPull = 1, onTimePull = 1, latePull = 1, untimedPull = 1})
local module = addon:New(L['EARLY_PULL'], L['EARLY_PULL'])
local enableCheckbox, printResultsCheckbox, onlyGuildGroupsCheckbox, pullHeader, earlyPullDropdown, onTimePullDropdown, latePullDropdown, untimedPullDropdown
local announceKinds = {[1] = 'Say', [2] = 'Group', [3] = 'Officer', [4] = 'Print', [5] = 'None'}
function module.options:Load()
local header = AstralUI:Text(self, L['EARLY_PULL_DETECTION']):Point('TOPLEFT', 0, 0):Shadow()
enableCheckbox = AstralUI:Check(self, ENABLE):Point('TOPLEFT', header, 'BOTTOMLEFT', 0, -20):OnClick(function(self)
AstralRaidSettings.earlypull.general.isEnabled = self:GetChecked()
if AstralRaidSettings.earlypull.general.isEnabled then
init()
printResultsCheckbox:Show()
pullHeader:Show()
onlyGuildGroupsCheckbox:Show()
earlyPullDropdown:Show()
onTimePullDropdown:Show()
latePullDropdown:Show()
untimedPullDropdown:Show()
else
printResultsCheckbox:Hide()
pullHeader:Hide()
onlyGuildGroupsCheckbox:Hide()
earlyPullDropdown:Hide()
onTimePullDropdown:Hide()
latePullDropdown:Hide()
untimedPullDropdown:Hide()
end
end)
printResultsCheckbox = AstralUI:Check(self, L['EARLY_PULL_PRINT_RESULTS'] .. CHAT):Point('LEFT', enableCheckbox, 'RIGHT', 150, 0):OnClick(function(self)
AstralRaidSettings.earlypull.general.printResults = self:GetChecked()
end)
local earlyPullDesc = AstralUI:Text(self, L['EARLY_PULL_DESC']):Point('TOPLEFT', enableCheckbox, 'BOTTOMLEFT', 0, -10):FontSize(9):Shadow()
pullHeader = AstralUI:Text(self, L['EARLY_PULL_ANNOUNCE']):Point('TOPLEFT', earlyPullDesc, 'BOTTOMLEFT', 0, -20):Shadow()
onlyGuildGroupsCheckbox = AstralUI:Check(self, 'Only Announce in ' .. GUILD .. ' ' .. GROUPS):Point('TOPLEFT', pullHeader, 'BOTTOMLEFT', 0, -20):OnClick(function(self)
AstralRaidSettings.earlypull.announce.onlyGuild = self:GetChecked()
end)
local function earlyPullDropdownSetValue(_, arg1)
AstralUI:DropDownClose()
earlyPullDropdown:SetText(announceKinds[arg1])
AstralRaidSettings.earlypull.announce.earlyPull = arg1
end
earlyPullDropdown = AstralUI:DropDown(self, 200, 10):Size(250):Point('TOPLEFT', onlyGuildGroupsCheckbox, 'BOTTOMLEFT', 0, -20):AddText(string.format('|cffffce00%s:', L['EARLY_PULL']))
for i = 1, #announceKinds do
local info = {}
earlyPullDropdown.List[i] = info
info.text = announceKinds[i]
info.arg1 = i
info.func = earlyPullDropdownSetValue
info.justifyH = 'CENTER'
end
local function onTimePullDropdownSetValue(_, arg1)
AstralUI:DropDownClose()
onTimePullDropdown:SetText(announceKinds[arg1])
AstralRaidSettings.earlypull.announce.onTimePull = arg1
end
onTimePullDropdown = AstralUI:DropDown(self, 200, 10):Size(250):Point('LEFT', earlyPullDropdown, 'RIGHT', 10, 0):AddText(string.format('|cffffce00%s:', L['ON_TIME_PULL']))
for i = 1, #announceKinds do
local info = {}
onTimePullDropdown.List[i] = info
info.text = announceKinds[i]
info.arg1 = i
info.func = onTimePullDropdownSetValue
info.justifyH = 'CENTER'
end
local function latePullDropdownSetValue(_, arg1)
AstralUI:DropDownClose()
latePullDropdown:SetText(announceKinds[arg1])
AstralRaidSettings.earlypull.announce.latePull = arg1
end
latePullDropdown = AstralUI:DropDown(self, 200, 10):Size(250):Point('TOPLEFT', earlyPullDropdown, 'BOTTOMLEFT', 0, -20):AddText(string.format('|cffffce00%s:', L['LATE_PULL']))
for i = 1, #announceKinds do
local info = {}
latePullDropdown.List[i] = info
info.text = announceKinds[i]
info.arg1 = i
info.func = latePullDropdownSetValue
info.justifyH = 'CENTER'
end
local function untimedPullDropdownSetValue(_, arg1)
AstralUI:DropDownClose()
untimedPullDropdown:SetText(announceKinds[arg1])
AstralRaidSettings.earlypull.announce.untimedPull = arg1
end
untimedPullDropdown = AstralUI:DropDown(self, 200, 10):Size(250):Point('LEFT', latePullDropdown, 'RIGHT', 10, 0):AddText(string.format('|cffffce00%s:', L['UNTIMED_PULL']))
for i = 1, #announceKinds do
local info = {}
untimedPullDropdown.List[i] = info
info.text = announceKinds[i]
info.arg1 = i
info.func = untimedPullDropdownSetValue
info.justifyH = 'CENTER'
end
end
function module.options:OnShow()
enableCheckbox:SetChecked(AstralRaidSettings.earlypull.general.isEnabled)
printResultsCheckbox:SetChecked(AstralRaidSettings.earlypull.general.printResults)
onlyGuildGroupsCheckbox:SetChecked(AstralRaidSettings.earlypull.announce.onlyGuild)
earlyPullDropdown:SetText(announceKinds[AstralRaidSettings.earlypull.announce.earlyPull])
onTimePullDropdown:SetText(announceKinds[AstralRaidSettings.earlypull.announce.onTimePull])
latePullDropdown:SetText(announceKinds[AstralRaidSettings.earlypull.announce.latePull])
untimedPullDropdown:SetText(announceKinds[AstralRaidSettings.earlypull.announce.untimedPull])
if not AstralRaidSettings.earlypull.general.isEnabled then
printResultsCheckbox:Hide()
onlyGuildGroupsCheckbox:Hide()
pullHeader:Hide()
earlyPullDropdown:Hide()
onTimePullDropdown:Hide()
latePullDropdown:Hide()
untimedPullDropdown:Hide()
end
end