-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathTargeting.lua
1235 lines (1021 loc) · 38.4 KB
/
Targeting.lua
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
local addonName, addon = ...
local fmt, tinsert, tremove, mmax = string.format, table.insert, table.remove,
math.max
local GetMacroInfo, CreateMacro, EditMacro, InCombatLockdown, GetNumMacros =
GetMacroInfo, CreateMacro, EditMacro, InCombatLockdown, GetNumMacros
local TargetUnit, UnitName, next, IsInRaid, UnitIsDead, UnitIsGroupLeader,
IsInGroup, UnitOnTaxi, UnitIsPlayer, UnitIsUnit = TargetUnit, UnitName,
next, IsInRaid,
UnitIsDead,
UnitIsGroupLeader,
IsInGroup, UnitOnTaxi,
UnitIsPlayer, UnitIsUnit
local GetRaidTargetIndex, SetRaidTarget = GetRaidTargetIndex, SetRaidTarget
local GetTime, FlashClientIcon, PlaySound = GetTime, FlashClientIcon, PlaySound
local wipe = wipe
local GetRealZoneText = GetRealZoneText
local GetNamePlates = C_NamePlate.GetNamePlates
local GameTooltip = _G.GameTooltip
local L = addon.locale.Get
addon.targeting = addon:NewModule("Targeting", "AceEvent-3.0")
addon.targeting.macroName = "RXPTargeting"
local announcedTargets = {}
local macroTargets = {}
local lowPrioTargets = {}
local proxmityPolling = {
frequency = 0.25,
match = false,
lastMatch = 0,
matchTimeout = 5,
scanData = {},
scannedTargets = {},
rareAnnounced = {}
}
local targetList = {}
local targetPlaceholder = 132150
local targetIcons = {
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_4.blp", -- Triangle
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_3.blp", -- Diamond
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_1.blp", -- Star
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_2.blp" -- Circle
}
local mobList = {}
local mobPlaceholder = 14144
local mobIcons = {
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_8.blp", -- Skull
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_7.blp", -- Cross
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_6.blp" -- Square
}
local unitscanList = {}
local unitscanPlaceholder = 132212
local unitscanIcons = {
"Interface\\TargetingFrame\\UI-RaidTargetingIcon_5.blp" -- Moon
}
local rareTargets = {}
function addon.targeting:Setup()
if not addon.settings.profile.enableTargetMacro then
DeleteMacro(self.macroName)
end
self:CreateTargetFrame()
self:RegisterEvent("PLAYER_REGEN_ENABLED")
-- Remove interacted target
self:RegisterEvent("GOSSIP_SHOW")
self:RegisterEvent("MERCHANT_SHOW")
self:RegisterEvent("QUEST_PROGRESS")
self:RegisterEvent("QUEST_GREETING")
self:RegisterEvent("QUEST_COMPLETE")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
if not addon.settings.profile.enableTargetAutomation then return end
-- TODO toggle without reloads
-- Only works when nameplates are enabled
self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
-- Increase nameplate scanning distance to max allowed
if addon.gameVersion > 40000 then
SetCVar("nameplateMaxDistance", "100")
else
SetCVar("nameplateMaxDistance", "41")
end
if addon.settings.profile.showTargetingOnProximity then
if addon.settings.profile and addon.settings.profile.updateFrequency then
proxmityPolling.frequency = addon.settings.profile.updateFrequency / 2000
end
self.ticker = C_Timer.NewTicker(proxmityPolling.frequency, self.CheckTargetProximity)
self:RegisterEvent("ADDON_ACTION_FORBIDDEN")
-- Prevent default forbidden UI popup
UIParent:UnregisterEvent("ADDON_ACTION_FORBIDDEN")
end
if addon.rares then
self:LoadRares()
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
end
end
local function shouldTargetCheck()
return not IsInRaid() and not UnitOnTaxi("player") and not addon.isCastingHS and
(next(unitscanList) ~= nil or next(mobList) ~= nil or
next(targetList) ~= nil or next(rareTargets) ~= nil or
next(proxmityPolling.scannedTargets) ~= nil)
end
local currentTargets = ""
local function AnnounceTargets()
if addon.settings.profile.notifyOnTargetUpdates then
addon.comms.PrettyPrint(L("Targeting macro updated with:%s"),currentTargets)
end
end
function addon.targeting:UpdateMacro(queuedTargets)
-- TODO add rare targets
if not addon.settings.profile.enableTargetMacro then return end
if not shouldTargetCheck() then return end
if InCombatLockdown() then
macroTargets = queuedTargets or macroTargets
return
end
local targets = queuedTargets or {}
if not GetMacroInfo(self.macroName) then
if not self:CanCreateMacro() then return end
CreateMacro(self.macroName, "Ability_eyeoftheowl", "")
end
for _, t in ipairs(unitscanList) do
if not lowPrioTargets[t] then tinsert(targets, t) end
end
for _, t in ipairs(mobList) do
if not lowPrioTargets[t] then tinsert(targets, t) end
end
for _, t in ipairs(targetList) do
if not lowPrioTargets[t] then tinsert(targets, t) end
end
for t in pairs(lowPrioTargets) do tinsert(targets, t) end
-- Removes duplicate entries:
local npcNames = {}
for i = #targets, 1, -1 do
local t = targets[i]
if npcNames[t] then
targets[i] = false
else
npcNames[t] = true
end
end
local content
local targetText = ""
for n = #targets,1,-1 do
local t = targets[n]
if t then
if content then
content = fmt('%s\n/targetexact %s', content, t)
else
content = fmt('/targetexact %s', t)
end
-- Prevent multiple spams
if not (announcedTargets[t] or lowPrioTargets[t]) and
addon.settings.profile.notifyOnTargetUpdates then
targetText = fmt("%s %s,",targetText,t)
end
announcedTargets[t] = true
if #content > 255 then
content = content:gsub("^\n?[^\n]*[\n]*", "")
end
end
end
if #targetText > 0 then
currentTargets = targetText:sub(1,-2)
addon.ScheduleTask(1.5,AnnounceTargets)
end
if content then
while #content > 230 do
content = content:gsub("^\n?[^\n]*[\n]*", "")
end
content = content .. '\n/targetlasttarget [dead]'
else
content = fmt('//%s - %s', addon.title,
L("current step has no configured targets")) -- TODO locale
end
EditMacro(self.macroName, self.macroName, nil, content)
if not addon.settings.profile.macroAnnounced and
addon.settings.profile.notifyOnTargetUpdates and next(targets) ~= nil then
C_Timer.After(1, function()
addon.comms.PrettyPrint(L(
"A macro has been automatically built to aid in leveling. Please move %s to your action bars."),
self.macroName)
end)
addon.settings.profile.macroAnnounced = true
end
macroTargets = {}
end
function addon.targeting:PLAYER_REGEN_ENABLED()
if macroTargets then
C_Timer.After(0.5, function() self:UpdateMacro(macroTargets) end)
end
self:UpdateTargetFrame()
end
function addon.targeting:CheckNameplate(nameplateID)
if not nameplateID then return end
local unitName = UnitName(nameplateID)
if not unitName then return end
if addon.settings.profile.enableFriendlyTargeting then
for i, name in ipairs(targetList) do
if name == unitName then
self:UpdateTargetFrame(nameplateID)
if addon.settings.profile.enableTargetMarking then
self:UpdateMarker("friendly", nameplateID, i)
end
end
end
end
if addon.settings.profile.enableEnemyTargeting then
for i, name in ipairs(mobList) do
if name == unitName then
self:UpdateTargetFrame(nameplateID)
if addon.settings.profile.enableMobMarking then
self:UpdateMarker("mob", nameplateID, i)
end
end
end
for i, name in ipairs(unitscanList) do
if name == unitName then
self:UpdateTargetFrame(nameplateID)
if addon.settings.profile.flashOnFind then
FlashClientIcon()
end
if addon.settings.profile.enableTargetingFlash then
addon.tips:EnableDangerWarning(1)
end
if addon.settings.profile.enableEnemyMarking then
self:UpdateMarker("unitscan", nameplateID, i)
end
end
end
end
if addon.settings.profile.scanForRares then
for _, name in ipairs(rareTargets) do
if name == unitName then
self:UpdateTargetFrame(nameplateID)
if addon.settings.profile.flashOnFind then
FlashClientIcon()
end
if addon.settings.profile.enableTargetingFlash then
addon.tips:EnableDangerWarning(1)
end
if addon.settings.profile.enableEnemyMarking then
-- Steal moon, lowest of enemies for mark
self:UpdateMarker("rare", nameplateID, 4)
end
end
end
end
end
function addon.targeting:CheckNameplates()
local nameplatesArray = GetNamePlates()
if not nameplatesArray then return end
for _, nameplate in ipairs(nameplatesArray) do
self:CheckNameplate(nameplate.namePlateUnitToken)
end
end
function addon.targeting:NAME_PLATE_UNIT_ADDED(_, nameplateID)
if not nameplateID or not shouldTargetCheck() then return end
self:CheckNameplate(nameplateID)
end
function addon.targeting:UPDATE_MOUSEOVER_UNIT()
if not shouldTargetCheck() then return end
local kind = "mouseover"
local unitName = UnitName(kind)
if not unitName then return end
if addon.settings.profile.enableFriendlyTargeting then
for i, name in ipairs(targetList) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.enableTargetMarking then
self:UpdateMarker("friendly", kind, i)
end
end
end
end
if addon.settings.profile.enableEnemyTargeting then
for i, name in ipairs(mobList) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.enableMobMarking then
self:UpdateMarker("mob", kind, i)
end
end
end
for i, name in ipairs(unitscanList) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.flashOnFind then
FlashClientIcon()
end
if addon.settings.profile.enableTargetingFlash then
addon.tips:EnableDangerWarning(1)
end
if addon.settings.profile.enableEnemyMarking then
self:UpdateMarker("unitscan", kind, i)
end
end
end
end
if addon.settings.profile.scanForRares then
for _, name in ipairs(rareTargets) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.flashOnFind then
FlashClientIcon()
end
if addon.settings.profile.enableTargetingFlash then
addon.tips:EnableDangerWarning(1)
end
if addon.settings.profile.enableEnemyMarking then
-- Steal moon, lowest of enemies for mark
self:UpdateMarker("rare", kind, 4)
end
end
end
end
end
function addon.targeting:PLAYER_TARGET_CHANGED()
if not shouldTargetCheck() then return end
local kind = "target"
local unitName = UnitName(kind)
if not unitName then return end
if addon.settings.profile.enableFriendlyTargeting then
for i, name in ipairs(targetList) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.enableTargetMarking then
self:UpdateMarker("friendly", kind, i)
end
end
end
end
if addon.settings.profile.enableEnemyTargeting then
for i, name in ipairs(mobList) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.enableMobMarking then
self:UpdateMarker("mob", kind, i)
end
end
end
for i, name in ipairs(unitscanList) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.enableEnemyMarking then
self:UpdateMarker("unitscan", kind, i)
end
end
end
end
if addon.settings.profile.scanForRares then
for _, name in ipairs(rareTargets) do
if name == unitName then
self:UpdateTargetFrame(kind)
if addon.settings.profile.flashOnFind then
FlashClientIcon()
end
if addon.settings.profile.enableTargetingFlash then
addon.tips:EnableDangerWarning(1)
end
if addon.settings.profile.enableEnemyMarking then
-- Steal moon, lowest of enemies for mark
self:UpdateMarker("rare", kind, 4)
end
end
end
end
end
function addon.targeting:GOSSIP_SHOW()
local targetUnit = UnitName("target")
if not targetUnit then return end
-- Return after first match, won't be an enemy and friendly target as the same step
if addon.settings.profile.enableFriendlyTargeting then
for i, name in ipairs(targetList) do
if name == targetUnit then
tremove(targetList, i)
self:UpdateTargetFrame("target")
self:UpdateMacro()
if GetRaidTargetIndex("target") ~= nil then
SetRaidTarget("target", 0)
end
return
end
end
end
end
addon.targeting.MERCHANT_SHOW = addon.targeting.GOSSIP_SHOW
addon.targeting.QUEST_PROGRESS = addon.targeting.GOSSIP_SHOW
addon.targeting.QUEST_GREETING = addon.targeting.GOSSIP_SHOW
addon.targeting.QUEST_COMPLETE = addon.targeting.GOSSIP_SHOW
function addon.targeting.CheckTargetProximity()
if not shouldTargetCheck() or
not addon.settings.profile.showTargetingOnProximity then return end
if addon.settings.profile.enableEnemyTargeting then
for _, name in pairs(unitscanList) do
proxmityPolling.scanData = {name = name, kind = 'unitscan'}
TargetUnit(name, true)
end
for _, name in pairs(mobList) do
proxmityPolling.scanData = {name = name, kind = 'mob'}
TargetUnit(name, true)
end
end
if addon.settings.profile.enableFriendlyTargeting then
for _, name in pairs(targetList) do
proxmityPolling.scanData = {name = name, kind = 'friendly'}
TargetUnit(name, true)
end
end
if addon.settings.profile.scanForRares then
for _, name in ipairs(rareTargets) do
proxmityPolling.scanData = {name = name, kind = 'rare'}
TargetUnit(name, true)
end
end
local now = GetTime()
-- Unset match if >5s without a ADDON_ACTION_FORBIDDEN
-- No hits, reset everything
if proxmityPolling.match and now - proxmityPolling.lastMatch >
proxmityPolling.matchTimeout then
if addon.settings.profile.debug then
addon.comms.PrettyPrint("All match expired, resetting targets")
end
proxmityPolling.match = false
wipe(proxmityPolling.rareAnnounced)
wipe(proxmityPolling.scannedTargets)
if not InCombatLockdown() then
addon.targeting.activeTargetFrame:Hide()
end
-- Full reset, so don't handle per-mob checks below
return
end
for name, data in pairs(proxmityPolling.scannedTargets) do
if now - data.lastMatch > proxmityPolling.matchTimeout then
if addon.settings.profile.debug then
addon.comms.PrettyPrint("Individual match expired", name)
end
proxmityPolling.scannedTargets[name] = nil
end
end
end
-- Disables and mutes the annoying dialog that shows up
local actionForbiddenText = fmt(ADDON_ACTION_FORBIDDEN, addonName)
local TextBoxHook = function(self)
if self.text:GetText() == actionForbiddenText then
if self:IsShown() then self:Hide() end
local _, channel = PlaySound(SOUNDKIT.IG_MAINMENU_CLOSE)
if channel then
StopSound(channel)
StopSound(channel - 1)
end
StaticPopupDialogs["ADDON_ACTION_FORBIDDEN"] = nil
end
end
_G.StaticPopup1:HookScript("OnShow", TextBoxHook)
_G.StaticPopup1:HookScript("OnHide", TextBoxHook)
_G.StaticPopup2:HookScript("OnShow", TextBoxHook)
_G.StaticPopup2:HookScript("OnHide", TextBoxHook)
function addon.targeting:ADDON_ACTION_FORBIDDEN(_, forbiddenAddon, func)
if func ~= "TargetUnit()" or forbiddenAddon ~= addonName then return end
-- Unexpected call from (mistakenly) RXP
if not proxmityPolling.scanData or not proxmityPolling.scanData.name then
return
end
local scannedName = proxmityPolling.scanData.name
local now = GetTime()
proxmityPolling.scannedTargets[scannedName] = {
kind = proxmityPolling.scanData.kind,
lastMatch = now
}
proxmityPolling.lastMatch = now
self:UpdateTargetFrame()
if proxmityPolling.scanData.kind == 'rare' and
addon.settings.profile.notifyOnRares and
not proxmityPolling.rareAnnounced[scannedName] then
proxmityPolling.rareAnnounced[scannedName] = true
addon.comms.PrettyPrint(L("Rare Found! %s is nearby."), scannedName) -- TODO locale
end
-- Only notify sound once per step
if proxmityPolling.match then return end
proxmityPolling.match = true
if addon.settings.profile.soundOnFind ~= "none" and
(proxmityPolling.scanData.kind == 'rare' or
proxmityPolling.scanData.kind == 'unitscan') then
PlaySound(addon.settings.profile.soundOnFind,
addon.settings.profile.soundOnFindChannel)
end
end
function addon.targeting:UpdateUnitList()
local stepUnitscan = {}
local stepMobs = {}
local stepTargets = {}
local function AddUnits(element,stepUnitscan,stepMobs,stepTargets)
if element.unitscan then
for _, t in ipairs(element.unitscan) do
tinsert(stepUnitscan, addon.GetCreatureName(t))
end
end
if element.mobs then
for _, t in ipairs(element.mobs) do
tinsert(stepMobs, addon.GetCreatureName(t))
end
end
if element.targets then
for _, t in ipairs(element.targets) do
tinsert(stepTargets, addon.GetCreatureName(t))
end
end
end
for _,step in pairs(addon.RXPFrame.activeSteps) do
for _,element in pairs(step.elements) do
AddUnits(element,stepUnitscan,stepMobs,stepTargets)
end
end
local unitscanGenerated = {}
local mobsGenerated = {}
local targetsGenerated = {}
for _,context in pairs(addon.generatedSteps) do
for _,step in ipairs(context) do
for _,element in ipairs(step.elements or {}) do
AddUnits(element,unitscanGenerated,mobsGenerated,targetsGenerated)
end
end
end
-- Update targets for macro
addon.targeting:UpdateEnemyList(stepUnitscan, stepMobs)
addon.targeting:UpdateTargetList(stepTargets)
addon.targeting:UpdateEnemyList(unitscanGenerated, mobsGenerated, true)
addon.targeting:UpdateTargetList(targetsGenerated, true)
-- Don't process new targets if targeting disabled
if addon.settings.profile.enableTargetAutomation then
addon.targeting:CheckNameplates()
end
end
local function FilterList(list)
local u = {}
for i,unit in pairs(list) do
if unit:sub(1,1) == "*" then
local name = unit:sub(2,-1)
u[i] = name
end
end
local size = #list
for n = size,1,-1 do
if u[n] then
table.remove(list,n)
end
end
for n = 1,size do
local name = u[n]
if name then
table.insert(list,name)
end
end
end
function addon.targeting:UpdateTargetList(targets, addEntries)
FilterList(targets)
if addEntries then
local update
for _, unit in ipairs(targets) do
local found
for _, src in ipairs(targetList) do
if src == unit then
found = true
break
end
end
if not found then
update = true
lowPrioTargets[unit] = true
tinsert(targetList, unit)
end
end
if not update then return end
elseif addEntries == false then
table.wipe(lowPrioTargets)
targetList = targets
else
targetList = targets
end
self:UpdateMacro()
if not addon.settings.profile.enableTargetAutomation then return end
proxmityPolling.match = false
proxmityPolling.lastMatch = 0
if addon.settings.profile.showTargetingOnProximity then
for name, data in pairs(proxmityPolling.scannedTargets) do
if data.kind == 'friendly' then
proxmityPolling.scannedTargets[name] = nil
end
end
end
self:UpdateTargetFrame()
end
function addon.targeting:UpdateEnemyList(unitscan, mobs, addEntries)
FilterList(unitscan)
FilterList(mobs)
if addEntries then
local update
for _, unit in ipairs(unitscan) do
local found
for _, src in ipairs(unitscanList) do
if src == unit then
found = true
break
end
end
if not found then
update = true
tinsert(unitscanList, unit)
lowPrioTargets[unit] = true
end
end
for _, unit in ipairs(mobs) do
local found
for _, src in ipairs(mobList) do
if src == unit then
found = true
break
end
end
if not found then
tinsert(mobList, unit)
update = true
lowPrioTargets[unit] = true
end
end
if not update then return end
elseif addEntries == false then
table.wipe(lowPrioTargets)
unitscanList = unitscan
mobList = mobs
else
unitscanList = unitscan
mobList = mobs
end
self:UpdateMacro()
if not addon.settings.profile.enableTargetAutomation then return end
proxmityPolling.match = false
proxmityPolling.lastMatch = 0
if addon.settings.profile.showTargetingOnProximity then
for name, data in pairs(proxmityPolling.scannedTargets) do
if data.kind == 'unitscan' or data.kind == 'mob' then
proxmityPolling.scannedTargets[name] = nil
end
end
end
self:UpdateTargetFrame()
end
function addon.targeting:CanCreateMacro() return GetNumMacros() < 119 end
local function UpdateIconFrameVisuals(self, updateFrame)
self:SetScale(addon.settings.profile.activeTargetScale or 1)
addon.targeting:RenderTargetFrameBackground()
self.title:ClearBackdrop()
self.title:SetBackdrop(addon.RXPFrame.backdrop.edge)
self.title:SetBackdropColor(unpack(addon.colors.background))
self.title.text:SetFont(addon.font, 9, "")
self.title.text:SetTextColor(unpack(addon.activeTheme.textColor))
self.title:SetSize(self.title.text:GetStringWidth() + 14, 19)
end
function addon.targeting:CreateTargetFrame()
-- Still create frame even if targeting disabled, for frame location preservation
if self.activeTargetFrame then return end
self.activeTargetFrame = CreateFrame("Frame", "RXPTargetFrame", UIParent,
BackdropTemplateMixin and
"BackdropTemplate" or nil)
local f = self.activeTargetFrame
f:SetClampedToScreen(true)
f:EnableMouse(true)
f:SetMovable(true)
f:Hide()
addon.enabledFrames["activeTargetFrame"] = f
f.IsFeatureEnabled = function()
if not addon.settings.profile.enableTargetAutomation then return nil,true end
if addon.settings.profile.showTargetingOnProximity then
return proxmityPolling.match and shouldTargetCheck(),true
end
return shouldTargetCheck()
end
self:RenderTargetFrameBackground()
f.onMouseDown = function()
if addon.settings.profile.lockFrames and not IsAltKeyDown() then
return
end
f:StartMoving()
end
function f.onMouseUp()
f:StopMovingOrSizing()
addon.settings:SaveFramePositions()
end
f:SetScript("OnMouseDown", f.onMouseDown)
f:SetScript("OnMouseUp", f.onMouseUp)
f.friendlyTargetButtons = {}
f.enemyTargetButtons = {}
f:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
f.title = CreateFrame("Frame", "$parent_title", f,
BackdropTemplateMixin and "BackdropTemplate" or nil)
f.title:SetPoint("TOPLEFT", f, 5, 5)
f.title:ClearBackdrop()
f.title:SetBackdrop(addon.RXPFrame.backdrop.edge)
f.title:SetBackdropColor(unpack(addon.colors.background))
f.title.text = f.title:CreateFontString(nil, "OVERLAY")
f.title.text:ClearAllPoints()
f.title.text:SetPoint("CENTER", f.title, 0, 2)
f.title.text:SetJustifyH("CENTER")
f.title.text:SetJustifyV("MIDDLE")
f.title.text:SetTextColor(unpack(addon.activeTheme.textColor))
f.title.text:SetFont(addon.font, 9, "")
f.title.text:SetText(L "Active Targets")
f.title:SetSize(f.title.text:GetStringWidth() + 14, 19)
f.title:EnableMouse(true)
f.title:SetScript("OnMouseDown", f.onMouseDown)
f.title:SetScript("OnMouseUp", f.onMouseUp)
f.UpdateVisuals = UpdateIconFrameVisuals
f:SetHeight(40)
f:SetScale(addon.settings.profile.activeTargetScale)
end
function addon.targeting:RenderTargetFrameBackground()
if not self.activeTargetFrame then return end
local f = self.activeTargetFrame
-- print(RXP.activeTheme.texturePath)
if addon.settings.profile.hideActiveTargetsBackground then
f:ClearBackdrop()
else
f:ClearBackdrop()
f:SetBackdrop(addon.RXPFrame.backdrop.edge)
f:SetBackdropColor(unpack(addon.colors.background))
end
end
local fOnEnter = function(self)
if self:IsForbidden() or GameTooltip:IsForbidden() or not self.targetData then
return
end
GameTooltip:ClearLines()
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM", 0, 0)
if self.targetData.kind == "friendly" then
GameTooltip:AddLine(self.targetData.name, 0, 1, 0)
else
GameTooltip:AddLine(self.targetData.name, 1, 0, 0)
end
GameTooltip:Show()
end
local fOnLeave = function(self)
if self:IsForbidden() or _G.GameTooltip:IsForbidden() then return end
GameTooltip:Hide()
end
function addon.targeting:UpdateMarker(kind, unitId, index)
if (UnitIsDead(unitId) and kind ~= 'friendly') or UnitIsPlayer(unitId) or UnitIsUnit(unitId, "pet") then
return
end
if IsInGroup() and not UnitIsGroupLeader('player') then return end
-- Only mark 4/8 targets, ignore later marks
if index > 4 then return end
local markerId
if kind == 'friendly' then
-- Use star, circle, diamond, and triangle
markerId = index
elseif kind == 'unitscan' or kind == 'rare' then
markerId = 5 -- moon
elseif kind == 'mob' then
-- use skull, cross, square
markerId = 9 - index
end
if not markerId then return end
if GetRaidTargetIndex(unitId) == nil and GetRaidTargetIndex(unitId) ~=
markerId then SetRaidTarget(unitId, markerId) end
end
addon.targeting.portraitCache = {}
addon.targeting.activeIcons = {}
local iconCounter = 0
local function GetIcon(unit)
local texture = addon.targeting.portraitCache[unit]
local time = GetTime()
if not texture then
if iconCounter < 30 then
texture = addon.targeting.activeTargetFrame:CreateTexture()
iconCounter = iconCounter + 1
else
local lastActive = time
local oldest
local name
for u, f in pairs(addon.targeting.portraitCache) do
if f.lastActive < lastActive then
lastActive = f.lastActive
oldest = f
name = u
end
end
addon.targeting.portraitCache[name] = nil
texture = oldest
end
end
addon.targeting.portraitCache[unit] = texture
texture.unit = unit
texture.lastActive = time
return texture
end
local function GetUnitTexture(self, name, unit)
local f = addon.targeting.portraitCache[name]
if f and f.anchor then f.anchor:Show() end
-- unit = unit or 'target'
if unit and name and UnitName(unit) == name then
f = GetIcon(name)
SetPortraitTexture(f, unit)
end
if f then
-- self.placeholder:Hide()
f.anchor = self.placeholder
addon.targeting.activeIcons[f] = true
f:SetParent(self)
f:SetAllPoints(self)
f:Show()
self.placeholder:Hide()
self.icon = f
return f
else
self.placeholder:Show()
self.icon = self.placeholder
return self.placeholder
end
end
function addon.targeting:UpdateTargetFrame(selector)
if not addon.settings.profile.enableTargetAutomation then return end
local targetFrame = self.activeTargetFrame
if InCombatLockdown() then return end
local enemyTargetButtons = targetFrame.enemyTargetButtons
local j = 0
local enemiesList = {}