-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCursiveTankTarget.lua
More file actions
964 lines (849 loc) · 31.4 KB
/
Copy pathCursiveTankTarget.lua
File metadata and controls
964 lines (849 loc) · 31.4 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
-- CursiveTankTarget 3.2.2-hf11 (Turtle-WoW compatible)
-- Change: Added Puppeteer and pfUI integration - automatically reads tanks from both addons' role assignments
-- Keeps: Assist primary/fallback cast, spam suppression, clutch2 + Weakened Soul, parser fixes, per-character settings, Clutch skips tanks.
local _G = getfenv(0)
local ADDON_VERSION = "3.2.2-hf11"
-- ===== Per-character settings =====
local S -- alias to ctt_settings after VARIABLES_LOADED
local function CTT_Defaults()
return {
tanks = {}, -- [name]=true
guidonly = false,
debug = false,
scale = 1.25,
assistrange = "near", -- "near" or "far"
assistspell = "", -- primary assist spell
assistspell2 = "", -- fallback assist spell
clutchspell = "",
clutchspell2 = "", -- fallback spell
arrowoffset = 0, -- pixels; 0 = align flush with Cursive bar edge
}
end
local function CTT_DeepCopy(src)
if type(src) ~= "table" then return src end
local t = {}
for k,v in pairs(src) do t[k] = CTT_DeepCopy(v) end
return t
end
local function EnsureDefaults()
if type(ctt_settings) ~= "table" then
ctt_settings = CTT_Defaults()
else
local d = CTT_Defaults()
for k,v in pairs(d) do if ctt_settings[k] == nil then ctt_settings[k] = CTT_DeepCopy(v) end end
end
S = ctt_settings
end
local evt = CreateFrame("Frame")
evt:RegisterEvent("VARIABLES_LOADED")
evt:SetScript("OnEvent", function()
if event == "VARIABLES_LOADED" then
EnsureDefaults()
end
end)
-- ===== Addon Integration =====
local function CTT_IsPuppeteerLoaded()
return (_G.Puppeteer ~= nil and
_G.Puppeteer.AssignedRoles ~= nil and
type(_G.Puppeteer.GetAssignedRole) == "function")
end
local function CTT_GetPuppeteerTanks()
if not CTT_IsPuppeteerLoaded() then return {} end
local tanks = {}
for name, data in pairs(_G.Puppeteer.AssignedRoles) do
if type(data) == "table" and data.role == "Tank" then
tanks[name] = true
end
end
return tanks
end
local function CTT_IsPfUILoaded()
return (_G.pfUI ~= nil and
_G.pfUI.uf ~= nil and
_G.pfUI.uf.raid ~= nil and
_G.pfUI.uf.raid.tankrole ~= nil)
end
local function CTT_GetPfUITanks()
if not CTT_IsPfUILoaded() then return {} end
local tanks = {}
for name, istank in pairs(_G.pfUI.uf.raid.tankrole) do
if istank then
tanks[name] = true
end
end
return tanks
end
local function CTT_GetCombinedTanks()
local combined = {}
-- First, add manually configured tanks
if S and S.tanks then
for name, _ in pairs(S.tanks) do
combined[name] = "manual"
end
end
-- Then, add tanks from Puppeteer (if available)
if CTT_IsPuppeteerLoaded() then
for name, _ in pairs(CTT_GetPuppeteerTanks()) do
if not combined[name] then
combined[name] = "puppeteer"
end
end
end
-- Finally, add tanks from pfUI (if available)
if CTT_IsPfUILoaded() then
for name, _ in pairs(CTT_GetPfUITanks()) do
if not combined[name] then
combined[name] = "pfui"
end
end
end
return combined
end
-- ===== Utilities =====
local function CTT_Print(msg) DEFAULT_CHAT_FRAME:AddMessage("|cffff2020[CTT]|r "..msg) end
local function tlen(a)
if type(a) ~= "table" then return 0 end
if table.getn then return table.getn(a) end
local n = 0
while true do n = n + 1; if a[n] == nil then return n-1 end end
end
local function Help()
local scale_txt = (S and S.scale) or 1.25
local range_txt = (S and S.assistrange) or "near"
local guid_txt = (S and S.guidonly) and "ON" or "OFF"
local assist1 = (S and S.assistspell and S.assistspell ~= "" and S.assistspell) or "none"
local assist2 = (S and S.assistspell2 and S.assistspell2 ~= "" and S.assistspell2) or "none"
local clutch = (S and S.clutchspell and S.clutchspell ~= "" and S.clutchspell) or "none"
local clutch2 = (S and S.clutchspell2 and S.clutchspell2 ~= "" and S.clutchspell2) or "none"
local aofs = (S and S.arrowoffset) or 0
local puppet_txt = CTT_IsPuppeteerLoaded() and "LOADED" or "not loaded"
local pfui_txt = CTT_IsPfUILoaded() and "LOADED" or "not loaded"
CTT_Print("CursiveTankTarget v"..ADDON_VERSION.." (3.2.2 base)")
CTT_Print("Settings: guidonly="..guid_txt.." assist="..range_txt.." scale="..tostring(scale_txt).." arrowoffset="..tostring(aofs))
CTT_Print(" assist='"..assist1.."' assist2='"..assist2.."' clutch='"..clutch.."' clutch2='"..clutch2.."' (Clutch skips tanks)")
CTT_Print(" Puppeteer: "..puppet_txt.." | pfUI: "..pfui_txt.." (tanks auto-imported if available)")
CTT_Print("Commands:")
CTT_Print(" /ctt add | remove | clear | list | guidonly [on|off] | debug | debug pt")
CTT_Print(" /ctt assist (use saved near/far; target; then cast assist spell if ready)")
CTT_Print(" /ctt assist near|far (sets preference, then runs assist)")
CTT_Print(" /ctt assist <Spell Name> (save primary assist spell only)")
CTT_Print(" /ctt assist2 <Spell Name> (save fallback assist spell only)")
CTT_Print(" /ctt scale <factor> (e.g., 1.25)")
CTT_Print(" /ctt arrowoffset <px> (0 aligns flush; positive nudges outward)")
CTT_Print(" /ctt clutch [<Spell Name>] (save only when given; cast when no args)")
CTT_Print(" /ctt clutch2 <Spell Name> (set fallback spell only; casting still uses /ctt clutch)")
CTT_Print(" Saved per character in 'ctt_settings'.")
end
-- ===== Roster (friendly name -> unit) =====
local roster, rosterTick = {}, 0
local function BuildRoster()
local now = GetTime()
if now < rosterTick then return end
rosterTick = now + 0.5
for k in pairs(roster) do roster[k] = nil end
local n = UnitName("player"); if n then roster[n] = "player" end
for i=1,4 do
local u = "party"..i
if UnitExists(u) then
local nm = UnitName(u); if nm then roster[nm] = u end
local p = u.."pet"; if UnitExists(p) then local pn = UnitName(p); if pn then roster[pn] = p end end
end
end
for i=1,40 do
local u = "raid"..i
if UnitExists(u) then
local nm = UnitName(u); if nm then roster[nm] = u end
local p = u.."pet"; if UnitExists(p) then local pn = UnitName(p); if pn then roster[pn] = p end end
end
end
end
-- ===== Mob target resolution from a Cursive unitFrame =====
local function GetMobTargetName(frame)
if not frame then return nil, "none" end
if S and S.guidonly then
local guid = frame.guid
if guid and UnitExists and UnitExists(guid) and UnitExists(guid.."target") then
return UnitName(guid.."target"), "guid"
end
return nil, "guidonly"
end
local unit = frame.unit or frame.unitToken
if unit and UnitExists and UnitExists(unit) and UnitExists(unit.."target") then
return UnitName(unit.."target"), "unit"
end
local guid = frame.guid
if guid and UnitExists and UnitExists(guid) and UnitExists(guid.."target") then
return UnitName(guid.."target"), "guid"
end
if frame.target_left and frame.target_left:IsShown() and UnitExists and UnitExists("targettarget") then
return UnitName("targettarget"), "player-target"
end
return nil, "none"
end
_G.CTT_GetMobTargetName = GetMobTargetName -- Expose globally for external addons
-- ===== Frame registry for fallback scans =====
local CTT_Frames = {}
_G.CTT_Frames = CTT_Frames -- Expose globally for external addons
local function CTT_RegisterFrame(frame)
if not frame or frame.cttReg then return end
table.insert(CTT_Frames, frame)
frame.cttReg = true
end
-- ===== Distance helpers for Assist sorting =====
local function CTT_GetDistanceTo(frame)
if type(UnitXP) ~= "function" then return nil end
local unit = frame and (frame.unit or frame.unitToken)
if unit and UnitExists and UnitExists(unit) then
local ok, d = pcall(UnitXP, "distanceBetween", "player", unit)
if ok and type(d) == "number" then return d end
end
local guid = frame and frame.guid
if guid then
local ok, d = pcall(UnitXP, "distanceBetween", "player", guid)
if ok and type(d) == "number" then return d end
end
return nil
end
-- ===== Spellbook helpers =====
local function CTT_StripRank(spell)
if not spell then return "" end
local s = string.gsub(spell, "%s*%(%s*[Rr]ank%s*%d+%s*%)", "")
s = string.gsub(s, "%s*%(%s*[Rr]ank%s*%d+%s*%-%s*%d+%s*%)", "")
s = string.gsub(s, "%s*%(%s*[Rr]ank%s*%d+%s*%a*%s*%)", "")
s = string.gsub(s, "%s*%(%s*[Rr]ank%s*%d+%s*$", "")
return s
end
local function CTT_FindSpellIndexByName(spellName)
if not spellName or spellName == "" then return nil end
local base = CTT_StripRank(spellName)
local tabs = GetNumSpellTabs and GetNumSpellTabs() or 0
local bestIndex, bestRankNum = nil, -1
for t=1,tabs do
local name, texture, offset, numSpells = GetSpellTabInfo(t)
local start = offset + 1
local endi = offset + numSpells
for i = start, endi do
local nm, rk = GetSpellName(i, "spell")
if nm then
local nmBase = CTT_StripRank(nm)
if string.lower(nmBase) == string.lower(base) then
local rnum = 0
if rk then
local digits = string.gsub(rk, "%D", "")
if digits ~= "" then rnum = tonumber(digits) or 0 end
end
if rnum >= bestRankNum then
bestRankNum = rnum
bestIndex = i
end
end
end
end
end
return bestIndex
end
local function CTT_IsSpellReadyByName(spellName)
local idx = CTT_FindSpellIndexByName(spellName)
if not idx then return false end
local start, duration, enable = GetSpellCooldown(idx, "spell")
if not start or not duration then return true end
if start == 0 or duration == 0 then return true end
local now = GetTime and GetTime() or 0
if (start + duration - now) <= 0 then return true end
return false
end
-- ===== generic frame scanner =====
local function CTT_ScanFrames(consider_cb)
local ui = _G.ui
local used = 0
if ui and ui.unitFrames then
local cols = {}
for c,_ in pairs(ui.unitFrames) do table.insert(cols, c) end
table.sort(cols, function(a,b) return (tonumber(a) or 0) < (tonumber(b) or 0) end)
for _, c in ipairs(cols) do
local rows = ui.unitFrames[c]
if rows then
local rks = {}
for r,_ in pairs(rows) do table.insert(rks, r) end
table.sort(rks, function(a,b) return (tonumber(a) or 0) < (tonumber(b) or 0) end)
for _, r in ipairs(rks) do consider_cb(rows[r]); used = used + 1 end
end
end
end
if used == 0 then
local n = tlen(CTT_Frames)
for i=1,n do consider_cb(CTT_Frames[i]) end
end
end
-- ===== Assist spell casting =====
local function CTT_AssistTryCast()
if not S then return end
local primary = S.assistspell or ""
local backup = S.assistspell2 or ""
if primary ~= "" and CTT_IsSpellReadyByName(primary) then
CastSpellByName(primary)
if S.debug then CTT_Print("Assist casting '"..primary.."'") end
return
end
if backup ~= "" and CTT_IsSpellReadyByName(backup) then
CastSpellByName(backup)
if S.debug then CTT_Print("Assist casting backup '"..backup.."'") end
return
end
-- otherwise, just targeting is fine per request
end
-- ===== Assist main =====
function CTT_Assist()
EnsureDefaults()
local mode = S.assistrange or "near"
local candidates = {}
local function consider_frame(frame)
if not frame or not frame.IsShown or not frame:IsShown() then return end
local tname, via = GetMobTargetName(frame)
local combinedTanks = CTT_GetCombinedTanks()
if tname and not combinedTanks[tname] then
local d = CTT_GetDistanceTo(frame) -- yards or nil
local idx = tlen(candidates)
candidates[idx+1] = { frame=frame, dist=d, via=via }
if S.debug then
local nm = frame.nameText and frame.nameText:GetText() or "(noname)"
CTT_Print("assist-cand nm="..tostring(nm).." target="..tostring(tname).." dist="..tostring(d).." via="..tostring(via))
end
end
end
CTT_ScanFrames(consider_frame)
local n = tlen(candidates)
if n == 0 then return end -- no spam
local pick_i = 1
local have_dist = false
for i=1,n do if type(candidates[i].dist) == "number" then have_dist = true; break end end
if have_dist then
local best_d = candidates[1].dist
pick_i = 1
for i=2,n do
local d = candidates[i].dist
if type(d) == "number" then
if mode == "near" then
if type(best_d) ~= "number" or d < best_d then best_d = d; pick_i = i end
else
if type(best_d) ~= "number" or d > best_d then best_d = d; pick_i = i end
end
end
end
else
if mode == "far" then pick_i = n else pick_i = 1 end
end
local frame = candidates[pick_i].frame
if frame.guid and UnitExists and UnitExists(frame.guid) then
TargetUnit(frame.guid)
if S.debug then CTT_Print("Assist("..mode.."): TargetUnit(guid)") end
CTT_AssistTryCast()
return
elseif frame.unit and UnitExists and UnitExists(frame.unit) then
TargetUnit(frame.unit)
if S.debug then CTT_Print("Assist("..mode.."): TargetUnit(unit)") end
CTT_AssistTryCast()
return
else
local nm = frame.nameText and frame.nameText:GetText()
if nm and nm ~= "" then
TargetByName(nm)
if S.debug then CTT_Print("Assist("..mode.."): TargetByName("..nm..")") end
CTT_AssistTryCast()
return
end
end
end
-- ===== Clutch helpers =====
local function CTT_GetUnitDistance(unit)
if type(UnitXP) ~= "function" then return nil end
local ok, d = pcall(UnitXP, "distanceBetween", "player", unit)
if ok and type(d) == "number" then return d end
return nil
end
local function CTT_HasLOS(unit)
if type(UnitXP) ~= "function" then return nil end
local ok, res = pcall(UnitXP, "inSight", "player", unit)
if ok then return (res and true or false) end
return nil
end
local WEAKENED_SOUL_ID = 6788
local function CTT_HasDebuff_WS(unit)
for i=1,16 do
local n, _, _, spellId = UnitDebuff(unit, i)
if spellId then
if spellId == WEAKENED_SOUL_ID then return true end
elseif n then
if string.lower(n) == "weakened soul" then return true end
else
break
end
end
return false
end
local function CTT_IsSpellReadyByName_Clutch(spellName) return CTT_IsSpellReadyByName(spellName) end
local function CTT_ShouldUseFallback(primaryName, unit)
if not primaryName or primaryName == "" then return true end
local pReady = CTT_IsSpellReadyByName_Clutch(primaryName)
if not pReady then return true end
local low = string.lower(primaryName)
if string.find(low, "power word:%s*shield") then
if CTT_HasDebuff_WS(unit) then return true end
end
return false
end
local function CTT_CastBestClutchSpellOn(unit)
local primary = (S and S.clutchspell) or ""
local fallback = (S and S.clutchspell2) or ""
local useFallback = CTT_ShouldUseFallback(primary, unit)
local spellToCast = primary
if useFallback and fallback ~= "" then
if CTT_IsSpellReadyByName_Clutch(fallback) then
spellToCast = fallback
else
spellToCast = primary
end
end
CastSpellByName(spellToCast)
if S and S.debug then CTT_Print("Clutch casting '"..spellToCast.."' (primary='"..primary.."', fallback='"..fallback.."')") end
end
function CTT_Clutch()
EnsureDefaults()
if not (S and S.clutchspell) or S.clutchspell == "" then
CTT_Print("Clutch: no spell configured. Use /ctt clutch <Spell Name>")
return
end
BuildRoster()
local candidates = {}
local function consider_frame(frame)
if not frame or not frame.IsShown or not frame:IsShown() then return end
local tname, via = GetMobTargetName(frame)
if not tname then return end
local unit = roster[tname]
if not unit or not UnitExists or not UnitExists(unit) then return end
if UnitIsDeadOrGhost and UnitIsDeadOrGhost(unit) then return end
if UnitIsFriend and not UnitIsFriend("player", unit) then return end
-- Skip tanks (do not clutch-cast on designated tanks)
local combinedTanks = CTT_GetCombinedTanks()
local uname = UnitName(unit)
if uname and combinedTanks[uname] then return end
local hp = (UnitHealth and UnitHealth(unit)) or 0
local hm = (UnitHealthMax and UnitHealthMax(unit)) or 1
if hm <= 0 then hm = 1 end
local pct = (hp * 100.0) / hm
local d = CTT_GetUnitDistance(unit) -- yards or nil
local los = CTT_HasLOS(unit) -- true/false or nil
if d ~= nil and d > 40.5 then return end
if los ~= nil and los ~= true then return end
local idx = tlen(candidates)
candidates[idx+1] = { unit = unit, pct = pct, dist = d, los = los }
if S and S.debug then
CTT_Print(string.format("clutch-cand unit=%s (%.1f%%) dist=%s los=%s", tostring(unit), pct, tostring(d), tostring(los)))
end
end
-- scan frames
local ui = _G.ui
local used = 0
if ui and ui.unitFrames then
local cols = {}
for c,_ in pairs(ui.unitFrames) do table.insert(cols, c) end
table.sort(cols, function(a,b) return (tonumber(a) or 0) < (tonumber(b) or 0) end)
for _, c in ipairs(cols) do
local rows = ui.unitFrames[c]
if rows then
local rks = {}
for r,_ in pairs(rows) do table.insert(rks, r) end
table.sort(rks, function(a,b) return (tonumber(a) or 0) < (tonumber(b) or 0) end)
for _, r in ipairs(rks) do consider_frame(rows[r]); used = used + 1 end
end
end
end
if used == 0 then
local n = tlen(CTT_Frames)
for i=1,n do consider_frame(CTT_Frames[i]) end
end
local n = tlen(candidates)
if n == 0 then return end -- no spam
local best_i = 1
local best_pct = candidates[1].pct
for i=2,n do
local p = candidates[i].pct
if p < best_pct then best_pct = p; best_i = i end
end
local chosen = candidates[best_i]
TargetUnit(chosen.unit)
CTT_CastBestClutchSpellOn(chosen.unit)
end
-- ===== Slash =====
if type(_G.SlashCmdList) ~= "table" then _G.SlashCmdList = {} end
_G.SLASH_CURSIVETANKTARGET1 = "/ctt"
_G.SlashCmdList["CURSIVETANKTARGET"] = function(msg)
msg = tostring(msg or "")
msg = string.lower(msg)
msg = string.gsub(msg, "^%s+", "")
msg = string.gsub(msg, "%s+$", "")
-- assist2 fallback setter (check BEFORE assist to avoid "assist2" matching "assist ...")
do
local s,e,rest = string.find(msg, "^assist2%s+(.+)$")
if s then
local arg = rest
EnsureDefaults()
S.assistspell2 = arg
CTT_Print("Assist fallback spell set to: "..arg)
return
end
end
-- assist handler: near/far/setter/run
do
if msg == "assist" then CTT_Assist(); return end
local s1,e1,mode = string.find(msg, "^assist%s+(near)$")
if s1 then
EnsureDefaults(); S.assistrange = "near"; CTT_Print("Assist preference set to near."); CTT_Assist(); return
end
local s2,e2,mode2 = string.find(msg, "^assist%s+(far)$")
if s2 then
EnsureDefaults(); S.assistrange = "far"; CTT_Print("Assist preference set to far."); CTT_Assist(); return
end
local s3,e3,spell = string.find(msg, "^assist%s+(.+)$")
if s3 then
EnsureDefaults(); S.assistspell = spell; CTT_Print("Assist primary spell set to: "..spell); return
end
end
-- scale
do
local s,e,num = string.find(msg, "^scale%s+([%d%.]+)$")
if s then
EnsureDefaults()
local f = tonumber(num)
if f and f > 0.25 and f <= 5.0 then
S.scale = f
CTT_Print("Scale set to "..string.format("%.2f", S.scale))
else
CTT_Print("Scale must be between 0.25 and 5.0")
end
return
end
end
-- arrowoffset
do
local s,e,num = string.find(msg, "^arrowoffset%s+([%-]?%d+)$")
if s then
EnsureDefaults()
local px = tonumber(num) or 0
if px < -64 then px = -64 end
if px > 64 then px = 64 end
S.arrowoffset = px
CTT_Print("Arrow offset set to "..tostring(px).." px.")
return
end
end
-- clutch2 setter
do
local s,e,rest = string.find(msg, "^clutch2%s+(.+)$")
if s then
local spell = rest
EnsureDefaults()
S.clutchspell2 = spell
CTT_Print("Clutch2 (fallback) set to: "..spell.." (casting still uses /ctt clutch)")
return
end
end
-- clutch setter or cast
do
if msg == "clutch" then CTT_Clutch(); return end
local s,e,rest = string.find(msg, "^clutch%s+(.+)$")
if s then
local spell = rest
EnsureDefaults()
S.clutchspell = spell
CTT_Print("Clutch spell set to: "..spell.." (use /ctt clutch to cast)")
return
end
end
if msg == "debug" then
EnsureDefaults()
S.debug = not S.debug
CTT_Print("Debug "..((S.debug and "ON") or "OFF"))
return
end
if msg == "debug pt" or msg == "debugpt" then
CTT_Print("=== Addon Integration Debug ===")
-- Puppeteer
CTT_Print("-- Puppeteer --")
CTT_Print("_G.Puppeteer exists: "..tostring(_G.Puppeteer ~= nil))
CTT_Print("_G.Puppeteer.AssignedRoles exists: "..tostring(_G.Puppeteer and _G.Puppeteer.AssignedRoles ~= nil or false))
CTT_Print("_G.Puppeteer.GetAssignedRole type: "..tostring(type(_G.Puppeteer and _G.Puppeteer.GetAssignedRole or nil)))
CTT_Print("CTT_IsPuppeteerLoaded(): "..tostring(CTT_IsPuppeteerLoaded()))
if _G.Puppeteer and _G.Puppeteer.AssignedRoles then
CTT_Print("Puppeteer.AssignedRoles table contents:")
local count = 0
for name, data in pairs(_G.Puppeteer.AssignedRoles) do
count = count + 1
local role = (type(data) == "table" and data.role) or tostring(data)
local lastSeen = (type(data) == "table" and data.lastSeen) or "N/A"
CTT_Print(" ["..name.."] role='"..tostring(role).."' lastSeen="..tostring(lastSeen))
end
if count == 0 then
CTT_Print(" (empty table)")
end
end
local puppeteerTanks = CTT_GetPuppeteerTanks()
CTT_Print("Puppeteer tanks found:")
local ptCount = 0
for name, _ in pairs(puppeteerTanks) do
ptCount = ptCount + 1
CTT_Print(" "..name)
end
if ptCount == 0 then
CTT_Print(" (none)")
end
-- pfUI
CTT_Print("-- pfUI --")
CTT_Print("_G.pfUI exists: "..tostring(_G.pfUI ~= nil))
CTT_Print("_G.pfUI.uf exists: "..tostring(_G.pfUI and _G.pfUI.uf ~= nil or false))
CTT_Print("_G.pfUI.uf.raid exists: "..tostring(_G.pfUI and _G.pfUI.uf and _G.pfUI.uf.raid ~= nil or false))
CTT_Print("_G.pfUI.uf.raid.tankrole exists: "..tostring(_G.pfUI and _G.pfUI.uf and _G.pfUI.uf.raid and _G.pfUI.uf.raid.tankrole ~= nil or false))
CTT_Print("CTT_IsPfUILoaded(): "..tostring(CTT_IsPfUILoaded()))
if _G.pfUI and _G.pfUI.uf and _G.pfUI.uf.raid and _G.pfUI.uf.raid.tankrole then
CTT_Print("pfUI.uf.raid.tankrole table contents:")
local count = 0
for name, istank in pairs(_G.pfUI.uf.raid.tankrole) do
count = count + 1
CTT_Print(" ["..name.."] = "..tostring(istank))
end
if count == 0 then
CTT_Print(" (empty table)")
end
end
local pfuiTanks = CTT_GetPfUITanks()
CTT_Print("pfUI tanks found:")
local pfCount = 0
for name, _ in pairs(pfuiTanks) do
pfCount = pfCount + 1
CTT_Print(" "..name)
end
if pfCount == 0 then
CTT_Print(" (none)")
end
CTT_Print("Manual tanks:")
if S and S.tanks and next(S.tanks) then
for name, _ in pairs(S.tanks) do
CTT_Print(" "..name)
end
else
CTT_Print(" (none)")
end
local combined = CTT_GetCombinedTanks()
CTT_Print("Combined tanks list:")
local combCount = 0
for name, source in pairs(combined) do
combCount = combCount + 1
CTT_Print(" "..name.." ("..source..")")
end
if combCount == 0 then
CTT_Print(" (none)")
end
return
end
if msg == "guidonly" or string.find(msg, "^guidonly%s+") then
EnsureDefaults()
local s,e,flag = string.find(msg, "^guidonly%s*([%a_]*)$")
if flag == "on" then S.guidonly = true
elseif flag == "off" then S.guidonly = false
else S.guidonly = not S.guidonly end
CTT_Print("GUID-only is now "..((S.guidonly and "ON") or "OFF"))
return
end
if msg == "add" then
EnsureDefaults()
if UnitExists("target") then
local name = UnitName("target")
if name then S.tanks[name] = true; CTT_Print("Added tank: "..name) else CTT_Print("Target has no resolvable name.") end
else CTT_Print("No target selected.") end
return
end
if msg == "remove" then
EnsureDefaults()
if UnitExists("target") then
local name = UnitName("target")
if name and S.tanks[name] then S.tanks[name] = nil; CTT_Print("Removed tank: "..name) else CTT_Print("Target not in tank list.") end
else CTT_Print("No target selected.") end
return
end
if msg == "clear" then
EnsureDefaults()
S.tanks = {}; CTT_Print("Tank list cleared.")
return
end
if msg == "list" then
EnsureDefaults()
local combinedTanks = CTT_GetCombinedTanks()
CTT_Print("Tanks:")
if not next(combinedTanks) then
DEFAULT_CHAT_FRAME:AddMessage(" (empty)")
else
for n, source in pairs(combinedTanks) do
if source == "manual" then
DEFAULT_CHAT_FRAME:AddMessage(" "..n.." (manual)")
elseif source == "puppeteer" then
DEFAULT_CHAT_FRAME:AddMessage(" "..n.." (from Puppeteer)")
elseif source == "pfui" then
DEFAULT_CHAT_FRAME:AddMessage(" "..n.." (from pfUI)")
end
end
end
return
end
Help()
end
-- ===== Primary indicator overlay (inverse of Cursive's target icon) =====
if not _G.CTT_Orig_CreateBarFirstSection then _G.CTT_Orig_CreateBarFirstSection = _G.CreateBarFirstSection end
_G.CreateBarFirstSection = function(unitFrame, guid)
if type(_G.CTT_Orig_CreateBarFirstSection) == "function" then _G.CTT_Orig_CreateBarFirstSection(unitFrame, guid) end
EnsureDefaults()
local firstSection = unitFrame.firstSection or unitFrame
local TEX_LEFT = "Interface\\AddOns\\Cursive\\img\\target-left"
local TEX_RIGHT = "Interface\\AddOns\\Cursive\\img\\target-right"
if not unitFrame.cttIndLeft then
local t = firstSection:CreateTexture(nil, "OVERLAY", nil, 7)
t:SetTexture(TEX_LEFT)
t:SetVertexColor(1.0, 0.1, 0.1) -- red tint
t:Hide()
unitFrame.cttIndLeft = t
end
if not unitFrame.cttIndRight then
local t = firstSection:CreateTexture(nil, "OVERLAY", nil, 7)
t:SetTexture(TEX_RIGHT)
t:SetVertexColor(1.0, 0.1, 0.1) -- red tint
t:Hide()
unitFrame.cttIndRight = t
end
-- Green arrows for "on tank but not me"
if not unitFrame.cttIndLeftGreen then
local t = firstSection:CreateTexture(nil, "OVERLAY", nil, 7)
t:SetTexture(TEX_LEFT)
t:SetVertexColor(0.1, 1.0, 0.1) -- green tint
t:Hide()
unitFrame.cttIndLeftGreen = t
end
if not unitFrame.cttIndRightGreen then
local t = firstSection:CreateTexture(nil, "OVERLAY", nil, 7)
t:SetTexture(TEX_RIGHT)
t:SetVertexColor(0.1, 1.0, 0.1) -- green tint
t:Hide()
unitFrame.cttIndRightGreen = t
end
local function currentBaseSize()
local b = 8
if _G.ui and _G.ui.targetIndicatorSize then b = _G.ui.targetIndicatorSize end
if unitFrame.target_left and unitFrame.target_left:GetWidth() then
local w = unitFrame.target_left:GetWidth()
if w and w > 0 then b = w end
end
return b, 8
end
local function applyScaleAndPoints()
local s = (S and S.scale) or 1.25
local ofs = (S and S.arrowoffset) or 0
local baseW, baseH = currentBaseSize()
local W = math.floor(baseW * s + 0.5)
local H = math.floor(baseH * s + 0.5)
if unitFrame.cttIndLeft then
unitFrame.cttIndLeft:SetWidth(W); unitFrame.cttIndLeft:SetHeight(H)
unitFrame.cttIndLeft:ClearAllPoints()
unitFrame.cttIndLeft:SetPoint("LEFT", unitFrame, "LEFT", -ofs, 0)
end
if unitFrame.cttIndRight then
unitFrame.cttIndRight:SetWidth(W); unitFrame.cttIndRight:SetHeight(H)
unitFrame.cttIndRight:ClearAllPoints()
unitFrame.cttIndRight:SetPoint("RIGHT", firstSection, "RIGHT", ofs, 0)
end
if unitFrame.cttIndLeftGreen then
unitFrame.cttIndLeftGreen:SetWidth(W); unitFrame.cttIndLeftGreen:SetHeight(H)
unitFrame.cttIndLeftGreen:ClearAllPoints()
unitFrame.cttIndLeftGreen:SetPoint("LEFT", unitFrame, "LEFT", -ofs, 0)
end
if unitFrame.cttIndRightGreen then
unitFrame.cttIndRightGreen:SetWidth(W); unitFrame.cttIndRightGreen:SetHeight(H)
unitFrame.cttIndRightGreen:ClearAllPoints()
unitFrame.cttIndRightGreen:SetPoint("RIGHT", firstSection, "RIGHT", ofs, 0)
end
end
applyScaleAndPoints()
unitFrame.cttIndAppliedScale = (S and S.scale) or 1.25
unitFrame.cttIndAppliedOfs = (S and S.arrowoffset) or 0
CTT_RegisterFrame(unitFrame)
if not unitFrame.cttIndUpdater then
unitFrame.cttIndUpdater = true
unitFrame.cttIndNext = 0
local prevOnUpdate = unitFrame.GetScript and unitFrame:GetScript("OnUpdate") or nil
unitFrame:SetScript("OnUpdate", function()
if prevOnUpdate then prevOnUpdate() end
local cur = (S and S.scale) or 1.25
local ofs = (S and S.arrowoffset) or 0
if unitFrame.cttIndAppliedScale ~= cur or unitFrame.cttIndAppliedOfs ~= ofs then
applyScaleAndPoints()
unitFrame.cttIndAppliedScale = cur
unitFrame.cttIndAppliedOfs = ofs
end
local now = GetTime()
if now < (unitFrame.cttIndNext or 0) then return end
unitFrame.cttIndNext = now + 0.25
local tname, via = GetMobTargetName(unitFrame)
local notTank = false
local onOtherTank = false
local combinedTanks = CTT_GetCombinedTanks()
if next(combinedTanks) and tname then
if combinedTanks[tname] then
-- Target IS on a tank - check if it's the player
local playerName = UnitName("player")
if playerName and tname ~= playerName then
onOtherTank = true
end
else
-- Target is NOT on any tank
notTank = true
end
end
local invbars = (Cursive and Cursive.db and Cursive.db.profile and Cursive.db.profile.invertbars) and true or false
-- Red arrows: target NOT on any tank
if notTank then
if invbars then
if unitFrame.cttIndLeft then unitFrame.cttIndLeft:Show() end
if unitFrame.cttIndRight then unitFrame.cttIndRight:Hide() end
else
if unitFrame.cttIndRight then unitFrame.cttIndRight:Show() end
if unitFrame.cttIndLeft then unitFrame.cttIndLeft:Hide() end
end
-- Hide green arrows
if unitFrame.cttIndLeftGreen then unitFrame.cttIndLeftGreen:Hide() end
if unitFrame.cttIndRightGreen then unitFrame.cttIndRightGreen:Hide() end
-- Green arrows: target IS on a tank but not the player
elseif onOtherTank then
if invbars then
if unitFrame.cttIndLeftGreen then unitFrame.cttIndLeftGreen:Show() end
if unitFrame.cttIndRightGreen then unitFrame.cttIndRightGreen:Hide() end
else
if unitFrame.cttIndRightGreen then unitFrame.cttIndRightGreen:Show() end
if unitFrame.cttIndLeftGreen then unitFrame.cttIndLeftGreen:Hide() end
end
-- Hide red arrows
if unitFrame.cttIndLeft then unitFrame.cttIndLeft:Hide() end
if unitFrame.cttIndRight then unitFrame.cttIndRight:Hide() end
-- No arrows: target is on player or no target at all
else
if unitFrame.cttIndLeft then unitFrame.cttIndLeft:Hide() end
if unitFrame.cttIndRight then unitFrame.cttIndRight:Hide() end
if unitFrame.cttIndLeftGreen then unitFrame.cttIndLeftGreen:Hide() end
if unitFrame.cttIndRightGreen then unitFrame.cttIndRightGreen:Hide() end
end
end)
end
end
-- ====== Lowercase keybind aliases (compat) ======
if not _G.ctt_assist then
function _G.ctt_assist() CTT_Assist() end
end
if not _G.ctt_clutch then
function _G.ctt_clutch() CTT_Clutch() end
end