-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
NugRunning.lua
2476 lines (2199 loc) · 86 KB
/
NugRunning.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 _, helpers = ...
local NugRunning = CreateFrame("Frame","NugRunning", UIParent)
NugRunning:SetScript("OnEvent", function(self, event, ...)
return self[event](self, event, ...)
end)
local L = setmetatable({}, {
__index = function(t, k)
-- print(string.format('L["%s"] = ""',k:gsub("\n","\\n")));
return k
end,
__call = function(t,k) return t[k] end,
})
helpers.L = L
NugRunning.L = L
--- Compatibility with Classic
local apiLevel = math.floor(select(4,GetBuildInfo())/10000)
local isClassic = apiLevel <= 3
local isBC = apiLevel == 2
local isMainline = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE -- WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
-- local isClassic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local UnitSpellHaste = UnitSpellHaste
if apiLevel <= 2 then UnitSpellHaste = function() return 0 end end
if apiLevel == 3 then
local GetCombatRatingBonus = GetCombatRatingBonus
local CR_HASTE_SPELL = CR_HASTE_SPELL
UnitSpellHaste = function() return GetCombatRatingBonus(CR_HASTE_SPELL) end
end
local GetSpecialization = isClassic and function() return nil end or _G.GetSpecialization
local LoadAddOn = LoadAddOn or C_AddOns.LoadAddOn
local NRunDB = nil
local config = NugRunningConfig
local spells = config.spells
local activations = config.activations
local cooldowns = config.cooldowns
local itemcooldowns = config.itemcooldowns
local event_timers = config.event_timers
local nameplates
local MAX_TIMERS = 20
local check_event_timers
local UpdateUnitAuras
local playerGUID
local alltimers = {}
local timersByGUID = {}
local timersByGUIDCounter = {}
local active = {}
local free = {}
function NugRunning:SetActive(timer)
rawset(free,timer,nil)
rawset(active,timer,true)
if not timer.isExternal then
NugRunning:AddTimerToGUID(timer.dstGUID, timer)
end
end
function NugRunning:FreeTimer(timer, skipGhost)
if timer.opts then
if timer.opts.with_cooldown then
local cd_opts = timer.opts.with_cooldown
config.cooldowns[cd_opts.id] = cd_opts
NugRunning:SPELL_UPDATE_COOLDOWN()
else
if not skipGhost then
if NRunDB.leaveGhost and (timer.opts.ghost or timer.scheduledGhost) and not timer.isGhost then return timer:BecomeGhost() end
if timer.isGhost and not timer.expiredGhost then return end
end
timer.isGhost = nil
timer.expiredGhost = nil
end
end
timer:Hide()
rawset(active,timer,nil)
if not timer.isExternal then
free[timer] = true
NugRunning:RemoveTimerFromGUID(timer.dstGUID, timer)
end
NugRunning:ArrangeTimers()
end
function NugRunning:FindFirstActiveTimer(spellID)
for timer in pairs(active) do
if timer.spellID == spellID and not timer.isGhost then
return timer
end
end
end
local gettimer = function(self,spellID,dstGUID,timerType)
local foundTimer
local spellActiveTimers = 0
if type(spellID) == "number" then
local baseSpellID = config.spellClones[spellID] or spellID
for timer in pairs(self) do
if timer.baseSpellID == baseSpellID and timer.timerType == timerType then
spellActiveTimers = spellActiveTimers + 1
if timer.dstGUID == dstGUID then
foundTimer = timer
break
end
end
end
else -- comparing by opts table, instead of
for timer in pairs(self) do
if timer.opts == spellID and timer.timerType == timerType then
spellActiveTimers = spellActiveTimers + 1
if timer.dstGUID == dstGUID then
foundTimer = timer
break
end
end
end
end
return foundTimer, spellActiveTimers
end
local IsPlayerSpell = IsPlayerSpell
local GetSpellInfo = helpers.GetSpellInfo
local GetSpellTexture = helpers.GetSpellTexture
local string_sub = string.sub
local RetailGetSpellCooldown = function(...)
local C_Spell_GetSpellCooldown = C_Spell.GetSpellCooldown
local info = C_Spell_GetSpellCooldown(...)
return info.startTime, info.duration, info.enabled, info.modRate
end
local GetSpellCooldown = GetSpellCooldown or RetailGetSpellCooldown
local GetSpellCharges = GetSpellCharges or C_Spell.GetSpellCharges
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local bit_band = bit.band
local strfind = string.find
local DeprecatedUnitAura = function(unitToken, index, filter)
local auraData = C_UnitAuras.GetAuraDataByIndex(unitToken, index, filter);
if not auraData then
return nil;
end
return AuraUtil.UnpackAuraData(auraData);
end
local UnitAura = UnitAura or DeprecatedUnitAura
local UnitGUID = UnitGUID
local table_wipe = table.wipe
local CheckSpec = helpers.CheckSpec
local COMBATLOG_OBJECT_AFFILIATION_MASK = COMBATLOG_OBJECT_AFFILIATION_MASK
local AFFILIATION_MINE = COMBATLOG_OBJECT_AFFILIATION_MINE
local AFFILIATION_PARTY_OR_RAID = COMBATLOG_OBJECT_AFFILIATION_RAID + COMBATLOG_OBJECT_AFFILIATION_PARTY
local AFFILIATION_OUTSIDER = COMBATLOG_OBJECT_AFFILIATION_OUTSIDER
local COMBATLOG_HOSTILE_PLAYER = COMBATLOG_OBJECT_CONTROL_PLAYER + COMBATLOG_OBJECT_REACTION_HOSTILE
local lastCastSpellID
NugRunning.active = active
NugRunning.free = free
NugRunning.timers = alltimers
NugRunning.gettimer = gettimer
NugRunning.helpers = helpers
local defaultFont = "AlegreyaSans-Medium"
local defaultShowLocalNames = false
do
local locale = GetLocale()
if locale == "zhTW" or locale == "zhCN" or locale == "koKR" then
defaultFont = LibStub("LibSharedMedia-3.0").DefaultMedia["font"]
defaultShowLocalNames = true
-- "預設" - zhTW
-- "默认" - zhCN
-- "기본 글꼴" - koKR
end
end
local defaults = {
anchors = {
main = {
point = "CENTER",
parent = "UIParent",
to = "CENTER",
x = 0,
y = 0,
},
secondary = {
point = "CENTER",
parent = "UIParent",
to = "CENTER",
x = -200,
y = 0,
},
},
groups = {
player = { order = 1, name = "player", gap = 10, alpha = 1, anchor = "main" },
target = { order = 2, name = "target", gap = 10, alpha = 1, anchor = "main"},
buffs = { order = 3, name = "buffs", gap = 25, alpha = 1, anchor = "main"},
offtargets = { order = 4, name = "offtargets", gap = 6, alpha = .7, anchor = "main"},
procs = { order = 1, name = "procs", gap = 10, alpha = .8, anchor = "secondary"},
},
growth = "up",
width = 150,
height = 20,
np_height = 7,
np_width = 74,
np_xoffset = 0,
np_yoffset = 0,
cooldownsEnabled = true,
missesEnabled = true,
targetTextEnabled = false,
spellTextEnabled = true,
shortTextEnabled = true,
swapTarget = true,
localNames = defaultShowLocalNames,
totems = true,
leaveGhost = true,
nameplates = true,
preghost = true,
dotpower = true,
dotticks = true,
textureName = "Aluminium",
nptextureName = "Aluminium",
nameFont = { font = defaultFont, size = 10, alpha = 0.5, outline = false },
timeFont = { font = defaultFont, size = 8, alpha = 1, outline = false },
stackFont = { font = defaultFont, size = 12, outline = true },
}
local MergeTable = helpers.MergeTable
local RemoveDefaultsPreserve = helpers.RemoveDefaultsPreserve
local RemoveDefaults = helpers.RemoveDefaults
local SetupDefaults = helpers.SetupDefaults
NugRunning.SetupDefaults = SetupDefaults
NugRunning.RemoveDefaults = RemoveDefaults
NugRunning.RemoveDefaultsPreserve = RemoveDefaultsPreserve
NugRunning.MergeTable = MergeTable
NugRunning:RegisterEvent("PLAYER_LOGIN")
NugRunning:RegisterEvent("PLAYER_LOGOUT")
function NugRunning.PLAYER_LOGIN(self,event,arg1)
NRunDB_Global = NRunDB_Global or {}
NRunDB_Char = NRunDB_Char or {}
NRunDB_Global.charspec = NRunDB_Global.charspec or {}
local user = UnitName("player").."@"..GetRealmName()
if NRunDB_Global.charspec[user] then
NRunDB = NRunDB_Char
else
NRunDB = NRunDB_Global
end
NugRunning.db = NRunDB
SetupDefaults(NRunDB, defaults)
NugRunningConfigCustom = NugRunningConfigCustom or {}
NugRunningConfigMerged = CopyTable(NugRunningConfig)
local _, class = UnitClass("player")
local categories = {"spells", "cooldowns", "activations", "casts"}
if not NugRunningConfigCustom[class] then NugRunningConfigCustom[class] = {} end
local function fixRemovedDefaultSpells(customConfig, defaultConfig)
if not (customConfig and defaultConfig) then return end
local toRemove = {}
for spellID, opts in pairs(customConfig) do
local dopts = defaultConfig[spellID]
if not dopts and not opts.name then
table.insert(toRemove, spellID)
elseif opts.name then -- then it's a is probably an added spell
opts.isAdded = true -- making sure it's marked as added
end
end
for _, spellID in ipairs(toRemove) do
customConfig[spellID] = nil
end
end
local globalConfig = NugRunningConfigCustom["GLOBAL"]
if globalConfig then
for _, category in ipairs(categories) do
fixRemovedDefaultSpells(globalConfig[category], config[category])
end
end
MergeTable(NugRunningConfigMerged, globalConfig)
local classConfig = NugRunningConfigCustom[class]
if classConfig then
for _, category in ipairs(categories) do
fixRemovedDefaultSpells(classConfig[category], config[category])
end
end
MergeTable(NugRunningConfigMerged, classConfig)
config = NugRunningConfigMerged
spells = config.spells
activations = config.activations
cooldowns = config.cooldowns
itemcooldowns = config.itemcooldowns
event_timers = config.event_timers
-- filling up ranks for spells and casts
local cloneIDs = {}
local rankCategories = { "spells", "casts" }
local tempTable = {}
for _, category in ipairs(rankCategories) do
table.wipe(tempTable)
for spellID, opts in pairs(config[category]) do
if not cloneIDs[spellID] and opts.clones then
opts.clones[spellID] = nil -- Removing possible input of original spell ID into clone list
for i, additionalSpellID in ipairs(opts.clones) do
tempTable[additionalSpellID] = opts
cloneIDs[additionalSpellID] = spellID
end
end
end
for spellID, opts in pairs(tempTable) do
config[category][spellID] = opts
end
end
config.spellClones = cloneIDs
NugRunning:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
if not isClassic then NugRunning:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") end
NugRunning.ACTIVE_TALENT_GROUP_CHANGED = NugRunning.ReInitSpells
-- NugRunning:RegisterEvent("PLAYER_TALENT_UPDATE")
-- NugRunning.PLAYER_TALENT_UPDATE = NugRunning.ReInitSpells
NugRunning.CHARACTER_POINTS_CHANGED = NugRunning.ReInitSpells
NugRunning.SPELLS_CHANGED = NugRunning.ReInitSpells
NugRunning:RegisterEvent("CHARACTER_POINTS_CHANGED")
NugRunning:RegisterEvent("SPELLS_CHANGED")
NugRunning:RegisterUnitEvent("UNIT_POWER_UPDATE", "player")
NugRunning:ReInitSpells()
NugRunning:RegisterEvent("PLAYER_TARGET_CHANGED")
NugRunning:RegisterEvent("UNIT_AURA")
if apiLevel > 1 then NugRunning:RegisterEvent("UPDATE_MOUSEOVER_UNIT") end
if NRunDB.cooldownsEnabled then
NugRunning:RegisterEvent("SPELL_UPDATE_COOLDOWN")
if C_Timer then
NugRunning.cooldownTicker = C_Timer.NewTicker(1, function()
NugRunning:SPELL_UPDATE_COOLDOWN("PERIODIC_COOLDOWN_UPDATE", true)
end)
end
end
if NRunDB.nameplates then
local found
for _, opts in pairs(config.spells) do
if opts.nameplates then found = true; break end
end
if found then
NugRunning:DoNameplates()
nameplates = NugRunningNameplates
end
end
--NugRunning:RegisterEvent("SPELL_UPDATE_USABLE")
if not isClassic then
NugRunning:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
NugRunning:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
end
if next(event_timers) then check_event_timers = true end
playerGUID = UnitGUID("player")
NugRunning.anchors = {}
for name, opts in pairs(NRunDB.anchors) do
local anchor = NugRunning:CreateAnchor(name, opts)
NugRunning.anchors[name] = anchor
end
NugRunning.targetIndicator = NugRunning:CreateTargetIndicator()
NugRunning:SetupArrange()
for i=1,MAX_TIMERS do
local timer = NugRunning:CreateTimer()
timer:Release()
end
--remove timer from the pool and change it to castbar
local cbt = NugRunning:ExtractFromPool()
NugRunning:CreateCastbarTimer(cbt)
local _,class = UnitClass("player")
if (class == "DRUID") and NRunDB.dotpower then
NugRunning.dotpowerFrame:RegisterUnitEvent("UNIT_AURA", "player")
end
SLASH_NUGRUNNING1= "/nugrunning"
SLASH_NUGRUNNING2= "/nrun"
SlashCmdList["NUGRUNNING"] = NugRunning.SlashCmd
if NRunDB.totems and NugRunning.InitTotems then NugRunning:InitTotems() end
NugRunning.SetupSpecialTimers()
local f = CreateFrame('Frame', nil, SettingsPanel or InterfaceOptionsFrame)
f:SetScript('OnShow', function(self)
self:SetScript('OnShow', nil)
LoadAddOn('NugRunningOptions')
end)
end
function NugRunning.PLAYER_LOGOUT(self, event)
RemoveDefaults(NRunDB, defaults)
end
--------------------
-- CLEU dispatcher
--------------------
function NugRunning.COMBAT_LOG_EVENT_UNFILTERED( self, event )
local timestamp, eventType, hideCaster,
srcGUID, srcName, srcFlags, srcFlags2,
dstGUID, dstName, dstFlags, dstFlags2,
spellID, spellName, spellSchool, auraType, amount = CombatLogGetCurrentEventInfo()
if spells[spellID] then
local affiliationStatus = (bit_band(srcFlags, AFFILIATION_MINE) == AFFILIATION_MINE)
local opts = spells[spellID]
if not affiliationStatus and opts.affiliation then
affiliationStatus = (bit_band(srcFlags, COMBATLOG_OBJECT_AFFILIATION_MASK) <= opts.affiliation)
end
if opts.singleTarget then
if dstGUID ~= UnitGUID("target") then return end
else
if opts.target and dstGUID ~= UnitGUID(opts.target) then return end
end
if affiliationStatus then
if eventType == "SPELL_AURA_REFRESH" then
self:RefreshTimer(srcGUID, dstGUID, dstName, dstFlags, spellID, spellName, opts, auraType, nil, amount)
elseif eventType == "SPELL_AURA_APPLIED_DOSE" then
self:RefreshTimer(srcGUID, dstGUID, dstName, dstFlags, spellID, spellName, opts, auraType, nil, amount, opts._ignore_applied_dose)
elseif eventType == "SPELL_AURA_APPLIED" then
self:ActivateTimer(srcGUID, dstGUID, dstName, dstFlags, spellID, spellName, opts, auraType)
elseif eventType == "SPELL_AURA_REMOVED" then
self:DeactivateTimer(srcGUID, dstGUID, spellID, spellName, opts, auraType)
elseif eventType == "SPELL_AURA_REMOVED_DOSE" then
self:RemoveDose(srcGUID, dstGUID, spellID, spellName, auraType, amount)
elseif eventType == "SPELL_MISSED" then
if NRunDB.missesEnabled then
self:ActivateTimer(srcGUID, dstGUID, dstName, dstFlags, spellID, spellName, opts, "MISSED", auraType) -- auraType = missType in this case
end
elseif eventType == "SPELL_CAST_SUCCESS" then
lastCastSpellID = spellID
end
end
end
if check_event_timers then
if event_timers[spellID] then
local opts = event_timers[spellID]
local opts_event = opts.event
if opts_event == eventType or (type(opts_event) == "table" and opts_event[eventType]) then
local affiliationStatus = (bit_band(srcFlags, AFFILIATION_MINE) == AFFILIATION_MINE)
if affiliationStatus or (opts.affiliation and bit_band(srcFlags, COMBATLOG_OBJECT_AFFILIATION_MASK) <= opts.affiliation ) then
-- if spellID == opts.spellID then
if dstGUID == "" then dstGUID = srcGUID end
if opts.action and not opts.disabled then
opts.action(active, srcGUID, dstGUID, spellID, auraType) -- auraType = damage amount for SPELL_DAMAGE
else
self:ActivateTimer(playerGUID, dstGUID, dstName, nil, spellID, spellName, opts, "EVENT", opts.duration)
-- break
end
-- end
end
end
end
end
if eventType == "UNIT_DIED" or eventType == "UNIT_DESTROYED" then
self:DeactivateTimersOnDeath(dstGUID)
end
end
---------------------------------
-- ACTIVATION OVERLAY & USABLE
---------------------------------
function NugRunning.SPELL_ACTIVATION_OVERLAY_GLOW_SHOW(self,event, spellID)
if activations[spellID] then
local opts = activations[spellID]
if not opts.for_cd then
if opts.showid then spellID = opts.showid end
local timer = self:ActivateTimer(UnitGUID("player"),UnitGUID("player"), UnitName("player"), nil, spellID, opts.localname, opts, "ACTIVATION", opts.duration)
if opts.instantGhost then
timer:BecomeGhost()
end
else
local cd_opts = cooldowns[spellID]
local timer = gettimer(active,spellID, playerGUID, "COOLDOWN")
if not timer then
timer = self:ActivateTimer(playerGUID, playerGUID, UnitName("player"), nil, spellID, GetSpellInfo(spellID), cd_opts, "COOLDOWN", 5)
if not timer then return end
timer:BecomeGhost(opts.ghost) -- overriding the normal ghost length with the one in activation's opts
end
if opts.effect then
timer.effect:SetEffect(opts.effect)
timer.effect:Show()
end
local arrow = opts.arrow
if arrow then
local color = arrow[3] and arrow or {1,0,0}
timer.arrow:SetVertexColor(unpack(color))
timer.arrow:Show()
end
end
end
end
function NugRunning.SPELL_ACTIVATION_OVERLAY_GLOW_HIDE(self,event, spellID)
if activations[spellID] then
local opts = activations[spellID]
if not opts.for_cd then
if opts.showid then spellID = opts.showid end
self:DeactivateTimer(UnitGUID("player"),UnitGUID("player"), spellID, nil, opts, "ACTIVATION")
else
-- local cd_opts = cooldowns[spellID]
local timer = gettimer(active,spellID,UnitGUID("player"),"COOLDOWN")
if timer then
if opts.effect then
timer.effect:SetEffect(opts.effect)
timer.effect:Hide()
end
if opts.arrow then
timer.arrow:Hide()
end
end
end
end
end
---------------------------
-- COOLDOWNS
---------------------------
local function GetSpellCooldownCharges(spellID)
local startTime, duration, enabled = GetSpellCooldown(spellID)
local charges, maxCharges, chargeStart, chargeDuration = GetSpellCharges(spellID)
if charges and charges ~= maxCharges then
startTime = chargeStart
duration = chargeDuration
end
return startTime, duration, enabled, charges, maxCharges
end
local activeCooldownTimers = {}
local gcdDuration = 1.5
local wandUserMinDuration
if isClassic then
local _, class = UnitClass("player")
if class == "WARLOCK" or class == "MAGE" or class == "PRIEST" then
wandUserMinDuration = 3
end
end
local function CheckCooldown(spellID, opts, startTime, duration, enabled, charges, maxCharges, isItem)
local cdType = isItem and "ITEMCOOLDOWN" or "COOLDOWN"
local timer
local old_timer = activeCooldownTimers[spellID]
if old_timer and (old_timer.spellID == spellID and old_timer.timerType == cdType) then
timer = old_timer
end
if opts.replaces then
timer = gettimer(active, opts.replaces, UnitGUID("player"), cdType)
end
if duration then
if duration <= gcdDuration then
if timer and timer:IsActive() then
local oldcdrem = timer.endTime - GetTime()
if oldcdrem > duration or oldcdrem < 0 then
if not timer.isGhost then
timer:Release()
if timer.isGhost and not timer.shine:IsPlaying() then timer.shine:Play() end
activeCooldownTimers[spellID] = nil
end
end
end
else
if not timer or not timer:IsActive() or timer.isGhost then
local mdur = opts.minduration or wandUserMinDuration
local time_remains = (duration + startTime) - GetTime()
local mrem = opts.hide_until
local isKnown = true
if opts.isknowncheck then
isKnown = opts.isknowncheck()
end
if isKnown and (not mdur or duration > mdur) and (not mrem or time_remains < mrem) then
timer = NugRunning:ActivateTimer(UnitGUID("player"),UnitGUID("player"), UnitName("player"), nil, spellID, opts.localname, opts, cdType, time_remains)
else
if timer and timer.isGhost then
timer:GhostExpire()
end
end
if timer then
timer.cd_startTime = startTime
timer.cd_duration = duration
timer.fixedoffset = timer.opts.fixedlen and duration - timer.opts.fixedlen or 0
timer:SetTime(startTime, startTime + duration, timer.fixedoffset)
activeCooldownTimers[spellID] = timer
end
else
-- print("1", spellID, startTime, duration)
local mdur = opts.minduration or wandUserMinDuration
if (timer.cd_startTime ~= startTime or timer.cd_duration ~= duration) and (not mdur or duration > mdur) then
timer.cd_startTime = startTime
timer.fixedoffset = timer.opts.fixedlen and duration - timer.opts.fixedlen or 0
timer:SetTime(startTime, startTime + duration, timer.fixedoffset)
-- elseif timer.cd_duration ~= duration then
end
if opts.replaces then
local name,_, texture = GetSpellInfo(spellID)
timer:SetIcon(texture)
timer:SetName(NugRunning:MakeName(opts, name, timer.dstName) )
if opts.color then timer:SetColor(unpack(opts.color)) end
end
activeCooldownTimers[spellID] = timer
end
if charges and timer then
activeCooldownTimers[spellID]:SetCount(maxCharges-charges)
end
end
end
end
local lastCooldownUpdateTime = GetTime()
function NugRunning.SPELL_UPDATE_COOLDOWN(self,event, periodic)
if periodic and GetTime() - lastCooldownUpdateTime < 0.9 then return end
if isMainline then
gcdDuration = select(2,GetSpellCooldown(61304)) -- gcd spell
end
for spellID,opts in pairs(cooldowns) do
if not opts.check_known or IsPlayerSpell(spellID) then
local startTime, duration, enabled, charges, maxCharges = GetSpellCooldownCharges(spellID)
CheckCooldown(spellID, opts, startTime, duration, enabled, charges, maxCharges)
end
end
for itemID,opts in pairs(itemcooldowns) do
local startTime, duration, enabled = GetItemCooldown(itemID)
CheckCooldown(itemID, opts, startTime, duration, enabled, nil, nil, true)
end
lastCooldownUpdateTime = GetTime()
end
local helpful = "HELPFUL"
local harmful = "HARMFUL"
function NugRunning.ActivateTimer(self,srcGUID,dstGUID,dstName,dstFlags, spellID, spellName, opts, timerType, override, amount, from_unitaura) -- duration override
if opts.disabled then return end
if opts.target then
if opts.target == "pvp" then
if string_sub(dstGUID,1,6) ~= "Player" then return end
else
if dstGUID ~= UnitGUID(opts.target) then return end
end
end
if timerType == "MISSED" then
if override == "IMMUNE" or override == "ABSORB" then return end
opts = { duration = 3, color = NugRunningConfig.colors.MISSED, scale = .8, maxtimers = 1, priority = opts.priority or 99999, shine = true }
end
if opts.specmask then
local spec = GetSpecialization()
if spec then
if not CheckSpec(opts.specmask, spec) then return end
end
end
local multiTargetGUID
if opts.multiTarget then multiTargetGUID = dstGUID; dstGUID = nil; end
local timer, totalTimers = gettimer(active, opts,dstGUID,timerType) -- finding timer by opts table id
if timer then
-- spellID = timer.spellID -- swapping current id for existing timer id in case they're different
-- refresh will be searching by spellID again
if multiTargetGUID then timer.targets[multiTargetGUID] = true end
return self:RefreshTimer(srcGUID, dstGUID or multiTargetGUID, dstName, dstFlags, spellID, spellName, opts, timerType, override, amount, from_unitaura)
end
if opts.maxtimers and totalTimers >= opts.maxtimers then
-- if UnitGUID("target") ~= dstGUID then
-- return
-- end
if UnitGUID("target") == dstGUID then
local deltimer
for t in pairs(active) do
if t.opts == opts and (not deltimer or deltimer._touched > t._touched) then
deltimer = t
end
end
if deltimer then
deltimer.isGhost = true
deltimer.expiredGhost = true
-- deltimer.timeless = false
deltimer:Release()
end
else
return
end
end
timer = NugRunning:AcquireTimer()
if not timer then return end
timer.srcGUID = srcGUID
timer.dstGUID = dstGUID
timer.dstName = dstName
timer.spellID = spellID
timer.baseSpellID = config.spellClones[spellID] or spellID
timer.spellName = spellName
timer.timerType = timerType
timer:SetActive(true)
timer:SetScript("OnUpdate",NugRunning.TimerFunc)
if multiTargetGUID then timer.targets[multiTargetGUID] = true end
timer._touched = GetTime()
if opts.init and not opts.init_done then
opts:init()
opts.init_done = true
end
if not from_unitaura then
if opts.tick and NRunDB.dotticks then
timer.tickPeriod = opts.tick > 0 and (opts.tick/(1+(UnitSpellHaste("player")/100))) or math.abs(opts.tick)
timer.mark.fullticks = nil
else
timer.tickPeriod = nil
end
local plevel = self:GetPowerLevel(spellID)
timer.powerLevel = plevel
self:UpdateTimerPower(timer, plevel)
end
if opts.isItem then
timer:SetIcon(select(5,GetItemInfoInstant(spellID)))
else
timer:SetIcon(select(3,GetSpellInfo(opts.showid or spellID)))
end
timer.opts = opts
timer.onupdate = opts.onupdate
if timerType == "BUFF"
then timer.filter = "HELPFUL"
else timer.filter = "HARMFUL"
end
local time
if timerType == "MISSED" then
time = opts.duration
elseif override then time = override
else
time = NugRunning.SetDefaultDuration(dstFlags, opts, timer)
-- print( "DEFAULT TIME", spellName, time, timerType)
if timerType == "BUFF" or timerType == "DEBUFF" then
local _guid = multiTargetGUID or dstGUID
local uaTime, uaCount = NugRunning.QueueAura(spellID, _guid, timerType, timer)
if uaTime then
time = uaTime
amount = uaCount
end
end
end
if timer.VScale then
local scale = opts.scale
if scale then
timer:VScale(scale)
else
timer:VScale(1)
end
end
timer.priority = opts.priority or 0
local now = GetTime()
timer.fixedoffset = opts.fixedlen and time - opts.fixedlen or 0
if not opts.color then
if timerType == "DEBUFF" then opts.color = NugRunningConfig.colors.DEFAULT_DEBUFF
else opts.color = NugRunningConfig.colors.DEFAULT_BUFF end
end
timer:SetColor(unpack(opts.color))
timer.timeless = (opts.timeless or opts.charged or override == -1)
timer:EnableSpark(not opts.timeless)
amount = amount or 1
if opts.charged then
timer:ToInfinite()
local max = opts.maxcharge
timer:SetMinMaxCharge(0,max)
if opts.color2 then
timer:SetColor(helpers.GetGradientColor(opts.color2, opts.color, amount/max))
end
timer:SetCharge(amount)
timer:UpdateMark()
elseif timer.timeless then
timer:ToInfinite()
timer:UpdateMark()
timer:SetCount(amount)
else
timer:SetTime(now, now + time, timer.fixedoffset)
timer:SetCount(amount)
end
timer.count = amount
local nameText
if opts.textfunc and type(opts.textfunc) == "function" then
nameText = opts.textfunc(timer)
elseif timerType == "MISSED" then
if override then
nameText = override:sub(1,1)..override:sub(2):lower()
else
nameText = "Miss"
end
else
nameText = NugRunning:MakeName(opts, spellName, dstName)
end
if timer.SetName then timer:SetName(nameText) end
if timer.glow:IsPlaying() then timer.glow:Stop() end
if timer.arrowglow:IsPlaying() then
timer.arrowglow:Stop()
end
local effect = opts.effect
if effect and not opts.effecttime then
timer.effect:SetEffect(effect)
timer.effect:Show()
else
timer.effect:Hide()
end
if opts.scale_until then
if timer:Remains() > opts.scale_until then
timer:VScale(0.4)
timer:SetTime(nil, nil, nil, 0)
end
end
local arrow = opts.arrow
if arrow then
local color = arrow[3] and arrow or {1,0,0}
timer.arrow:SetVertexColor(unpack(color))
timer.arrow:Show()
else
timer.arrow:Hide()
end
-- print(srcGUID,dstGUID,dstName,dstFlags, spellID, spellName, opts, timerType, override, amount)
timer:Show()
if not timer.animIn:IsPlaying() and not from_unitaura then timer.animIn:Play() end
timer.shine.tex:SetAlpha(0)
if opts.shine and not timer.shine:IsPlaying() then timer.shine:Play() end
self:ArrangeTimers()
return timer
end
function NugRunning.RefreshTimer(self,srcGUID,dstGUID,dstName,dstFlags, spellID, spellName, opts, timerType, override, amount, ignore_applied_dose)
local multiTargetGUID
if opts.multiTarget then multiTargetGUID = dstGUID; dstGUID = nil; end
local timer = gettimer(active, opts or spellID,dstGUID,timerType)
if not timer then
return self:ActivateTimer(srcGUID, dstGUID or multiTargetGUID, dstName, dstFlags, spellID, spellName, opts, timerType, override)
end
if (timerType == "COOLDOWN" or timerType == "ITEMCOOLDOWN") and not timer.isGhost then return timer end
-- if timer.isGhost then
timer:SetScript("OnUpdate",NugRunning.TimerFunc)
timer.isGhost = nil
timer.expiredGhost = nil
if not opts.color then
if timerType == "DEBUFF" then opts.color = { 0.8, 0.1, 0.7}
else opts.color = { 1, 0.4, 0.2} end
end
timer:SetColor(unpack(opts.color))
-- end
local time
if override then time = override
else
if not ignore_applied_dose then -- why was it ignoring multi target?
time = NugRunning.SetDefaultDuration(dstFlags, opts, timer)
end
if timerType == "BUFF" or timerType == "DEBUFF" then
local _guid = dstGUID or multiTargetGUID
NugRunning.QueueAura(spellID, _guid, timerType, timer)
end
end
if amount and opts.charged then
local max = opts.maxcharge
timer:SetMinMaxCharge(0,max)
if opts.color2 then
timer:SetColor(helpers.GetGradientColor(opts.color2, opts.color, amount/max))
end
timer:SetCharge(amount)
elseif not timer.timeless then
local now = GetTime()
timer.fixedoffset = opts.fixedlen and time - opts.fixedlen or 0
if time then timer:SetTime(now, now + time, timer.fixedoffset) end
timer:SetCount(amount)
end
timer.count = amount
if not ignore_applied_dose then
if opts.tick and NRunDB.dotticks then
timer.tickPeriod = opts.tick > 0 and (opts.tick/(1+(UnitSpellHaste("player")/100))) or math.abs(opts.tick)
timer.mark.fullticks = nil
else
timer.tickPeriod = nil
end
local plevel = self:GetPowerLevel(spellID)
timer.powerLevel = plevel
self:UpdateTimerPower(timer, plevel)
end
if opts.scale_until then
if timer:Remains() > opts.scale_until then
timer:VScale(0.4)
-- timer:SetTime(nil,nil,
end
end
local effect = opts.effect
if effect and not opts.effecttime then
timer.effect:SetEffect(effect)
timer.effect:Show()
else
timer.effect:Hide()
end
local arrow = opts.arrow
if arrow then
local color = arrow[3] and arrow or {1,0,0}
timer.arrow:SetVertexColor(unpack(color))
timer.arrow:Show()
else
timer.arrow:Hide()
end
timer:UpdateMark()
if timer.glow:IsPlaying() then timer.glow:Stop() end
if timer.arrowglow:IsPlaying() then
timer.arrowglow:Stop()
end
if not ignore_applied_dose and opts.shinerefresh and not timer.shine:IsPlaying() then timer.shine:Play() end -- ignore_applied_dose is the same as noshine
self:ArrangeTimers()
return timer
end
function NugRunning.RemoveDose(self,srcGUID,dstGUID, spellID, spellName, timerType, amount)
for timer in pairs(active) do
if timer.spellID == spellID
and timer.dstGUID == dstGUID
and timer.timerType == timerType
and timer.srcGUID == srcGUID
then
if timer.opts.charged then
local opts = timer.opts
local max = opts.maxcharge
if opts.color2 then
timer:SetColor(helpers.GetGradientColor(opts.color2, opts.color, amount/max))
end
timer:SetCharge(amount)
else
timer:SetCount(amount)
end
timer.count = amount
end
end
end
function NugRunning.DeactivateTimer(self,srcGUID,dstGUID, spellID, spellName, opts, timerType)
local multiTargetGUID
if opts.multiTarget then multiTargetGUID = dstGUID; dstGUID = nil; end
for timer in pairs(active) do
if timer.spellID == spellID
and timer.dstGUID == dstGUID
and timer.timerType == timerType
and timer.srcGUID == srcGUID
then
if multiTargetGUID then