Repository navigation
Expand file tree
/
Copy pathcurses.lua
More file actions
executable file
·1755 lines (1564 loc) · 62.5 KB
/
Copy pathcurses.lua
File metadata and controls
executable file
·1755 lines (1564 loc) · 62.5 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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if not Cursive.superwow then
return
end
local L = AceLibrary("AceLocale-2.2"):new("Cursive")
-- Local-cache frequently used globals
local GetTime = GetTime
local UnitExists = UnitExists
local UnitDebuff = UnitDebuff
local UnitBuff = UnitBuff
local UnitName = UnitName
local UnitClass = UnitClass
local UnitResistance = UnitResistance
local pairs = pairs
local floor = math.floor
-- Test Overlay: skip real API calls for fake GUIDs
local TEST_PREFIX = "CURSIVE_TEST_"
local function IsTestGuid(guid)
if not guid then return false end
return string.find(guid, TEST_PREFIX, 1, true) == 1
end
local ceil = math.ceil
local strfind = string.find
local strlower = string.lower
local strformat = string.format
local _, playerClassName = UnitClass("player")
local curses = {
trackedCurseIds = {},
trackedCurseNamesToTextures = {},
trackedCurseNameRanksToSpellSlots = {},
-- v3.2: Track player's own shared debuff casts for border color detection
-- Format: playerOwnedCasts[targetGuid][debuffKey] = timestamp
playerOwnedCasts = {},
conflagrateSpellIds = {
[17962] = true,
[18930] = true,
[18931] = true,
[18932] = true,
},
darkHarvestSpellIds = {
[52550] = true,
[52551] = true,
[52552] = true,
},
darkHarvestData = {},
guids = {},
isChanneling = false,
-- v4.0.4: Active channel proc scan timers (cancelled on channel stop)
channelProcScanIDs = {},
pendingCast = {},
resistSoundGuids = {},
expiringSoundGuids = {},
requestedExpiringSoundGuids = {}, -- guid added on spellcast, moved to expiringSoundGuids once rendered by ui
previousComboPoints = 0,
comboPoints = 0,
lastFerociousBiteTime = 0,
lastFerociousBiteTargetGuid = 0,
lastMoltenBlastTargetGuid = 0,
sharedDebuffs = {}, -- populated by LoadCurses() from shared_debuffs.lua
sharedDebuffGuids = {}, -- populated by LoadCurses(), tracks active debuffs per target
sharedDebuffMeta = {}, -- populated by LoadCurses(), metadata (category, stacks, isProc, etc.)
-- Reverse lookup: spellID -> debuffKey (built in LoadCurses for fast event handling)
sharedDebuffSpellLookup = {},
-- Reverse lookup: trigger spellID -> debuffKey (for proc-based debuffs)
sharedDebuffTriggerLookup = {},
-- v3.2.1: Proc refresh tracking
-- procExpected[targetGuid][debuffKey] = timestamp — set when trigger spell cast detected
procExpected = {},
-- lastProcStacks[targetGuid][debuffKey] = stackCount — for stack-change detection
lastProcStacks = {},
-- Whitelist of mobs that can bleed (for rake tracking at client debuff cap)
mobsThatBleed = {
["0xF13000F1F3276A33"] = true, -- Keeper Gnarlmoon
["0xF13000F1FA276A32"] = true, -- Ley-Watcher Incantagos
["0xF13000EA3F276C05"] = true, -- King
["0xF13000EA31279058"] = true, -- Queen
["0xF13000EA43276C06"] = true, -- Bishop
["0xF13000EA44279044"] = true, -- Pawn
["0xF13000EA42276C07"] = true, -- Rook
["0xF13000EA4D05DA44"] = true, -- Sanv Tas'dal
["0xF13000EA57276C04"] = true, -- Kruul
["0xF130016C95276DAF"] = true, -- Mephistroth
["0xF130003E5401591A"] = true, --Anub'Rekhan
["0xF130003E510159B0"] = true, --Grand Widow Faerlina
["0xF130003E500159A3"] = true, --Maexxna
["0xF130003EBD01598C"] = true, --Razuvious
["0xF130003EBC01599F"] = true, --Gothik
["0xF130003EBF015AB2"] = true, --Zeliek
["0xF130003EBE015AB3"] = true, --Mograine
["0xF130003EC1015AB1"] = true, --Blaumeux
["0xF130003EC0015AB0"] = true, --Thane
["0xF130003E52015824"] = true, --Noth
["0xF130003E4001588D"] = true, --Heigan
["0xF130003E8B0158A2"] = true, --Loatheb
["0xF130003E9C0158EA"] = true, --Patchwerk
["0xF130003E3B0158EF"] = true, --Grobbulus
["0xF130003E3C0158F0"] = true, --Gluth
["0xF130003E380159A0"] = true, --Thaddius
["0xF130003E75015AB4"] = true, --Sapphiron
["0xF130003E76015AED"] = true, --Kel'Thuzad
},
}
-- Bleed-immune creature types (Elementals, Undead, Mechanical cannot bleed)
local BLEED_IMMUNE_TYPES = {
["Elemental"] = true,
["Undead"] = true,
["Mechanical"] = true,
}
-- Check if a unit can receive bleed effects
local function CanApplyBleed(guid)
if IsTestGuid(guid) then return true end
if not UnitExists(guid) then
return true -- Can't check, assume can bleed
end
local creatureType = UnitCreatureType(guid)
if creatureType and BLEED_IMMUNE_TYPES[creatureType] then
return false
end
return true
end
-- combat events for curses
local fades_test = L["(.+) fades from (.+)"]
local resist_test = L["Your (.+) was resisted by (.+)"]
local missed_test = L["Your (.+) missed (.+)"]
local parry_test = L["Your (.+) is parried by (.+)"]
local immune_test = L["Your (.+) fail.+\. (.+) is immune"]
local block_test = L["Your (.+) was blocked by (.+)"]
local dodge_test = L["Your (.+) was dodged by (.+)"]
-- v4.0.4: Pre-built test arrays for CHAT_MSG_SPELL_SELF_DAMAGE (avoid per-event allocation)
local spell_failed_tests_base = { resist_test, immune_test }
local spell_failed_tests_melee = { resist_test, immune_test, missed_test, parry_test, block_test, dodge_test }
local molten_blast_test = L["Your Molten Blast(.+)for .+ Fire damage"]
local lastGuid = nil
-- I think depending on ping the combo point used event can fire either before or after your ability cast
function curses:GetComboPointsUsed()
if curses.comboPoints == 0 then
return curses.previousComboPoints
else
return curses.comboPoints
end
end
function curses:LoadCurses()
-- reset dicts
curses.trackedCurseIds = {}
curses.trackedCurseNamesToTextures = {}
curses.trackedCurseNameRanksToSpellSlots = {}
curses.isWarlock = playerClassName == "WARLOCK"
curses.isPriest = playerClassName == "PRIEST"
curses.isMage = playerClassName == "MAGE"
curses.isDruid = playerClassName == "DRUID"
curses.isHunter = playerClassName == "HUNTER"
curses.isRogue = playerClassName == "ROGUE"
curses.isShaman = playerClassName == "SHAMAN"
curses.isWarrior = playerClassName == "WARRIOR"
-- curses to track
if curses.isWarlock then
curses.trackedCurseIds = getWarlockSpells()
elseif curses.isPriest then
curses.trackedCurseIds = getPriestSpells()
elseif curses.isMage then
curses.trackedCurseIds = getMageSpells()
elseif curses.isDruid then
curses.trackedCurseIds = getDruidSpells()
elseif curses.isHunter then
curses.trackedCurseIds = getHunterSpells()
elseif curses.isRogue then
curses.trackedCurseIds = getRogueSpells()
elseif curses.isShaman then
curses.trackedCurseIds = getShamanSpells()
elseif curses.isWarrior then
curses.trackedCurseIds = getWarriorSpells()
end
-- load shared debuffs (v3.2: full metadata structure)
local sharedDebuffData = getSharedDebuffs()
curses.sharedDebuffs = {}
curses.sharedDebuffGuids = {}
curses.sharedDebuffMeta = {}
curses.sharedDebuffSpellLookup = {}
curses.sharedDebuffTriggerLookup = {}
-- v3.2.1: Target Armor cache — stores live + total (highest seen) armor per GUID
curses.armorCache = {} -- guid -> { live = number, total = number }
-- v3.2: Expose Armor — armor reduction per combo point, per rank (TurtleWoW values)
-- aDF-style: track frame-by-frame armor changes to detect exact EA reduction
curses.exposeArmorPerCP = {
[8647] = 80, -- Rank 1: 80 armor per CP
[8649] = 145, -- Rank 2: 145 armor per CP
[8650] = 210, -- Rank 3: 210 armor per CP
[11197] = 275, -- Rank 4: 275 armor per CP
[11198] = 340, -- Rank 5: 340 armor per CP
}
curses.exposeArmorTalentMults = { 1.00, 1.25, 1.50 } -- 0/1/2 talent points
-- Armor monitor state per target
curses.armorMonitor = {} -- targetGuid -> { prevArmor, baseArmor, expectingEA, eaSpellID, monitorUntil }
for debuffKey, data in pairs(sharedDebuffData) do
-- Build flat spell lookup (backward compatible: curses.sharedDebuffs.faeriefire[spellID])
curses.sharedDebuffs[debuffKey] = {}
if data.spells then
for spellID, spellData in pairs(data.spells) do
curses.sharedDebuffs[debuffKey][spellID] = spellData
-- Reverse lookup: spellID -> debuffKey
curses.sharedDebuffSpellLookup[spellID] = debuffKey
end
end
-- Initialize guid tracking table
curses.sharedDebuffGuids[debuffKey] = {}
-- Store metadata
curses.sharedDebuffMeta[debuffKey] = {
category = data.category,
class = data.class,
raidRelevant = data.raidRelevant,
stacks = data.stacks,
isProc = data.isProc,
triggerSpells = data.triggerSpells,
displayStacks = data.displayStacks,
exclusiveWith = data.exclusiveWith,
}
-- Build trigger spell reverse lookup for proc-based debuffs
if data.isProc and data.triggerSpells then
for _, triggerID in ipairs(data.triggerSpells) do
curses.sharedDebuffTriggerLookup[triggerID] = debuffKey
end
end
-- Initialize default setting if not set
if Cursive.db.profile.shareddebuffs[debuffKey] == nil then
-- Raid-relevant debuffs default to ON for existing faeriefire users
if debuffKey == "faeriefire" then
-- keep existing setting
else
Cursive.db.profile.shareddebuffs[debuffKey] = false
end
end
end
-- go through spell slots and
local i = 1
while true do
local spellname, spellrank = GetSpellName(i, BOOKTYPE_SPELL)
if not spellname then
break
end
if spellrank == "" then
spellrank = L["Rank 1"]
end
curses.trackedCurseNameRanksToSpellSlots[strlower(spellname) .. spellrank] = i
i = i + 1
end
for id, data in pairs(curses.trackedCurseIds) do
-- get the texture
local name, rank, texture = SpellInfo(id)
-- v4.1.1 FIX: Do not cache the "?" fallback texture for spells the player
-- doesn't know (cross-class spells where SpellInfo resolves to the question-mark
-- icon). Leaving it nil lets the render chain fall through to curseData.sharedTexture
-- or a live scan — never lock in a broken icon for a spell that has a valid
-- texture available from another source.
if texture and string.find(texture, "INV_Misc_QuestionMark", 1, true) then
texture = nil
end
-- update trackedCurseNamesToTextures
curses.trackedCurseNamesToTextures[data.name] = texture
-- update trackedCurseIds
curses.trackedCurseIds[id].texture = texture
end
-- v4.0.4: Pre-compute normalized debuff names (avoids string.gsub in hot paths)
curses.normalizedToKey = {}
curses.nameToNormalized = {}
for debuffKey, spells in pairs(curses.sharedDebuffs) do
curses.normalizedToKey[debuffKey] = debuffKey
for _, spellData in pairs(spells) do
if type(spellData) == "table" and spellData.name then
local normalized = string.gsub(string.lower(spellData.name), "[%s']", "")
curses.nameToNormalized[spellData.name] = normalized
curses.normalizedToKey[normalized] = debuffKey
end
end
end
for spellID, spellData in pairs(curses.trackedCurseIds) do
if spellData.name then
local normalized = string.gsub(string.lower(spellData.name), "[%s']", "")
curses.nameToNormalized[spellData.name] = normalized
end
end
if curses.isDruid or curses.isRogue then
Cursive:RegisterEvent("PLAYER_COMBO_POINTS", function()
local currentComboPoints = GetComboPoints()
if curses.isDruid and currentComboPoints >= curses.comboPoints then
-- combo points did not decrease, check if Ferocious Bite was used is the last .5 sec
if GetTime() - curses.lastFerociousBiteTime < 0.5 and
curses.lastFerociousBiteTargetGuid and
curses.lastFerociousBiteTargetGuid ~= 0 then
-- check if Rip active
local rip = L["rip"]
if curses:HasCurse(rip, curses.lastFerociousBiteTargetGuid, 0) then
curses.guids[curses.lastFerociousBiteTargetGuid][rip]["start"] = GetTime() -- reset start time to current time
end
-- check if Rake active
local rake = L["rake"]
if curses:HasCurse(rake, curses.lastFerociousBiteTargetGuid, 0) then
curses.guids[curses.lastFerociousBiteTargetGuid][rake]["start"] = GetTime() -- reset start time to current time
end
end
end
curses.previousComboPoints = curses.comboPoints
curses.comboPoints = currentComboPoints
end)
end
curses:CheckEyeOfDormantCorruption()
Cursive:RegisterEvent("PLAYER_EQUIPMENT_CHANGED", function()
curses:CheckEyeOfDormantCorruption()
end)
end
function curses:CheckEyeOfDormantCorruption()
local trinketItemId = 55111
for slot = 13, 14 do
local link = GetInventoryItemLink("player", slot)
if link then
local _, _, itemId = strfind(link, "item:(%d+)")
if itemId and tonumber(itemId) == trinketItemId then
curses.hasEyeOfDormantCorruption = true
return
end
end
end
curses.hasEyeOfDormantCorruption = false
end
function curses:ScanTooltipForDuration(curseSpellID)
-- scan spellbook for duration in case they have haste talent
local nameRank = curses.trackedCurseIds[curseSpellID].name .. L["Rank"] .. " " .. curses.trackedCurseIds[curseSpellID].rank
local spellSlot = curses.trackedCurseNameRanksToSpellSlots[nameRank]
if spellSlot then
Cursive.core.tooltipScan:SetOwner(Cursive.core.tooltipScan, "ANCHOR_NONE")
Cursive.core.tooltipScan:ClearLines()
Cursive.core.tooltipScan:SetSpell(spellSlot, BOOKTYPE_SPELL)
local numLines = Cursive.core.tooltipScan:NumLines()
if numLines and numLines > 0 then
-- get the last line
local text = getglobal("CursiveTooltipScan" .. "TextLeft" .. numLines):GetText()
if text then
local _, _, duration = strfind(text, L["curse_duration_format"])
if duration then
return tonumber(duration)
end
end
end
end
return curses.trackedCurseIds[curseSpellID].duration
end
function curses:GetCurseDuration(curseSpellID)
local duration
local durationFromTooltip = false
if curses.trackedCurseIds[curseSpellID].variableDuration then
duration = curses:ScanTooltipForDuration(curseSpellID)
durationFromTooltip = true
elseif curses.trackedCurseIds[curseSpellID].calculateDuration then
duration = curses.trackedCurseIds[curseSpellID].calculateDuration()
else
duration = curses.trackedCurseIds[curseSpellID].duration
end
local spellName = curses.trackedCurseIds[curseSpellID].name
local baseDuration = curses.trackedCurseIds[curseSpellID].duration
-- Eye of Dormant Corruption trinket handling
-- v4.0.3: Always add +3 when trinket is equipped for these spells.
-- The tooltip already shows haste-reduced duration (e.g. 16.8 instead of 18).
-- The server does NOT add the trinket bonus to the tooltip — we must always add it.
-- eyeExtended flag prevents premature removal when server debuff expires before addon timer.
curses._lastEyeExtended = false
if spellName == L["corruption"] or spellName == L["shadow word: pain"] then
curses:CheckEyeOfDormantCorruption()
if curses.hasEyeOfDormantCorruption then
duration = duration + 3
curses._lastEyeExtended = true
end
end
return duration
end
function curses:ScanGuidForCurse(guid, curseSpellID)
if IsTestGuid(guid) then return false end
for i = 1, 64 do
local _, _, _, spellID = UnitDebuff(guid, i)
if spellID then
if spellID == curseSpellID then
return true
end
else
break
end
end
for i = 1, 64 do
local _, _, spellID = UnitBuff(guid, i)
if spellID then
if spellID == curseSpellID then
return true
end
else
break
end
end
return nil
end
function curses:GetLowercaseSpellName(spellName)
spellName = strlower(spellName)
-- handle faerie fire special case
if curses.isDruid and strfind(spellName, L["faerie fire"]) then
return L["faerie fire"]
end
return spellName
end
-- v3.2: Scan target debuffs for proc-based shared debuffs (ISB, Fire Vuln, etc.)
-- Called via ScheduleEvent after a trigger spell is cast
function curses.ScanForProcDebuff(self, debuffKey, targetGuid)
if not curses.sharedDebuffs[debuffKey] then return end
if not UnitExists(targetGuid) then return end
local debuffSpells = curses.sharedDebuffs[debuffKey]
for i = 1, 64 do
local texture, stackCount, _, spellID = UnitDebuff(targetGuid, i)
if not spellID then break end
if debuffSpells[spellID] then
local procSpellData = debuffSpells[spellID]
-- v3.2.1 FIX: If already tracked in guids, only refresh timer when evidence exists
-- Previously this was unconditional — caused phantom timer resets on every Shadow Bolt
if procSpellData and curses.guids[targetGuid] and curses.guids[targetGuid][procSpellData.name] then
local existing = curses.guids[targetGuid][procSpellData.name]
existing.sharedTexture = texture
local newStacks = stackCount or 0
local meta = curses.sharedDebuffMeta[debuffKey]
-- Check for actual evidence of refresh (same logic as ScanTargetForSharedDebuffs)
local oldStacks = curses.lastProcStacks[targetGuid] and curses.lastProcStacks[targetGuid][debuffKey] or -1
local stackChanged = (newStacks ~= oldStacks and oldStacks ~= -1)
local isNewDebuff = (oldStacks == -1)
local noTrigger = meta and (not meta.triggerSpells or table.getn(meta.triggerSpells) == 0)
local elapsed = GetTime() - existing.start
local halfDuration = (procSpellData.duration or 10) * 0.5
-- v4.0.4: During active channeling, be more lenient with timer refresh
-- Channel ticks proc debuffs repeatedly but we only get scan snapshots
local channelRefresh = curses.isChanneling and (elapsed > 1.0)
-- v4.0.5 FIX: noTrigger procs only refresh on first detection or re-application
local noTriggerRefresh = noTrigger and (isNewDebuff or elapsed > (procSpellData.duration or 10))
local shouldRefresh = stackChanged or noTriggerRefresh or channelRefresh or (elapsed > halfDuration)
if shouldRefresh then
existing.start = GetTime()
existing.duration = procSpellData.duration
existing.sharedStacks = newStacks
if CursiveSVDebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00[SV] ScanProc REFRESH: "..tostring(procSpellData.name).." elapsed="..string.format("%.1f", elapsed).." stacks "..tostring(oldStacks).."->"..tostring(newStacks).."|r")
end
else
-- No evidence of refresh — update stacks/texture only, keep timer
existing.sharedStacks = newStacks
if CursiveSVDebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF888888[SV] ScanProc SKIP refresh: "..tostring(procSpellData.name).." elapsed="..string.format("%.1f", elapsed).." (< halfDur)|r")
end
end
-- Track stacks for next comparison
if not curses.lastProcStacks[targetGuid] then
curses.lastProcStacks[targetGuid] = {}
end
curses.lastProcStacks[targetGuid][debuffKey] = newStacks
return
end
-- No existing entry — queue for initial apply
curses.sharedDebuffGuids[debuffKey][targetGuid] = {
time = GetTime(),
texture = texture,
stacks = stackCount or 0,
spellID = spellID,
}
-- v3.2.1 FIX: Ensure target is in core.guids for rendering
Cursive.core.addGuid(targetGuid)
-- v4.0.4: Removed redundant full scan (ScanForProcDebuff already updates the specific debuff)
-- curses:ScanTargetForSharedDebuffs(targetGuid)
if CursiveSVDebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[SV] ScanProc NEW: "..tostring(procSpellData and procSpellData.name).." queued|r")
end
return
end
end
end
-- v3.2.1: OnUpdate poller for Expose Armor — polls armor every frame after EA cast
-- This is more reliable than waiting for UNIT_AURA since armor changes may arrive late
-- v4.0.6: EA Poller throttled from 60Hz (every frame) to 5Hz (200ms)
if not CursiveEAPollerFrame then
CursiveEAPollerFrame = CreateFrame("Frame")
CursiveEAPollerFrame:Hide()
CursiveEAPollerFrame:SetScript("OnUpdate", function()
local now = GetTime()
-- v4.0.6: Throttle to 10Hz (100ms) — 2x server tick (50ms), catches EA within 1-2 ticks
-- EA Poller is short-lived (only active during EA monitoring window), so 10Hz is fine
if (this._tick or 0) > now then return end
this._tick = now + 0.1
for targetGuid, mon in pairs(Cursive.curses.armorMonitor) do
if mon.expectingEA and now <= mon.monitorUntil then
-- SuperWoW: no need to check current target, GUID works directly
Cursive.curses:CheckArmorChangeForEA(targetGuid)
elseif mon.expectingEA and now > mon.monitorUntil then
mon.expectingEA = false
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800[EA Poll] Monitor expired for "..targetGuid.."|r")
end
end
end
-- Hide poller if no active monitors
local anyActive = false
for _, mon in pairs(Cursive.curses.armorMonitor) do
if mon.expectingEA then
anyActive = true
break
end
end
if not anyActive then
CursiveEAPollerFrame:Hide()
end
end)
end
function curses:StartEAPoller()
CursiveEAPollerFrame:Show()
end
-- v3.2: Check armor changes on target to detect Expose Armor CP (aDF-style)
-- Called from OnUpdate poller and UNIT_AURA
-- NOTE: UnitResistance() only accepts unit tokens ("target"), NOT GUIDs!
function curses:CheckArmorChangeForEA(targetGuid)
local mon = curses.armorMonitor[targetGuid]
if not mon or not mon.expectingEA then return end
-- Check if monitor expired
if GetTime() > mon.monitorUntil then
mon.expectingEA = false
return
end
-- SuperWoW: UnitResistance accepts GUIDs directly — no need to be targeting
local armorNow = UnitResistance(targetGuid, 0) or 0
-- Use baseArmor (armor without EA) for calculation, fall back to prevArmor
local refArmor = mon.baseArmor or mon.prevArmor
local armorDrop = refArmor - armorNow -- total EA reduction from base
-- Debug output
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00[EA] base="..tostring(mon.baseArmor).." prev="..mon.prevArmor.." now="..armorNow.." drop="..armorDrop.." spellID="..tostring(mon.eaSpellID).."|r")
end
-- Only process if armor actually decreased from base
if armorDrop <= 0 then
-- Armor didn't drop (yet) — could be other changes, keep monitoring
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800[EA] No drop yet, keep monitoring|r")
end
return
end
local basePerCP = curses.exposeArmorPerCP[mon.eaSpellID] or 340
local comboPoints = 0
local bestError = 999
-- Try all talent multipliers (x1.00, x1.25, x1.50) and find cleanest CP fit
for _, mult in ipairs(curses.exposeArmorTalentMults) do
local perCP = basePerCP * mult
local rawCP = armorDrop / perCP
local roundedCP = floor(rawCP + 0.5)
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF888888[EA] mult="..mult.." perCP="..perCP.." raw="..strformat("%.2f", rawCP).." round="..roundedCP.."|r")
end
if roundedCP >= 1 and roundedCP <= 5 then
local err = math.abs(rawCP - roundedCP)
if err < bestError then
bestError = err
comboPoints = roundedCP
end
end
end
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[EA] RESULT: cp="..comboPoints.." err="..strformat("%.3f", bestError).."|r")
end
-- Accept result if close enough (tolerance: within 0.3 of a clean integer)
if comboPoints > 0 and bestError < 0.3 then
-- Ensure sharedDebuffGuids entry exists
if not curses.sharedDebuffGuids["exposearmor"] then
curses.sharedDebuffGuids["exposearmor"] = {}
end
local entry = curses.sharedDebuffGuids["exposearmor"][targetGuid]
if entry and type(entry) == "table" then
entry.stacks = comboPoints
entry.spellID = mon.eaSpellID
entry.time = GetTime()
else
-- Create entry if it doesn't exist yet (e.g. UNIT_AURA hasn't fired yet)
curses.sharedDebuffGuids["exposearmor"][targetGuid] = {
time = GetTime(),
texture = nil,
stacks = comboPoints,
spellID = mon.eaSpellID,
}
end
-- Also update if already in guids display table
local eaName = L["expose armor"]
if curses.guids[targetGuid] and curses.guids[targetGuid][eaName] then
curses.guids[targetGuid][eaName].sharedStacks = comboPoints
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00[EA] Set sharedStacks="..comboPoints.." on guids["..eaName.."]|r")
end
elseif CursiveEADebug then
-- Debug: show what keys exist for this target
local keys = ""
if curses.guids[targetGuid] then
for k, _ in pairs(curses.guids[targetGuid]) do
keys = keys .. tostring(k) .. ", "
end
end
DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8800[EA] guids key '"..tostring(eaName).."' not found. Keys: "..keys.."|r")
end
end
-- Done monitoring — armor change detected and processed
mon.expectingEA = false
-- Update prevArmor for next time (aDF-style continuous tracking)
mon.prevArmor = armorNow
end
-- v4.0.4: Extracted proc-refresh logic (was 11-tab nested; now standalone for readability)
-- Returns true if the existing debuff entry was updated (already tracked)
local function ProcessProcDebuffRefresh(existing, spellData, meta, debuffKey, targetGuid, now, stackCount, texture)
-- v4.0.4 FIX: Proc debuffs must always go through refresh check,
-- even when currentPlayer == true (fixes own Shadow Weaving skipped)
local isProcDebuff = meta and meta.isProc
if existing.currentPlayer ~= false and not isProcDebuff then
return
end
-- Update live texture
existing.sharedTexture = texture
local newStacks = stackCount or 0
-- v3.2.1 FIX: Detect proc debuff refresh
if meta and meta.isProc then
local oldStacks = curses.lastProcStacks[targetGuid] and curses.lastProcStacks[targetGuid][debuffKey] or -1
local stackChanged = (newStacks ~= oldStacks and oldStacks ~= -1)
local isNewDebuff = (oldStacks == -1)
-- Consume procExpected flag if present (prevents stale flags)
local procTriggered = false
if curses.procExpected[targetGuid] and curses.procExpected[targetGuid][debuffKey] then
local triggerTime = curses.procExpected[targetGuid][debuffKey]
if (now - triggerTime) < 2.0 then
procTriggered = true
end
curses.procExpected[targetGuid][debuffKey] = nil
end
-- v3.2.1: Weapon procs without triggerSpells
local noTrigger = (not meta.triggerSpells or table.getn(meta.triggerSpells) == 0)
-- v3.2.1 FIX: Only reset timer on actual evidence of refresh
local elapsed = now - existing.start
local halfDuration = (spellData.duration or 10) * 0.5
local procRefreshValid = procTriggered and (isNewDebuff or elapsed > halfDuration)
-- v4.0.5 FIX: noTrigger procs must only refresh on first detection or re-application
-- (was: unconditional refresh on every scan, resetting timer multiple times/second)
local noTriggerRefresh = noTrigger and (isNewDebuff or elapsed > (spellData.duration or 10))
if stackChanged or noTriggerRefresh or procRefreshValid then
existing.start = now
existing.duration = spellData.duration
if procTriggered and curses.playerOwnedCasts[targetGuid] and curses.playerOwnedCasts[targetGuid][debuffKey] then
local ownCastTime = curses.playerOwnedCasts[targetGuid][debuffKey]
if (now - ownCastTime) < 2.0 then
existing.currentPlayer = true
end
end
if CursiveSVDebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFFFFFF00[SV] REFRESH: "..tostring(spellData.name).." stacks "..tostring(oldStacks).."->"..tostring(newStacks).." procFlag="..tostring(procTriggered).." noTrig="..tostring(noTrigger).."|r")
end
end
-- Track stacks for next comparison
if not curses.lastProcStacks[targetGuid] then
curses.lastProcStacks[targetGuid] = {}
end
curses.lastProcStacks[targetGuid][debuffKey] = newStacks
end
-- Update stacks (except EA which uses armor-diff calculated CP)
if debuffKey ~= "exposearmor" then
existing.sharedStacks = newStacks
end
end
-- v3.2: Scan target for all enabled shared debuffs (reliable detection for procs + direct casts)
-- Called on UNIT_AURA for target, and periodically via UI update
function curses:ScanTargetForSharedDebuffs(targetGuid)
if not targetGuid then return end
if not UnitExists(targetGuid) then return end
local now = GetTime()
for debuffKey, debuffSpells in pairs(curses.sharedDebuffs) do
if Cursive.db.profile.shareddebuffs[debuffKey] then
local found = false
-- Scan all debuffs on the target
for i = 1, 64 do
local texture, stackCount, _, spellID = UnitDebuff(targetGuid, i)
if not spellID then break end
if debuffSpells[spellID] then
found = true
local spellData = debuffSpells[spellID]
-- v3.2.1 FIX: Check if this debuff is already applied in guids table
-- If yes, update texture/stacks and check for timer refresh (proc debuffs)
local alreadyApplied = false
if spellData and curses.guids[targetGuid] then
local existing = curses.guids[targetGuid][spellData.name]
if existing then
alreadyApplied = true
local meta = curses.sharedDebuffMeta[debuffKey]
ProcessProcDebuffRefresh(existing, spellData, meta, debuffKey, targetGuid, now, stackCount, texture)
end
end
-- Only queue for initial apply if not already tracked
if not alreadyApplied then
if not curses.sharedDebuffGuids[debuffKey] then
curses.sharedDebuffGuids[debuffKey] = {}
end
curses.sharedDebuffGuids[debuffKey][targetGuid] = {
time = now,
texture = texture,
stacks = stackCount or 0,
spellID = spellID,
}
end
break
end
end
-- v3.2: If shared debuff was NOT found on target but was tracked, remove it
if not found and curses.sharedDebuffGuids[debuffKey] and curses.sharedDebuffGuids[debuffKey][targetGuid] then
-- v3.2.1: Don't remove EA tracking while armor monitor is expecting a re-application
if debuffKey == "exposearmor" and curses.armorMonitor[targetGuid] and curses.armorMonitor[targetGuid].expectingEA then
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFF[EA] Debuff temporarily gone but monitor active — keeping tracking|r")
end
else
curses.sharedDebuffGuids[debuffKey][targetGuid] = nil
-- v3.2: Reset armor monitor when EA actually falls off (no pending re-apply)
if debuffKey == "exposearmor" and curses.armorMonitor[targetGuid] then
curses.armorMonitor[targetGuid].expectingEA = false
-- Reset baseArmor so next cast captures fresh base (SuperWoW: GUID direct)
local freshArmor = UnitResistance(targetGuid, 0) or 0
curses.armorMonitor[targetGuid].prevArmor = freshArmor
curses.armorMonitor[targetGuid].baseArmor = freshArmor
if CursiveEADebug then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FFFF[EA REMOVED] baseArmor reset to "..freshArmor.."|r")
end
end
end
-- Also remove from guids display table
local spellData = nil
for sid, sd in pairs(debuffSpells) do
spellData = sd
break
end
if spellData and curses.guids[targetGuid] and curses.guids[targetGuid][spellData.name] then
-- Only remove if it was a shared debuff (not own)
if curses.guids[targetGuid][spellData.name].currentPlayer == false then
curses.guids[targetGuid][spellData.name] = nil
end
end
end
end
end
end
-- v3.2: Clean up expired shared debuffs from tracking tables
function curses:CleanupSharedDebuffs()
local now = GetTime()
-- v3.2.1 FIX: Clean up stale procExpected flags (>2s old)
for guid, keys in pairs(curses.procExpected) do
local empty = true
for key, timestamp in pairs(keys) do
if (now - timestamp) > 2.0 then
keys[key] = nil
else
empty = false
end
end
if empty then
curses.procExpected[guid] = nil
end
end
-- v4.0.4: Cleanup orphaned armorCache, lastProcStacks, playerOwnedCasts
for guid in pairs(curses.armorCache) do
if not UnitExists(guid) then curses.armorCache[guid] = nil end
end
for guid in pairs(curses.lastProcStacks) do
if not UnitExists(guid) then curses.lastProcStacks[guid] = nil end
end
for guid, casts in pairs(curses.playerOwnedCasts) do
if not UnitExists(guid) then
curses.playerOwnedCasts[guid] = nil
else
for key, ts in pairs(casts) do
if (now - ts) > 600 then casts[key] = nil end
end
end
end
for debuffKey, targets in pairs(curses.sharedDebuffGuids) do
local maxDuration = 0
-- Find the longest duration for this debuff type
if curses.sharedDebuffs[debuffKey] then
for _, spellData in pairs(curses.sharedDebuffs[debuffKey]) do
if spellData.duration and spellData.duration > maxDuration then
maxDuration = spellData.duration
end
end
end
-- Remove entries older than max duration + buffer
if maxDuration > 0 then
for targetGuid, data in pairs(targets) do
local appliedTime = data
-- v3.2: data can be a table {time=...} or a plain timestamp
if type(data) == "table" then
appliedTime = data.time or 0
end
if now - appliedTime > maxDuration + 5 then
targets[targetGuid] = nil
end
end
end
end
-- v3.2.1: Clean up armor cache alongside shared debuffs
curses:CleanupArmorCache()
end
Cursive:RegisterEvent("LEARNED_SPELL_IN_TAB", function()
-- reload curses in case spell slots changed
curses:LoadCurses()
end)
-- v3.2: Scan target debuffs when auras change (catches procs, direct casts, everything)
Cursive:RegisterEvent("UNIT_AURA", function()
-- v4.0.4: Skip entirely when no targets are tracked (e.g. idle in city)
if not next(Cursive.core.guids) then return end
local a1 = arg1
-- v4.0.6: Invalidate CC/Reflect cache for any unit whose auras changed
if a1 == "target" then
local _, targetGuid = UnitExists("target")
if targetGuid then
curses:InvalidateCCReflectCache(targetGuid)
-- v4.0.4: Debounce aura scans (coalesce burst events within 50ms)
curses._pendingAuraGuid = targetGuid
if not curses._pendingAuraScan then
curses._pendingAuraScan = true
Cursive:ScheduleEvent("CursiveAuraDebounce", function()
curses._pendingAuraScan = false
local guid = curses._pendingAuraGuid
if guid and UnitExists(guid) then
curses:ScanTargetForSharedDebuffs(guid)
end
end, 0.05)
end
-- Armor monitor still immediate (rare, targeted)
if curses.armorMonitor[targetGuid] and curses.armorMonitor[targetGuid].expectingEA then
curses:CheckArmorChangeForEA(targetGuid)
end
end
end
end)
-- v3.2: Also scan when target changes
Cursive:RegisterEvent("PLAYER_TARGET_CHANGED", function()
local _, targetGuid = UnitExists("target")
if targetGuid then
curses:ScanTargetForSharedDebuffs(targetGuid)
end
end)
-- Finalize Dark Harvest reduction when channeling stops
local function FinalizeDarkHarvest()
if curses.darkHarvestData.targetGuid then
local targetGuid = curses.darkHarvestData.targetGuid
local dhEndTime = GetTime()
if curses.guids[targetGuid] then
for curseName, curseData in pairs(curses.guids[targetGuid]) do
if curseData.dhStartTime then
-- Calculate how long DH was active for this DoT
local dhActiveTime = dhEndTime - curseData.dhStartTime
-- Add 40% of that time as extra reduction (1.4x speed = 0.4 extra per second)
curseData.dhAccumulatedReduction = (curseData.dhAccumulatedReduction or 0) + (dhActiveTime * 0.4)
curseData.dhStartTime = nil
end
end
end
curses.darkHarvestData = {}
end
end
local function StopChanneling()
FinalizeDarkHarvest()
curses.isChanneling = false
-- v4.0.4: Cancel any pending channel proc scan timers
for _, scanID in ipairs(curses.channelProcScanIDs) do
if Cursive:IsEventScheduled(scanID) then
Cursive:CancelScheduledEvent(scanID)
end
end
curses.channelProcScanIDs = {}
end
-- v3.2.1: Update armor cache for a GUID (called from ui.lua OnUpdate)
function curses:UpdateArmorCache(guid)
if not curses.armorCache then curses.armorCache = {} end
if not UnitResistance then return end
if IsTestGuid(guid) then
-- v4.0: Fake armor data for Test Overlay
local entry = curses.armorCache[guid]
if not entry then
local fakeTotal = math.random(3000, 6000)
local fakeReduced = math.random(500, 2000)
local fakeLive = fakeTotal - fakeReduced
curses.armorCache[guid] = { live = fakeLive, total = fakeTotal }
end
return
end
local _, effective = UnitResistance(guid, 0)
if not effective then return end
effective = math.max(0, effective)
local entry = curses.armorCache[guid]
if not entry then
curses.armorCache[guid] = { live = effective, total = effective }
else
entry.live = effective
if effective > entry.total then