-
Notifications
You must be signed in to change notification settings - Fork 13
/
Gladdy.lua
825 lines (676 loc) · 25.4 KB
/
Gladdy.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
local setmetatable = setmetatable
local type = type
local tostring = tostring
local select = select
local pairs = pairs
local tinsert = table.insert
local tsort = table.sort
local strsplit = string.split
local CreateFrame = CreateFrame
local DEFAULT_CHAT_FRAME = DEFAULT_CHAT_FRAME
local IsAddOnLoaded = IsAddOnLoaded
local IsInInstance = IsInInstance
local MAX_BATTLEFIELD_QUEUES = MAX_BATTLEFIELD_QUEUES
local GetBattlefieldStatus = GetBattlefieldStatus
local GetSpellInfo = GetSpellInfo
local UnitGUID = UnitGUID
local UnitBuff = UnitBuff
local UnitDebuff = UnitDebuff
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local UnitHealth = UnitHealth
local UnitHealthMax = UnitHealthMax
local UnitMana = UnitMana
local UnitManaMax = UnitManaMax
local UnitPowerType = UnitPowerType
local UnitCastingInfo = UnitCastingInfo
local GetTime = GetTime
local UnitChannelInfo = UnitChannelInfo
local UnitIsPartyLeader = UnitIsPartyLeader
local UnitName = UnitName
local UnitExists = UnitExists
local UnitIsPlayer = UnitIsPlayer
local UnitCanAttack = UnitCanAttack
local UnitIsCharmed = UnitIsCharmed
local UnitRace = UnitRace
local UnitClass = UnitClass
local tonumber = tonumber
local CombatLogClearEntries = CombatLogClearEntries
local CombatLog_Object_IsA = CombatLog_Object_IsA
local COMBATLOG_OBJECT_TARGET = COMBATLOG_OBJECT_TARGET
local COMBATLOG_OBJECT_FOCUS = COMBATLOG_OBJECT_FOCUS
local MAJOR, MINOR = "Gladdy", 3
local Gladdy = LibStub:NewLibrary(MAJOR, MINOR)
local L
LibStub("AceTimer-3.0"):Embed(Gladdy)
LibStub("AceComm-3.0"):Embed(Gladdy)
Gladdy.modules = {}
setmetatable(Gladdy, {
__tostring = function()
return MAJOR
end
})
function Gladdy:Print(...)
local text = "|cff33ff99Gladdy|r:"
for i = 1, select("#", ...) do
text = text .. " " .. tostring(select(i, ...))
end
DEFAULT_CHAT_FRAME:AddMessage(text)
end
Gladdy.events = CreateFrame("Frame")
Gladdy.events.registered = {}
Gladdy.events:RegisterEvent("PLAYER_LOGIN")
Gladdy.events:SetScript("OnEvent", function(self, event, ...)
if (event == "PLAYER_LOGIN") then
Gladdy:OnInitialise()
Gladdy:OnEnable()
else
local func = self.registered[event]
if (type(Gladdy[func]) == "function") then
Gladdy[func](Gladdy, event, ...)
end
end
end)
function Gladdy:RegisterEvent(event, func)
self.events.registered[event] = func or event
self.events:RegisterEvent(event)
end
function Gladdy:UnregisterEvent(event)
self.events.registered[event] = nil
self.events:UnregisterEvent(event)
end
function Gladdy:UnregisterAllEvents()
self.events.registered = {}
self.events:UnregisterAllEvents()
end
local function pairsByPrio(t)
local a = {}
for k, v in pairs(t) do
tinsert(a, {k, v.priority})
end
tsort(a, function(x, y) return x[2] > y[2] end)
local i = 0
return function()
i = i + 1
if (a[i] ~= nil) then
return a[i][1], t[a[i][1]]
else
return nil
end
end
end
function Gladdy:IterModules()
return pairsByPrio(self.modules)
end
function Gladdy:Call(module, func, ...)
if (type(module) == "string") then
module = self.modules[module]
end
if (type(module[func]) == "function") then
module[func](module, ...)
end
end
function Gladdy:SendMessage(message, ...)
for k, v in self:IterModules() do
self:Call(v, v.messages[message], ...)
end
end
function Gladdy:NewModule(name, priority, defaults)
local module = {
name = name,
priority = priority or 0,
defaults = defaults or {},
messages = {},
}
module.RegisterMessage = function(self, message, func)
self.messages[message] = func or message
end
module.GetOptions = function()
return nil
end
for k, v in pairs(module.defaults) do
self.defaults.profile[k] = v
end
self.modules[name] = module
return module
end
function Gladdy:OnInitialise()
self.dbi = LibStub("AceDB-3.0"):New("GladdyXZ", self.defaults)
self.dbi.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.dbi.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.dbi.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
self.db = self.dbi.profile
self.LSM = LibStub("LibSharedMedia-3.0")
self.LSM:Register("statusbar", "Gloss", "Interface\\AddOns\\Gladdy\\Images\\Gloss")
self.LSM:Register("statusbar", "Minimalist", "Interface\\AddOns\\Gladdy\\Images\\Minimalist")
L = self.L
self.testData = {
["arena1"] = {name = "Swift", raceLoc = L["Undead"], classLoc = L["Warrior"], class = "WARRIOR", health = 9635, healthMax = 14207, power = 76, powerMax = 100, powerType = 1, spec = L["Arms"]},
["arena2"] = {name = "Vilden", raceLoc = L["Undead"], classLoc = L["Mage"], class = "MAGE", health = 10969, healthMax = 11023, power = 7833, powerMax = 10460, powerType = 0, spec = L["Frost"]},
["arena3"] = {name = "Krymu", raceLoc = L["Night Elf"], classLoc = L["Rogue"], class = "ROGUE", health = 1592, healthMax = 11740, power = 45, powerMax = 110, powerType = 3, spec = L["Subtlety"]},
["arena4"] = {name = "Talmon", raceLoc = L["Human"], classLoc = L["Warlock"], class = "WARLOCK", health = 10221, healthMax = 14960, power = 9855, powerMax = 9855, powerType = 0, spec = L["Demonology"]},
["arena5"] = {name = "Hydra", raceLoc = L["Undead"], classLoc = L["Priest"], class = "PRIEST", health = 11960, healthMax = 11960, power = 2515, powerMax = 10240, powerType = 0, spec = L["Discipline"]},
}
self.specBuffs = self:GetSpecBuffs()
self.specSpells = self:GetSpecSpells()
self.NS = GetSpellInfo(16188)
self.POM = GetSpellInfo(12043)
self.NF = GetSpellInfo(18095)
self.SHADOWBOLT = GetSpellInfo(27209)
self.INSTANT = {
[GetSpellInfo(172)] = true, -- Corruption
[GetSpellInfo(2645)] = true, -- Ghost Wolf
}
self.CAST_TIMES = {
[GetSpellInfo(26985)] = 1.5, -- Wrath
}
self.FD = GetSpellInfo(18708)
self.SUMMON = {
[GetSpellInfo(688)] = true,
[GetSpellInfo(697)] = true,
[GetSpellInfo(712)] = true,
[GetSpellInfo(691)] = true,
[GetSpellInfo(30146)] = true,
}
self.buttons = {}
self.guids = {}
self.curBracket = nil
self.curUnit = 1
self.lastInstance = nil
self:SetupOptions()
for k, v in self:IterModules() do
self:Call(v, "Initialise") -- B.E > A.E :D
end
end
function Gladdy:OnProfileChanged()
self.db = self.dbi.profile
self:HideFrame()
self:ToggleFrame(3)
end
function Gladdy:OnEnable()
self:RegisterEvent("PLAYER_ENTERING_WORLD")
if (IsAddOnLoaded("Clique")) then
for i = 1, 5 do
self:CreateButton(i)
end
ClickCastFrames = ClickCastFrames or {}
ClickCastFrames[self.buttons.arena1.secure] = true
ClickCastFrames[self.buttons.arena2.secure] = true
ClickCastFrames[self.buttons.arena3.secure] = true
ClickCastFrames[self.buttons.arena4.secure] = true
ClickCastFrames[self.buttons.arena5.secure] = true
end
if (not self.db.locked and self.db.x == 0 and self.db.y == 0) then
self:Print(L["Welcome to Gladdy!"])
self:Print(L["First run has been detected, displaying test frame."])
self:Print(L["Valid slash commands are:"])
self:Print(L["/gladdy ui"])
self:Print(L["/gladdy test2-5"])
self:Print(L["/gladdy hide"])
self:Print(L["/gladdy reset"])
self:Print(L["If this is not your first run please lock or move the frame to prevent this from happening."])
self:HideFrame()
self:ToggleFrame(3)
end
end
function Gladdy:Test()
for i = 1, self.curBracket do
local unit = "arena" .. i
if (not self.buttons[unit]) then
self:CreateButton(i)
end
local button = self.buttons[unit]
for k, v in pairs(self.testData[unit]) do
button[k] = v
end
for k, v in self:IterModules() do
self:Call(v, "Test", unit)
end
button:SetAlpha(1)
end
end
function Gladdy:PLAYER_ENTERING_WORLD()
self:Reset()
local instance = select(2, IsInInstance())
if (instance == "arena") then
self:JoinedArena()
elseif (instance ~= "arena" and self.lastInstance == "arena") then
self:HideFrame()
end
self.lastInstance = instance
end
function Gladdy:Reset()
self.guids = {}
self.curBracket = nil
self.curUnit = 1
for k1, v1 in self:IterModules() do
self:Call(v1, "Reset")
end
for k2 in pairs(self.buttons) do
self:ResetUnit(k2)
end
end
function Gladdy:ResetUnit(unit)
local button = self.buttons[unit]
if (not button) then return end
button:SetAlpha(0)
button._health = nil
button._power = nil
for k1, v1 in pairs(self.BUTTON_DEFAULTS) do
button[k1] = v1
end
for k2, v2 in self:IterModules() do
self:Call(v2, "ResetUnit", unit)
end
end
function Gladdy:JoinedArena()
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("UNIT_MANA", "UNIT_POWER")
self:RegisterEvent("UNIT_ENERGY", "UNIT_POWER")
self:RegisterEvent("UNIT_RAGE", "UNIT_POWER")
self:RegisterEvent("UNIT_DISPLAYPOWER", "UNIT_POWER")
self:RegisterEvent("UNIT_SPELLCAST_START")
self:RegisterEvent("UNIT_SPELLCAST_STOP")
self:RegisterEvent("UNIT_SPELLCAST_DELAYED")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("UNIT_SPELLCAST_FAILED", "UNIT_SPELLCAST_STOP")
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED", "UNIT_SPELLCAST_STOP")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", "UNIT_SPELLCAST_DELAYED")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP", "UNIT_SPELLCAST_STOP")
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("PLAYER_FOCUS_CHANGED")
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
self:RegisterEvent("UNIT_TARGET")
self:ScheduleRepeatingTimer("Sync", 1, self)
self:RegisterComm("Gladdy")
for i = 1, MAX_BATTLEFIELD_QUEUES do
local status, _, _, _, _, teamSize = GetBattlefieldStatus(i)
if (status == "active" and teamSize > 0) then
self.curBracket = teamSize
break
end
end
for i = 1, self.curBracket do
if (not self.buttons["arena" .. i]) then
self:CreateButton(i)
end
end
self:SendMessage("JOINED_ARENA")
self:UpdateFrame()
self.frame:Show()
CombatLogClearEntries()
end
function Gladdy:UNIT_AURA(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
local Auras = Gladdy.modules.Auras
local auraName, auraIcon, auraExpTime
local priority = 0
local index = 1
while (true) do
local name, _, icon, _, _, expTime = UnitBuff(uid, index)
if (not name) then break end
self:AuraGain(button.unit, name)
if (Auras.auras[name] and Auras.auras[name].priority >= (Auras.frames[button.unit].priority or 0)) then
auraName = name
auraIcon = icon
auraExpTime = expTime or 0
priority = Auras.auras[name].priority
end
index = index + 1
end
index = 1
while (true) do
local name, _, icon, _, _, _, expTime = UnitDebuff(uid, index)
if (not name) then break end
self:AuraGain(button.unit, name)
if (Auras.auras[name] and Auras.auras[name].priority >= (Auras.frames[button.unit].priority or 0)) then
auraName = name
auraIcon = icon
auraExpTime = expTime or 0
priority = Auras.auras[name].priority
end
index = index + 1
end
if (auraName) then
if (not auraExpTime) then
if (auraName == Auras.frames[button.unit].name) then
auraExpTime = Auras.frames[button.unit].timeLeft
else
auraExpTime = Auras.auras[name].duration
end
end
self:SendMessage("AURA_GAIN", button.unit, auraName, auraIcon, auraExpTime, priority)
else
self:SendMessage("AURA_FADE", button.unit)
end
end
function Gladdy:UNIT_HEALTH(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
if (not UnitIsDeadOrGhost(uid)) then
button.health = UnitHealth(uid)
button.healthMax = UnitHealthMax(uid)
self:SendMessage("UNIT_HEALTH", button.unit, button.health, button.healthMax)
else
self:SendMessage("UNIT_DEATH", button.unit)
end
end
function Gladdy:UNIT_POWER(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
if (not UnitIsDeadOrGhost(uid)) then
button.power = UnitMana(uid)
button.powerMax = UnitManaMax(uid)
button.powerType = UnitPowerType(uid)
self:SendMessage("UNIT_POWER", button.unit, button.power, button.powerMax, button.powerType)
else
self:SendMessage("UNIT_DEATH", button.unit)
end
end
function Gladdy:UNIT_SPELLCAST_START(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
local spell, rank, displayName, icon, startTime, endTime = UnitCastingInfo(uid)
local value = (endTime / 1000) - GetTime()
local maxValue = (endTime - startTime) / 1000
self:CastStart(button.unit, spell, icon, value, maxValue, "cast")
end
function Gladdy:UNIT_SPELLCAST_CHANNEL_START(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
local spell, rank, displayName, icon, startTime, endTime = UnitChannelInfo(uid)
local value = (endTime / 1000) - GetTime()
local maxValue = (endTime - startTime) / 1000
self:CastStart(button.unit, spell, icon, value, maxValue, "channel")
end
function Gladdy:UNIT_SPELLCAST_SUCCEEDED(event, uid, spell)
local button = self:GetButton(uid)
if (not button) then return end
self:CastSuccess(button.unit, spell)
end
function Gladdy:UNIT_SPELLCAST_DELAYED(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
local spell, rank, displayName, icon, startTime, endTime
if (event == "UNIT_SPELLCAST_DELAYED") then
spell, rank, displayName, icon, startTime, endTime = UnitCastingInfo(uid)
else
spell, rank, displayName, icon, startTime, endTime = UnitChannelInfo(uid)
end
local castBar = Gladdy.modules.Castbar.frames[button.unit]
castBar.value = GetTime() - (startTime / 1000)
castBar.maxValue = (endTime - startTime) / 1000
castBar:SetMinMaxValues(0, castBar.maxValue)
end
function Gladdy:UNIT_SPELLCAST_STOP(event, uid)
local button = self:GetButton(uid)
if (not button) then return end
self:SendMessage("CAST_STOP", button.unit)
end
function Gladdy:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, ...)
local srcUnit = self.guids[sourceGUID]
local destUnit = self.guids[destGUID]
if (not srcUnit and not destUnit) then return end
local events = {
["PARTY_KILL"] = "DEATH",
["UNIT_DIED"] = "DEATH",
["UNIT_DESTROYED"] = "DEATH",
["SWING_DAMAGE"] = "DAMAGE",
["RANGE_DAMAGE"] = "DAMAGE",
["SPELL_DAMAGE"] = "DAMAGE",
["SPELL_PERIODIC_DAMAGE"] = "DAMAGE",
["ENVIRONMENTAL_DAMAGE"] = "DAMAGE",
["DAMAGE_SHIELD"] = "DAMAGE",
["DAMAGE_SPLIT"] = "DAMAGE",
["SPELL_AURA_APPLIED"] = "BUFF",
["SPELL_PERIODIC_AURA_APPLIED"] = "BUFF",
["SPELL_AURA_APPLIED_DOSE"] = "BUFF",
["SPELL_PERIODIC_AURA_APPLIED_DOSE"] = "BUFF",
["SPELL_AURA_REFRESH"] = "REFRESH",
["SPELL_AURA_REMOVED"] = "FADE",
["SPELL_PERIODIC_AURA_REMOVED"] = "FADE",
["SPELL_AURA_REMOVED_DOSE"] = "FADE",
["SPELL_PERIODIC_AURA_REMOVED_DOSE"] = "FADE",
["SPELL_CAST_START"] = "CASTSTART",
["SPELL_SUMMON"] = "CASTSTART",
["SPELL_CREATE"] = "CASTSTART",
["SPELL_CAST_SUCCESS"] = "CASTSUCCESS",
["SPELL_CAST_FAILED"] = "CASTEND",
["SPELL_INTERRUPT"] = "INTERRUPT",
}
eventType = events[eventType]
if (not eventType) then return end
local t = ("%.1f"):format(GetTime())
if (events[eventType] == "DEATH" and destUnit) then
self:SendMessage("UNIT_DEATH", destUnit)
elseif (events[eventType] == "DAMAGE") then
local button = self.buttons[destUnit]
if (not button) then return end
button.damaged = t
elseif (eventType == "BUFF" and destUnit) then
local button = self.buttons[destUnit]
if (not button) then return end
local auraId, auraName = ...
self:AuraGain(destUnit, auraName)
local Auras = Gladdy.modules.Auras
local aura = Auras.auras[auraName]
local factor = self:Call("Diminishings", "Gain", destUnit, auraName)
if (aura and aura.priority >= (Auras.frames[destUnit].priority or 0)) then
local auraIcon = select(3, GetSpellInfo(auraId))
local auraExpTime = aura.duration / (factor or 1)
self:SendMessage("AURA_GAIN", destUnit, auraName, auraIcon, auraExpTime, aura.priority)
button.spells[auraName] = t
end
elseif (eventType == "REFRESH" and destUnit) then
local button = self.buttons[destUnit]
if (not button) then return end
local auraId, auraName = ...
if (button.spells[auraName] and t > button.spells[auraName]) then
self:AuraGain(destUnit, auraName)
local Auras = Gladdy.modules.Auras
local aura = Auras.auras[auraName]
self:Call("Diminishings", "Fade", destUnit, auraName)
local factor = self:Call("Diminishings", "Gain", destUnit, auraName)
if (aura and aura.priority >= (Auras.frames[destUnit].priority or 0)) then
local auraIcon = select(3, GetSpellInfo(auraId))
local auraExpTime = aura.duration / (factor or 1)
self:SendMessage("AURA_GAIN", destUnit, auraName, auraIcon, auraExpTime, aura.priority)
button.spells[auraName] = t
end
end
elseif (eventType == "FADE" and destUnit) then
local button = self.buttons[destUnit]
if (not button) then return end
local auraId, auraName = ...
self:AuraFade(destUnit, auraName)
self:Call("Diminishings", "Fade", destUnit, auraName)
local Auras = Gladdy.modules.Auras
if (auraName == Auras.frames[destUnit].name) then
self:SendMessage("AURA_FADE", destUnit)
button.spells[auraName] = nil
end
elseif (eventType == "CASTSTART" and srcUnit) then
local fromTarget = CombatLog_Object_IsA(sourceFlags, COMBATLOG_OBJECT_TARGET)
local fromFocus = CombatLog_Object_IsA(sourceFlags, COMBATLOG_OBJECT_FOCUS)
if (not fromTarget and not fromFocus) then
local spellId, spellName = ...
local icon = select(3, GetSpellInfo(spellId))
local castTime = self.CAST_TIMES[spellName] or select(7, GetSpellInfo(spellId)) / 1000
self:CastStart(srcUnit, spellName, icon, 0, castTime, "cast")
end
elseif (eventType == "CASTSUCCESS" and srcUnit) then
local spellId, spellName = ...
self:CastSuccess(srcUnit, spellName)
elseif (eventType == "CASTEND" and srcUnit) then
local fromTarget = CombatLog_Object_IsA(sourceFlags, COMBATLOG_OBJECT_TARGET)
local fromFocus = CombatLog_Object_IsA(sourceFlags, COMBATLOG_OBJECT_FOCUS)
if (not fromTarget and not fromFocus) then
self:SendMessage("CAST_END", srcUnit)
end
elseif (eventType == "INTERRUPT" and srcUnit) then
self:SendMessage("CAST_END", srcUnit)
end
end
function Gladdy:PLAYER_TARGET_CHANGED()
local guid = UnitGUID("target")
if (guid and self:IsValid("target")) then
self:UpdateGUID(guid, "target")
end
for k, v in pairs(self.buttons) do
self:Call("Highlight", "Toggle", k, "target", guid and guid == v.guid)
end
end
function Gladdy:PLAYER_FOCUS_CHANGED()
local guid = UnitGUID("focus")
if (guid and self:IsValid("focus")) then
self:UpdateGUID(guid, "focus")
end
for k, v in pairs(self.buttons) do
self:Call("Highlight", "Toggle", k, "focus", guid and guid == v.guid)
end
end
function Gladdy:UPDATE_MOUSEOVER_UNIT()
local guid = UnitGUID("mouseover")
if (guid and self:IsValid("mouseover")) then
self:UpdateGUID(guid, "mouseover")
end
end
function Gladdy:UNIT_TARGET(event, uid)
if (UnitIsPartyLeader(uid) and UnitName(uid) ~= UnitName("player")) then
local unit = uid .. "target"
local guid = UnitGUID(unit)
if (guid and self:IsValid(unit)) then
self:UpdateGUID(guid, unit)
end
for k, v in pairs(self.buttons) do
self:Call("Highlight", "Toggle", k, "leader", guid and guid == v.guid)
end
end
end
function Gladdy:Sync()
for k, v in pairs(self.buttons) do
if (v.guid ~= "") then
if (not v._health or not v._power or v.health ~= v._health or v.power ~= v._power) then
local message = ("%s,%s,%s,%s,%s,%s,%d,%d,%d,%d,%d"):format(
v.name, v.guid, v.class, v.classLoc, v.raceLoc, v.spec,
v.health, v.healthMax, v.power, v.powerMax, v.powerType
)
v._health = v.health
v._power = v.power
self:SendCommMessage("Gladdy", message, "PARTY", nil, "ALERT")
end
end
end
end
function Gladdy:OnCommReceived(prefix, message, dest, sender)
if (prefix == "Gladdy" and sender ~= UnitName("player")) then
local name, guid, class, classLoc, raceLoc, spec, health, healthMax, power, powerMax, powerType = strsplit(',', message)
health, healthMax = tonumber(health), tonumber(healthMax)
power, powerMax, powerType = tonumber(power), tonumber(powerMax), tonumber(powerType)
local unit = self.guids[guid]
if (not unit) then
unit = self:EnemySpotted(name, guid, class, classLoc, raceLoc)
end
local button = self.buttons[unit]
if (not button) then return end
button.health = health
button.healthMax = healthMax
self:SendMessage("UNIT_HEALTH", unit, health, healthMax)
button.power = power
button.powerMax = powerMax
button.powerType = powerType
self:SendMessage("UNIT_POWER", unit, power, powerMax, powerType)
if (spec ~= "") then
self:DetectSpec(unit, spec)
end
end
end
function Gladdy:GetButton(uid)
local guid = UnitGUID(uid)
local unit = self.guids[guid]
return self.buttons[unit]
end
function Gladdy:AuraGain(unit, aura)
local button = self.buttons[unit]
if (not button) then return end
if (aura == self.NS) then
button.ns = true
elseif (aura == self.NF) then
button.nf = true
elseif (aura == self.POM) then
button.pom = true
elseif (aura == self.FD) then
button.fd = true
end
self:Call("Announcements", "CheckDrink", unit, aura)
self:DetectSpec(unit, self.specBuffs[aura])
end
function Gladdy:AuraFade(unit, aura)
local button = self.buttons[unit]
if (not button) then return end
if (aura == self.NS) then
button.ns = false
elseif (aura == self.NF) then
button.nf = false
elseif (aura == self.POM) then
button.pom = false
elseif (aura == self.FD) then
button.fd = false
end
end
function Gladdy:CastStart(unit, spell, icon, value, maxValue, event)
local button = self.buttons[unit]
if (not button) then return end
if (button.ns or button.pom or (button.nf and spell == self.SHADOWBOLT) or self.INSTANT[spell]) then
self:CastSuccess(unit, spell)
return
elseif (button.fd and self.SUMMON[spell]) then
maxValue = 0.5
end
self:SendMessage("CAST_START", unit, spell, icon, value, maxValue, event)
self:DetectSpec(unit, self.specSpells[spell])
end
function Gladdy:CastSuccess(unit, spell)
self:DetectSpec(unit, self.specSpells[spell])
end
function Gladdy:DetectSpec(unit, spec)
local button = self.buttons[unit]
if (not button or not spec or button.spec ~= "") then return end
button.spec = spec
self:SendMessage("UNIT_SPEC", unit, spec)
end
function Gladdy:IsValid(uid)
if (UnitExists(uid) and UnitName(uid) and UnitIsPlayer(uid) and UnitCanAttack("player", uid) and not UnitIsCharmed(uid) and not UnitIsCharmed("player")) then
return true
end
end
function Gladdy:UpdateGUID(guid, uid)
local unit = self.guids[guid]
if (not unit) then
local name = UnitName(uid)
local classLoc, class = UnitClass(uid)
local raceLoc = UnitRace(uid)
unit = self:EnemySpotted(name, guid, class, classLoc, raceLoc)
end
self:UNIT_AURA(nil, uid)
self:UNIT_HEALTH(nil, uid)
self:UNIT_POWER(nil, uid)
end
function Gladdy:EnemySpotted(name, guid, class, classLoc, raceLoc)
local unit = "arena" .. self.curUnit
self.curUnit = self.curUnit + 1
self.guids[guid] = unit
local button = self.buttons[unit]
if (not button) then return end
button.name = name
button.guid = guid
button.class = class
button.classLoc = classLoc
button.raceLoc = raceLoc
self:SendMessage("ENEMY_SPOTTED", unit)
button:SetAlpha(1)
return unit
end