-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMagicTargets.lua
2162 lines (1994 loc) · 67.9 KB
/
MagicTargets.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
--[[
**********************************************************************
MagicTargets - Show the targets of the raid / party members.
**********************************************************************
This file is part of MagicTargets, a World of Warcraft Addon
MagicTargets is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MagicTargets is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with MagicTargets. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************
]]
-- 10:50 <@vhaarr> local ae = {}; AceLibrary("AceEvent-2.0"):embed(ae); ae:RegisterEvent("oRA_MainTankUpdate", function() --[[ update tanks ]] end)
-- 10:50 <@vhaarr> NeoTron: or even AceLibrary("AceEvent-2.0"):RegisterEvent("oRA_MainTankUpdate", function() ... end)
MagicTargets = LibStub("AceAddon-3.0"):NewAddon("MagicTargets", "AceEvent-3.0", "LibMagicUtil-1.0",
"AceTimer-3.0", "AceConsole-3.0", "LibSimpleBar-1.0")
--LoadAddOn("LibGroupTalents-1.0")
-- Silently fail embedding if it doesn't exist
local LibStub = LibStub
local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
local LGT = LibStub:GetLibrary("LibGroupTalents-1.0", true)
local Logger = LibStub("LibLogger-1.0", true)
if Logger then
Logger:Embed(MagicTargets)
end
local L = LibStub("AceLocale-3.0"):GetLocale("MagicTargets")
local C = LibStub("AceConfigDialog-3.0")
local DBOpt = LibStub("AceDBOptions-3.0")
local media = LibStub("LibSharedMedia-3.0")
local mod = MagicTargets
local comm = LibStub("MagicComm-1.0")
local UnitAura = UnitAura
local CreateFrame = CreateFrame
local GetInventoryItemLink = GetInventoryItemLink
local GetItemInfo = GetItemInfo
local GetNumGroupMembers = GetNumGroupMembers
local IsInRaid = IsInRaid
local GetRaidRosterInfo = GetRaidRosterInfo
local GetRaidTargetIndex = GetRaidTargetIndex
local InCombatLockdown = InCombatLockdown
local UIParent = UIParent
local UnitCanAttack = UnitCanAttack
local UnitClass = UnitClass
local UnitClassification = UnitClassification
local UnitCreatureType = UnitCreatureType
local UnitExists = UnitExists
local UnitGUID = UnitGUID
local UnitHealth = UnitHealth
local UnitHealthMax = UnitHealthMax
local UnitIsDead = UnitIsDead
local UnitIsPlayer = UnitIsPlayer
local UnitLevel = UnitLevel
local UnitName = UnitName
local UnitPlayerControlled = UnitPlayerControlled
local ceil = math.ceil
local fmt = string.format
local gsub = gsub
local ipairs = ipairs
local max = max
local min = min
local next = next
local pairs = pairs
local rnd = math.random
local select = select
local sort = sort
local strlen = strlen
local tconcat = table.concat
local time = time
local tinsert = table.insert
local tonumber = tonumber
local tostring = tostring
local tremove = table.remove
local tsort = table.sort
local type = type
local unpack = unpack
local isClassic = UnitCharacterPoints ~= nil
local addonEnabled = false
local ccspells = {}
local db, isInGroup, inCombat
local ccstrings = {}
local mobspells = {}
local tooltipInfo = {}
local died = {}
local seen = {}
local mmtargets = {}
local raidicons = {}
local ingroup = {}
local trivial = {}
local focusIcon, targetIcon
local GetSpellInfo = function(id) return MagicTargets.GetSpellInfo(id) end
local tableStore = {}
local classColors = {}
if UnitGroupRolesAssigned == nil then
function UnitGroupRolesAssigned() return false end
end
for k, v in pairs(RAID_CLASS_COLORS) do
classColors[k] = ("|cff%02x%02x%02x"):format(v.r * 255, v.g * 255, v.b * 255)
end
-- Helper table to cache colored player names.
local coloredNames = setmetatable({}, { __index = function(self, key)
if type(key) == "nil" then
return nil
end
local _, class = UnitClass(key)
if class then
self[key] = classColors[class] .. key .. "|r"
return self[key]
else
return key
end
end
})
local colors = {
Tank = { [1] = 0, [2] = 1, [3] = 0.2, [4] = 1 },
CC = { [1] = 0, [2] = 0.7, [3] = 0.9, [4] = 1 },
Notank = { [1] = 1, [2] = 0, [3] = 0, [4] = 1 },
Normal = { [1] = 1, [2] = 1, [3] = 0.5, [4] = 1 }
}
function mod.clear(tbl)
if type(tbl) == "table" then
for id, data in pairs(tbl) do
if type(data) == "table" then
mod.del(data)
end
tbl[id] = nil
end
end
end
function mod.get()
return tremove(tableStore) or {}
end
function mod.del(tbl, index)
local todel = tbl
if index then
todel = tbl[index]
end
if type(todel) ~= "table" then
return
end
mod.clear(todel)
tinsert(tableStore, todel)
if index then
tbl[index] = nil
end
end
local function SetColorOpt(arg, r, g, b, a)
local color = arg[#arg]
db.colors[color][1] = r
db.colors[color][2] = g
db.colors[color][3] = b
db.colors[color][4] = a
end
function mod:SetBarColors()
for _, frame in pairs(mod.bars) do
frame:SetColor(frame.color)
end
end
local function GetColorOpt(arg)
return unpack(db.colors[arg[#arg]])
end
local iconPath = [[Interface\AddOns\MagicTargets\Textures\%d.tga]]
local defaults = {
profile = {
showNotTargetedBy = false,
showDuration = true,
focus = true,
coloredNames = true,
target = true,
eliteonly = false,
filterTargetRoles = true,
growup = false,
font = "Friz Quadrata TT",
locked = false,
mmlisten = true,
hideanchor = true,
outsidegroup = true,
texture = "Minimalist",
maxbars = 20,
fontsize = 8,
width = 150,
height = 12,
spacing = 2,
fadebars = false,
HideMinimapButton = false,
showTooltip = true,
scale = 1.0,
labelTheme = "default",
-- frame background
edgeSize = 16,
padding = 2,
backdropColors = {
backgroundColor = { 0, 0, 0, 0.5 },
borderColor = { 0.88, 0.88, 0.88, 0.8 },
},
background = "Solid",
border = "None",
tile = false,
tileSize = 32,
},
}
function mod:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MagicTargetsDB", defaults, "Default")
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
db = self.db.profile
if not db.colors then
db.colors = colors
end
mod:FixLabelThemes()
self.ldb = LDB:NewDataObject("Magic Targets",
{
type = "launcher",
label = "Magic Targets",
icon = [[Interface\AddOns\MagicTargets\target.tga]],
tooltiptext = (L["|cffffff00Left click|r to open the configuration screen.\n"] ..
L["|cffffff00Right click|r to toggle the Magic Target window lock."]),
OnClick = function(clickedframe, button)
if button == "LeftButton" then
mod:ToggleConfigDialog()
elseif button == "RightButton" then
mod:ToggleLocked()
end
end,
})
mod.options.profile = DBOpt:GetOptionsTable(self.db)
mod:SetupOptions()
for i = 1, 8 do
raidicons[i] = iconPath:format(i)
end
for id, duration in pairs(comm.spellIdToDuration) do
local icon = select(3, GetSpellInfo(id))
ccspells[id] = { duration, icon }
end
mod.recycledFrames = {}
mod.unitbars = {}
mod.bars = {}
mod:CreateFrame()
end
-- Sort first by Magic Marker priority, then by health and lastly by guid.
local function BarSortFunc(a, b)
local amm = mmtargets[a.name]
local bmm = mmtargets[b.name]
local av = 0
local bv = 0
if amm then
av = 1000 + (amm.val or 0) + (amm.cc == L["Tank"] and 100 or 0)
else
av = a.value
end
if bmm then
bv = 1000 + (bmm.val or 0) + (bmm.cc == L["Tank"] and 100 or 0)
else
bv = b.value
end
if av == bv then
return a.name > b.name
else
return av > bv
end
end
function mod:OnEnable()
self:ApplyProfile()
if self.SetLogLevel then
self:SetLogLevel(self.logLevels.TRACE)
end
self:RegisterEvent("GROUP_ROSTER_UPDATE", "ScheduleGroupScan")
self:ScheduleGroupScan(true)
end
local function GetRaidIcon(id)
if id and id > 0 and id <= 8 then
return raidicons[id]
end
end
function mod:SetIcon(bar, mark)
if not mark then
bar.icon:SetTexture(nil)
elseif bar.mark ~= mark then
bar.icon:SetTexture(GetRaidIcon(mark))
end
bar.mark = mark
end
function mod:IterateBars(func, ...)
for _, frame in pairs(mod.bars) do
if frame[func] then
frame[func](frame, ...)
elseif frame.bar[func] then
frame.bar[func](frame.bar, ...)
end
end
end
function mod:SetTexture(frame)
local t = media:Fetch("statusbar", db.texture)
if frame then
frame.bar:SetTexture(t)
else
mod:IterateBars("SetTexture", t)
end
end
function mod:SetFont()
mod:IterateBars("SetBarFont")
mod:SetHandleFont()
end
function mod:OnDisable()
self:UnregisterEvent("GROUP_ROSTER_UPDATE")
end
local unitTanks = {}
local shieldSubType = select(7, GetItemInfo(40700)) -- badge shield, always available
local function hasShieldEquipped(unit)
local shieldLink = GetInventoryItemLink(unit, 17)
if shieldLink then
return select(7, GetItemInfo(shieldLink)) == shieldSubType
else
return false
end
end
do
local tankAura = {
PALADIN = { [GetSpellInfo(25780)] = true },
WARRIOR = hasShieldEquipped,
DRUID = { [GetSpellInfo(5487)] = true, [GetSpellInfo(9634) or GetSpellInfo(5487)] = true }, -- there's no dire bear in cataclysm, this is a simple fix
}
if GetSpellInfo(48263) ~= nil then
tankAura["DEATHKNIGHT"] = { [GetSpellInfo(48263)] = true } -- yay, frost presence is visible!
end
function mod:IsTank(unit)
local name = UnitName(unit)
if unitTanks[name] ~= nil then
return unitTanks[name]
end
local oRA = oRA
if oRA and oRA.maintanktable then
for _, tname in pairs(oRA.maintanktable) do
if name == tname then
unitTanks[name] = true
return true
end
end
end
-- This checks the new 5-man role as well as the spec of the player
if UnitGroupRolesAssigned(unit) == "TANK" or mod:UnitRole(unit, true) == "tank" then
unitTanks[name] = true
return true
end
local _, class = UnitClass(unit)
local auras = tankAura[class]
-- if mod.debug then mod:debug("Tank check: Class = %s,auras = %s, type(auras) = %s",
-- class, mod:Dump(auras), type(auras))
-- end
if not auras then
-- mod:debug("Found no auras for class %s", class)
unitTanks[name] = false
return false
end
if type(auras) == "function" then
unitTanks[name] = auras(unit)
--mod:debug("Found that %s [%s] is %s", name, unit, tostring(auras(unit)))
return unitTanks[name]
else
for idx = 1, 40 do
local aura = UnitAura(unit, idx, "HELPFUL")
if not aura then
break
end
-- mod:debug("Scanning: Found %s ", mod:Dump(aura) or "nil")
if auras[aura] then
unitTanks[name] = true
return true
end
end
end
return false
end
end
function mod:UnitRole(unit, specOnly)
if not specOnly and mod:IsTank(unit) then
return "tank"
end
local role = UnitGroupRolesAssigned(unit)
if role == "TANK" then
return "tank"
elseif role == "HEALER" then
return "healer"
else
if LGT then
return LGT:GetUnitRole(unit)
else
return "dps"
end
end
end
do
local groupScanTimer
function mod:ScheduleGroupScan(fast)
if groupScanTimer then
self:CancelTimer(groupScanTimer, true)
end
if fast == true then
groupScanTimer = self:ScheduleTimer("ScanGroupMembers", 0.1)
else
groupScanTimer = self:ScheduleTimer("ScanGroupMembers", 5)
end
end
function mod:ScanGroupMembers()
mod.clear(ingroup)
if GetNumGroupMembers() > 0 then
isInGroup = true
else
mod.clear(coloredNames)
isInGroup = false
mod:OnCommResetV2() -- make sure the magic marker bars are gone
end
if isInGroup or db.outsidegroup then
mod:IterateRaid(function(self, unittarget, unitname)
if unitname then
ingroup[unitname] = unittarget
end
end, true)
if not addonEnabled then
addonEnabled = true
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_TARGET_CHANGED", "UpdateTarget", "target")
if not isClassic then
self:RegisterEvent("PLAYER_FOCUS_CHANGED", "UpdateTarget", "focus")
end
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT", "UpdateBar", "mouseover")
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:ClearCombatData()
if db.mmlisten then
comm:RegisterListener(self, "MM", true)
end
if InCombatLockdown() then
self:PLAYER_REGEN_DISABLED()
else
self:PLAYER_REGEN_ENABLED()
end
end
else
if addonEnabled then
addonEnabled = false
self:UnregisterEvent("UNIT_HEALTH")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
if not isClassic then
self:UnregisterEvent("PLAYER_FOCUS_CHANGED")
end
self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
comm:UnregisterListener(self, "MM")
self:PLAYER_REGEN_ENABLED()
end
self:ClearCombatData()
self:RemoveAllBars(true)
end
end
end
function mod:UpdateTarget(target, norefresh)
if mod.testBars then
return
end
local icon = target == "focus" and focusIcon or targetIcon
if icon then
icon:Hide()
end
self:UpdateBar(target, UnitName("player"))
if UnitExists(target) then
local frame = mod.unitbars[UnitGUID(target)]
if frame then
self:MoveIconTo(icon, frame, target)
mod:SetBarStrings(frame)
end
end
if norefresh ~= true then
mod:SortBars()
end
end
local function Noop()
end
function mod:RemoveBar(id)
local frame = mod.unitbars[id] or mod.bars[id]
if frame then
mod.unitbars[frame.guid] = nil
frame.mark = nil
frame.guid = nil
seen[id] = nil
mod.del(tooltipInfo, id)
frame:SetScript("OnEnter", nil)
frame:SetScript("OnLeave", nil)
frame:EnableMouse(false)
if frame.tooltipShowing then
frame.tooltipShowing = nil
GameTooltip:Hide()
end
frame:Hide()
mod.recycledFrames[#mod.recycledFrames + 1] = frame
for id, data in pairs(mod.bars) do
if frame == data then
tremove(mod.bars, id)
break
end
end
end
end
function mod:RemoveAllBars(removeAll)
if mod.testBars then
return
end
for id in pairs(mod.unitbars) do
if removeAll or not mmtargets[id] then
mod:RemoveBar(id)
end
end
mod:SortBars()
end
local updated = {}
local tanked = {}
local lvlFmt = L["Level %d %s"]
local colorToText = {
CC = L["Crowd Controlled"],
Tank = L["Tanked"],
Notank = L["Untanked"],
}
local function Bar_UpdateTooltip(self, tooltip)
tooltip:ClearLines()
local tti = tooltipInfo[self.guid]
if tti and tti.name then
tooltip:AddLine(tti.name, 0.85, 0.85, 0.1)
tooltip:AddLine(fmt(lvlFmt, tti.level, tti.type), 1, 1, 1)
tooltip:AddLine(" ")
tooltip:AddDoubleLine(L["Health:"], fmt("%.0f%%", 100 * self.bar.value / self.bar.maxValue), nil, nil, nil, 1, 1, 1)
if tti.target then
tooltip:AddDoubleLine(L["Target:"], tti.target, nil, nil, nil, 1, 1, 1)
end
if self.color and colorToText[self.color] and InCombatLockdown() then
local c = db.colors[self.color]
tooltip:AddDoubleLine(L["Status:"], colorToText[self.color], nil, nil, nil, c[1], c[2], c[3])
else
local c = db.colors.Normal
tooltip:AddDoubleLine(L["Status:"], L["Idle"], nil, nil, nil, c[1], c[2], c[3])
end
if mmtargets[self.guid] then
tooltip:AddDoubleLine(L["MagicMarker Assignment:"], mmtargets[self.guid].cc, nil, nil, nil, 1, 1, 1)
end
if tti.cc then
tooltip:AddDoubleLine(L["Crowd Control:"], tti.cc, nil, nil, nil, 1, 1, 1)
end
tooltip:AddLine(" ")
if next(tti.targets) then
local sorted = mod.get()
if db.showNotTargetedBy then
tooltip:AddLine(L["Not targeted by:"], 0.85, 0.85, 0.1);
for id in pairs(ingroup) do
if not tti.targets[id] then
if db.filterTargetRoles then
local role = mod:UnitRole(id)
if role ~= "tank" and role ~= "healer" then
sorted[#sorted + 1] = id
end
else
sorted[#sorted + 1] = id
end
end
end
else
tooltip:AddLine(L["Currently targeted by:"], 0.85, 0.85, 0.1);
for id in pairs(tti.targets) do
sorted[#sorted + 1] = id
end
end
sort(sorted)
if db.coloredNames then
for id, name in ipairs(sorted) do
sorted[id] = coloredNames[name]
end
end
tooltip:AddLine(tconcat(sorted, ", "), 1, 1, 1, 1)
mod.del(sorted)
else
tooltip:AddLine(L["Not targeted by anyone."]);
end
else
if tti and tti.name then
tooltip:AddLine(tti.name, 0.85, 0.85, 0.1)
tooltip:AddLine(" ")
end
tooltip:AddLine(L["Not targeted by anyone."]);
end
tooltip:Show()
end
local function Bar_OnEnter(frame)
if not db.showTooltip then
return
end
local tooltip = GameTooltip
tooltip:SetOwner(frame, "ANCHOR_CURSOR")
Bar_UpdateTooltip(frame, tooltip)
frame.tooltipShowing = true
end
local function Bar_OnLeave(frame)
if not db.showTooltip then
return
end
GameTooltip:Hide()
frame.tooltipShowing = nil
end
function mod:UNIT_HEALTH(event, unit)
local guid = UnitGUID(unit)
local frame = mod.unitbars[guid]
if not frame then
return
end
local tti = tooltipInfo[guid]
local uh, uhm = UnitHealth(unit), UnitHealthMax(unit)
if tti then
tti.health = uh
tti.maxhealth = uhm
tti["%"] = ceil(100 * uh / uhm)
end
if frame.bar.value ~= uh or frame.bar.maxvalue ~= uhm then
frame.bar:SetValue(uh, uhm)
end
end
function mod:UpdateBar(target, targetedBy)
if not UnitExists(target) or mod.testbars then
return
end
if target == "mouseover" then
targetedBy = nil
end
local guid = UnitGUID(target)
-- Add to the people targeting this particular unit
if updated[guid] then
if targetedBy then
local tti = tooltipInfo[guid]
if tti and not tti.targets[targetedBy] then
tti.targets[targetedBy] = true
updated[guid] = updated[guid] + 1
end
end
return
elseif trivial[guid] or died[guid] then
return
end
local type = UnitCreatureType(target)
local unitname = UnitName(target)
if UnitCanAttack("player", target) and not UnitIsDead(target) and not ingroup[unitname] and not UnitPlayerControlled(target) then
-- and not UnitIsPlayer(target) then
if type == L["Critter"] or type == L["Totem"] or (db.eliteonly and UnitClassification(target) == "normal") then
trivial[guid] = true
self:RemoveBar(guid)
return
end
local frame = mod.unitbars[guid]
local mark = GetRaidTargetIndex(target)
local uh, uhm = UnitHealth(target), UnitHealthMax(target)
if not frame then
frame = self:CreateBar(guid, uh, uhm)
frame:SetColor("Normal")
else
frame.bar:SetValue(uh, uhm)
end
mod:SetIcon(frame, mark)
local targettarget = target .. "target"
if UnitExists(targettarget) and not UnitCanAttack("player", targettarget) and
not UnitIsDead(targettarget) and UnitIsPlayer(targettarget) then
tanked[guid] = mod:IsTank(targettarget)
end
if mmtargets[guid] then
if not inCombat then
frame:SetColor(mmtargets[guid].cc)
end
mmtargets[guid].mark = mark
end
local tti = tooltipInfo[guid] or mod.get()
tooltipInfo[guid] = tti
if tti.targets then
mod.clear(tti.targets)
else
tti.targets = mod.get()
end
if targetedBy then
updated[guid] = 1
tti.targets[targetedBy] = true
else
updated[guid] = 0
end
if isClassic then
tti.threat = 0 -- TODO - use threat meter?
else
local _, _, scaledPercent = UnitDetailedThreatSituation("Player", target)
tti.threat = ceil(scaledPercent or 0)
end
local tn = UnitName(targettarget)
tti.name = unitname
tti.target = tn and db.coloredNames and coloredNames[tn] or tn
tti.type = type
tti.level = UnitLevel(target)
tti.health = uh
tti.maxhealth = uhm
tti["%"] = ceil(100 * uh / uhm)
seen[guid] = time() + 4
if target == "mouseover" then
mod:SortBars()
mod:SetBarStrings(frame)
end
end
end
function mod:UpdateBars()
local tt = time()
if mod.testBars then
return
end
inCombat = InCombatLockdown()
mod.clear(updated)
mod.clear(unitTanks)
mod.clear(tanked)
-- Make bars for MagicMarker assignments
for id, data in pairs(mmtargets) do
if not died[id] then
local bar = mod.unitbars[id] or self:CreateBar(id, 100, 100)
mod:SetIcon(bar, data.mark)
end
end
-- Update raid targeting information, adding bars as necessary
for name, target in pairs(ingroup) do
self:UpdateBar(target, name)
end
-- If we have a pet, let's see what he's targeting
self:UpdateBar("pettarget")
if next(mod.unitbars) then
-- This updates the list of "seen" mobs. Bars for mobs not seen for a while
-- are removed.
for id, seenTime in pairs(seen) do
if seenTime < tt then
local frame = mod.unitbars[id]
if frame and mmtargets[id] then
if not inCombat then
frame.bar:SetValue(frame.bar.maxValue or 100)
frame:SetColor(mmtargets[id].cc)
seen[id] = nil
end
elseif not mobspells[id] or not inCombat then
seen[id] = nil -- only remove them if not in combat or if not cc'd
end
end
end
-- Update crowd control info, recycle non-needed bars etc
for id, frame in pairs(mod.unitbars) do
if updated[id] or mmtargets[id] or seen[id] then
-- We're keeping this one
if mobspells[id] then
-- Build crowd control info for this mob
if db.showDuration then
ccstrings[id] = nil
end
if not ccstrings[id] then
local str = " "
local timeLeft = 0
for _, tex in pairs(mobspells[id]) do
local spellTimeLeft = tex.expiration - tt
if spellTimeLeft > timeLeft then
timeLeft = spellTimeLeft
end
str = fmt("%s|T%s:0|t", tostring(str), tostring(tex.icon))
end
if timeLeft > 0 and db.showDuration then
str = fmt("%s %.0f", str, timeLeft)
end
ccstrings[id] = str
end
frame:SetColor("CC")
elseif inCombat then
-- Update bar colors based on mob status
if isInGroup then
if tanked[id] == nil then
frame:SetColor("Normal")
elseif tanked[id] then
frame:SetColor("Tank")
else
frame:SetColor("Notank")
end
else
frame:SetColor("Tank")
end
end
local tti = tooltipInfo[id]
if tti then
if not updated[id] then
-- This unit had no raid members targeting it
mod.clear(tooltipInfo[id].targets)
end
tti.cc = ccstrings[id]
end
if frame.tooltipShowing then
Bar_UpdateTooltip(frame, GameTooltip)
end
-- Update the text on the bar
mod:SetBarStrings(frame)
else
self:RemoveBar(id) -- Remove it since it's not seen, updated or MagicMarker
end
end
else
mod.clear(seen)
end
self:UpdateTarget("target", true)
if not isClassic then
self:UpdateTarget("focus", true)
end
mod:SortBars()
end
--------------------------------------------------
-- Move the <| icon to the appropriate location --
--------------------------------------------------
function mod:MoveIconTo(icon, frame, target)
if not icon then
return
end
local parent = icon:GetParent()
local othericon = target == "focus" and targetIcon or focusIcon
local otherparent = db[target == "focus" and "target" or "focus"] and othericon:GetParent()
if db[target] then
icon:SetPoint("LEFT", frame.bar, "RIGHT", -6, 0)
icon:SetParent(frame.bar)
icon:Show()
else
icon:SetParent(mod.frame)
icon:Hide()
end
end
do
local raidtarget, partytarget
function mod:IterateRaid(callback, target, ...)
local id, name, class, map
if IsInRaid() then
-- if mod.debug then mod:debug("Scanning raid ") end
if target then
if not raidtarget then
raidtarget = mod.get()
end
map = raidtarget
end
for id = 1, GetNumGroupMembers() do
local name = GetRaidRosterInfo(id)
if target then
if not map[id] then
map[id] = "raid" .. id .. (target and "target" or "")
end
-- if mod.debug then mod:debug("Raid id %d is %s or %s", id, name, map[id]) end
callback(self, map[id], name, ...)
else
callback(self, name, name, ...)
end
end
else
if GetNumGroupMembers() > 0 then
if not partytarget then
partytarget = mod.get()
end
map = partytarget
for id = 1, GetNumGroupMembers() - 1 do
if not map[id] then
map[id] = "party" .. id
end
local name = UnitName(map[id])
callback(self, (target and (map[id] .. "target")) or name, name, ...)
end
end
local name = UnitName("player")
callback(self, target and "target" or name, name, ...);
end
end
end
function mod:OnCommResetV2()
mod.clear(mmtargets)
if not InCombatLockdown() then
self:RemoveAllBars(true)
end
self:UpdateBars()
end
function mod:AddTooltipData(id, name)
local tti = tooltipInfo[id] or mod.get()
tooltipInfo[id] = tti
tti.targets = tti.targets or mod.get()
tti.name = name
tti.level = tti.level or 0
tti.type = tti.type or "Unknown"
tti["%"] = tti["%"] or 100
mod:SetBarStrings(mod.unitbars[id])
end
function mod:OnAssignData(data)
mmtargets = data
self:UpdateBars()
for id, data in pairs(mmtargets) do
if mod.unitbars[id] then
mod.unitbars[id]:SetColor(data.cc)
mod:AddTooltipData(id, data.name)
end
end
end
function mod:OnCommMarkV2(mark, guid, _, name)
if not name then
return
end
if not mmtargets[guid] then
mmtargets[guid] = mod.get()
mod:AddTooltipData(guid, name)