-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
Utils.lua
1107 lines (859 loc) · 36.7 KB
/
Utils.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
-- Utils.lua
-- July 2024
local addon, ns = ...
local Hekili = _G[ addon ]
local format, gsub, lower = string.format, string.gsub, string.lower
local insert, remove = table.insert, table.remove
local class = Hekili.Class
local state = Hekili.State
local GetPlayerAuraBySpellID = C_UnitAuras.GetPlayerAuraBySpellID
local GetBuffDataByIndex, GetDebuffDataByIndex = C_UnitAuras.GetBuffDataByIndex, C_UnitAuras.GetDebuffDataByIndex
local FindAura = AuraUtil.FindAura
local UnpackAuraData = AuraUtil.UnpackAuraData
local GetSpellBookItemInfo = function(index, bookType)
local spellBank = ( bookType == "spell" or bookType == Enum.SpellBookItemType.Spell ) and Enum.SpellBookSpellBank.Player or Enum.SpellBookSpellBank.Pet
local info = C_SpellBook.GetSpellBookItemInfo(index, spellBank)
if info then return info.name, info.icon, info.spellID end
end
ns.UnitBuff = function( unit, index, filter )
return UnpackAuraData( GetBuffDataByIndex( unit, index, filter ) )
end
ns.UnitDebuff = function( unit, index, filter )
return UnpackAuraData( GetDebuffDataByIndex( unit, index, filter ) )
end
ns.UnitBuffByID = function( unitToken, spellID, filter )
local playerOrPet = UnitIsUnit( "player", unitToken ) or UnitIsUnit( "pet", unitToken )
filter = filter or "HELPFUL"
return FindAura( function( _, _, _, ... )
local id, isFromPlayerOrPet = select( 10, ... ), select( 13, ... )
return id == spellID and ( not playerOrPet or isFromPlayerOrPet )
end, unitToken, filter )
end
ns.UnitDebuffByID = function( unitToken, spellID, filter )
local playerOrPet = UnitIsUnit( "player", unitToken ) or UnitIsUnit( "pet", unitToken )
filter = filter or "HARMFUL"
return FindAura( function( _, _, _, ... )
local id, isFromPlayerOrPet = select( 10, ... ), select( 13, ... )
return id == spellID and ( not playerOrPet or isFromPlayerOrPet )
end, unitToken, filter )
end
local UnitBuff, UnitDebuff = ns.UnitBuff, ns.UnitDebuff
local UnitBuffByID, UnitDebuffByID = ns.UnitBuffByID, ns.UnitDebuffByID
local GetItemInfo = C_Item.GetItemInfo
local GetSpellInfo = C_Spell.GetSpellInfo
local errors = {}
local eIndex = {}
ns.Error = function( output, ... )
if ... then
output = format( output, ... )
end
if not errors[ output ] then
errors[ output ] = {
n = 1,
last = date( "%X", time() )
}
eIndex[ #eIndex + 1 ] = output
-- if Hekili.DB.profile.Verbose then Hekili:Print( output ) end
else
errors[ output ].n = errors[ output ].n + 1
errors[ output ].last = date( "%X", time() )
end
end
function Hekili:Error( ... )
ns.Error( ... )
end
Hekili.ErrorKeys = eIndex
Hekili.ErrorDB = errors
function Hekili:GetErrors()
for i = 1, #eIndex do
Hekili:Print( eIndex[i] .. " (n = " .. errors[ eIndex[i] ].n .. "), last at " .. errors[ eIndex[i] ].last .. "." )
end
end
function ns.SpaceOut( str )
str = str:gsub( "([!<>=|&()*%-%+/][?]?)", " %1 " ):gsub("%s+", " ")
str = str:gsub( "([^%%])([%%]+)([^%%])", "%1 %2 %3" )
str = str:gsub( "%.%s+%(", ".(" )
str = str:gsub( "%)%s+%.", ")." )
str = str:gsub( "([<>~!|]) ([|=])", "%1%2" )
str = str:trim()
return str
end
local LT = LibStub( "LibTranslit-1.0" )
-- Converts `s' to a SimC-like key: strip non alphanumeric characters, replace spaces with _, convert to lower case.
function ns.formatKey( s )
s = s:gsub( "|c........", "" ):gsub( "|r", "" )
s = LT:Transliterate( s )
s = lower( s or '' ):gsub( "[^a-z0-9_ ]", "" ):gsub( "%s+", "_" )
return s
end
ns.titleCase = function( s )
local helper = function( first, rest )
return first:upper()..rest:lower()
end
return s:gsub( "_", " " ):gsub( "(%a)([%w_']*)", helper ):gsub( "[Aa]oe", "AOE" ):gsub( "[Rr]jw", "RJW" ):gsub( "[Cc]hix", "ChiX" ):gsub( "(%W?)[Ss]t(%W?)", "%1ST%2" )
end
local replacements = {
['_'] = " ",
aoe = "AOE",
rjw = "RJW",
chix = "ChiX",
st = "ST",
cd = "CD",
cds = "CDs"
}
ns.titlefy = function( s )
for k, v in pairs( replacements ) do
s = s:gsub( '%f[%w]' .. k .. '%f[%W]', v ):gsub( "_", " " )
end
return s
end
ns.fsub = function( s, pattern, repl )
return s:gsub( "%f[%w]" .. s .. "%f[%W]", repl )
end
ns.escapeMagic = function( s )
return s:gsub( "([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1" )
end
local tblUnpack = {}
ns.multiUnpack = function( ... )
table.wipe( tblUnpack )
for i = 1, select( '#', ... ) do
for _, value in ipairs( select( i, ... ) ) do
tblUnpack[ #tblUnpack + 1 ] = value
end
end
return unpack( tblUnpack )
end
ns.round = function( num, places )
return tonumber( format( "%." .. ( places or 0 ) .. "f", num ) )
end
function ns.roundUp( num, places )
num = num or 0
local tens = 10 ^ ( places or 0 )
return ceil( num * tens ) / tens
end
function ns.roundDown( num, places )
num = num or 0
local tens = 10 ^ ( places or 0 )
return floor( num * tens ) / tens
end
-- Deep Copy
-- from http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value
local function tableCopy( obj, seen )
if type(obj) ~= 'table' then return obj end
if seen and seen[obj] then return seen[obj] end
local s = seen or {}
local res = setmetatable({}, getmetatable(obj))
s[obj] = res
for k, v in pairs(obj) do res[ tableCopy(k, s) ] = tableCopy(v, s) end
return res
end
ns.tableCopy = tableCopy
local toc = {}
local exclusions = { min = true, max = true, _G = true }
ns.commitKey = function( key )
if not toc[ key ] and not exclusions[ key ] then
ns.keys[ #ns.keys + 1 ] = key
toc[ key ] = 1
end
end
local orderedIndex = {}
local sortHelper = function( a, b )
local a1, b1 = tostring(a), tostring(b)
return a1 < b1
end
local function __genOrderedIndex( t )
for i = #orderedIndex, 1, -1 do
orderedIndex[i] = nil
end
for key in pairs( t ) do
table.insert( orderedIndex, key )
end
table.sort( orderedIndex, sortHelper )
return orderedIndex
end
local function orderedNext( t, state )
local key = nil
if state == nil then
t.__orderedIndex = __genOrderedIndex( t )
key = t.__orderedIndex[ 1 ]
else
for i = 1, table.getn( t.__orderedIndex ) do
if t.__orderedIndex[ i ] == state then
key = t.__orderedIndex[ i+1 ]
end
end
end
if key then
return key, t[ key ]
end
t.__orderedIndex = nil
return
end
function ns.orderedPairs( t )
return orderedNext, t, nil
end
function ns.safeMin( ... )
local result
for i = 1, select( "#", ... ) do
local val = select( i, ... )
if val then result = ( not result or val < result ) and val or result end
end
return result or 0
end
function ns.safeMax( ... )
local result
for i = 1, select( "#", ... ) do
local val = select( i, ... )
if val and type(val) == 'number' then result = ( not result or val > result ) and val or result end
end
return result or 0
end
function ns.safeAbs( val )
val = tonumber( val )
if val < 0 then return -val end
return val
end
-- Rivers' iterator for group members.
function ns.GroupMembers( reversed, forceParty )
local unit = ( not forceParty and IsInRaid() ) and 'raid' or 'party'
local numGroupMembers = forceParty and GetNumSubgroupMembers() or GetNumGroupMembers()
local i = reversed and numGroupMembers or ( unit == 'party' and 0 or 1 )
return function()
local ret
if i == 0 and unit == 'party' then
ret = 'player'
elseif i <= numGroupMembers and i > 0 then
ret = unit .. i
end
i = i + ( reversed and -1 or 1 )
return ret
end
end
-- Use C_Timer.After but allow for function args.
function Hekili:After( time, func, ... )
local args = { ... }
local function delayfunc()
func( unpack( args ) )
end
C_Timer.After( time, delayfunc )
end
function ns.FindRaidBuffByID( id )
local unitName
local buffCounter = 0
local buffIterator = 1
local name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3
if IsInRaid() or IsInGroup() then
if IsInRaid() then
unitName = "raid"
for numGroupMembers=1, GetNumGroupMembers() do
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
while( spellID ) do
if spellID == id then buffCounter = buffCounter + 1 break end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
end
end
elseif IsInGroup() then
unitName = "party"
for numGroupMembers=1, GetNumGroupMembers() do
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
while( spellID ) do
if spellID == id then buffCounter = buffCounter + 1 break end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
end
end
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( "player", buffIterator )
while( spellID ) do
if spellID == id then buffCounter = buffCounter + 1 break end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( "player", buffIterator )
end
else
unitName = "player"
end
end
return buffCounter
end
function ns.FindLowHpPlayerWithoutBuffByID(id)
local unitName
local playerWithoutBuff = 0
local buffFound = false
local buffIterator = 1
local name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3
if IsInRaid() or IsInGroup() then
if IsInRaid() then
unitName = "raid"
for numGroupMembers=1, GetNumGroupMembers() do
buffFound = false
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
while( name ) do
if spellID == id then buffFound = true break end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
end
if not buffFound then
local player = unitName..numGroupMembers
local Health = (UnitHealth(player))/1000
local HealthMax = (UnitHealthMax(player))/1000
local HealthPercent = (UnitHealth(player)/UnitHealthMax(player))*100
if HealthPercent <= 80 and UnitName(player) then
playerWithoutBuff = playerWithoutBuff + 1
end
end
end
elseif IsInGroup() then
unitName = "party"
for numGroupMembers=1, GetNumGroupMembers() do
buffFound = false
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
while( name ) do
if spellID == id then buffFound = true break end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
end
if not buffFound then
local player = unitName..numGroupMembers
local Health = (UnitHealth(player))/1000
local HealthMax = (UnitHealthMax(player))/1000
local HealthPercent = (UnitHealth(player)/UnitHealthMax(player))*100
if HealthPercent <= 80 and UnitName(player) then
playerWithoutBuff = playerWithoutBuff + 1
end
end
end
buffFound = false
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( "player", buffIterator )
while( name ) do
if spellID == id then buffFound = true break end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( "player", buffIterator )
end
if not buffFound then
local player = "player"
local Health = (UnitHealth(player))/1000
local HealthMax = (UnitHealthMax(player))/1000
local HealthPercent = (UnitHealth(player)/UnitHealthMax(player))*100
if HealthPercent <= 80 then
playerWithoutBuff = playerWithoutBuff + 1
end
end
else
unitName = "player"
end
end
return playerWithoutBuff
end
function ns.FindRaidBuffLowestRemainsByID(id)
local buffRemainsOld
local buffRemainsNew
local buffRemainsReturn
local unitName = "player"
local buffIterator = 1
local name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3
if IsInRaid() or IsInGroup() then
if IsInRaid() then
unitName = "raid"
for numGroupMembers=1, GetNumGroupMembers() do
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
while( name ) do
if spellID == id then
if buffRemainsOld == nil then
buffRemainsOld = expirationTime - GetTime()
end
local buffRemainsNew = expirationTime - GetTime()
if buffRemainsNew < buffRemainsOld then
buffRemainsReturn = buffRemainsNew
else
buffRemainsReturn = buffRemainsOld
end
break
end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
end
end
elseif IsInGroup() then
unitName = "party"
for numGroupMembers=1, GetNumGroupMembers() do
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
while( name ) do
if spellID == id then
if buffRemainsOld == nil then
buffRemainsOld = expirationTime - GetTime()
end
local buffRemainsNew = expirationTime - GetTime()
if buffRemainsNew < buffRemainsOld then
buffRemainsReturn = buffRemainsNew
else
buffRemainsReturn = buffRemainsOld
end
break
end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( unitName..numGroupMembers, buffIterator )
end
end
buffIterator = 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( "player", buffIterator )
while( name ) do
if spellID == id then
if buffRemainsOld == nil then
buffRemainsOld = expirationTime - GetTime()
end
local buffRemainsNew = expirationTime - GetTime()
if buffRemainsNew < buffRemainsOld then
buffRemainsReturn = buffRemainsNew
else
buffRemainsReturn = buffRemainsOld
end
break
end
buffIterator = buffIterator + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitBuff( "player", buffIterator )
end
end
end
return buffRemainsReturn == nil and 0 or buffRemainsReturn
end
local function FindPlayerAuraByID( id )
local aura = GetPlayerAuraBySpellID( id )
if aura and aura.name then
return aura.name, aura.icon, aura.applications, aura.dispelName, aura.duration, aura.expirationTime, aura.sourceUnit, aura.isStealable, aura.nameplateShowPersonal, aura.spellId, aura.canApplyAura, aura.isBossAura, aura.nameplateShowAll, aura.timeMod, unpack( aura.points )
end
end
ns.FindPlayerAuraByID = FindPlayerAuraByID
-- Duplicate spell info lookup.
function ns.FindUnitBuffByID( unit, id, filter )
if unit == "player" then return FindPlayerAuraByID( id ) end
return UnitBuffByID( unit, id, filter )
end
function ns.FindUnitDebuffByID( unit, id, filter )
if unit == "player" then return FindPlayerAuraByID( id ) end
local playerOrPet = false
if filter == "PLAYER|PET" then
playerOrPet = true
filter = nil
end
local i = 1
local name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitDebuff( unit, i, filter )
while( name ) do
if spellID == id and ( not playerOrPet or UnitIsUnit( caster, "player" ) or UnitIsUnit( caster, "pet" ) ) then break end
i = i + 1
name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3 = UnitDebuff( unit, i, filter )
end
if name and name ~= nil then
return name, icon, count, debuffType, duration, expirationTime, caster, stealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3
end
end
function ns.IsActiveSpell( id )
local slot = FindSpellBookSlotBySpellID( id )
if not slot then return false end
local _, _, spellID = GetSpellBookItemInfo( slot, "spell" )
return id == spellID
end
function ns.GetUnpackedSpellInfo( spellID )
if not spellID then
return nil;
end
local spellInfo = GetSpellInfo(spellID);
if spellInfo then
return spellInfo.name, nil, spellInfo.iconID, spellInfo.castTime, spellInfo.minRange, spellInfo.maxRange, spellInfo.spellID, spellInfo.originalIconID;
end
end
function Hekili:GetSpellLinkWithTexture( id, size, color )
if not id then return "" end
if type( id ) ~= "number" and class.abilities[ id ] then
id = class.abilities[ id ].id
end
local data = GetSpellInfo( id )
if data and data.name and data.iconID then
if type( color ) == "boolean" then
color = color and "ff00ff00" or "ffff0000"
end
if color == nil then color = "ff71d5ff" end
return "|W|T" .. data.iconID .. ":" .. ( size or 0 ) .. ":" .. ( size or "" ) .. ":::64:64:4:60:4:60|t " .. ( color and ( "|c" .. color ) or "" ) .. data.name .. ( color and "|r" or "" ) .. "|w"
end
return tostring( id )
end
function Hekili:ZoomedTextureWithText( texture, text )
if not texture or not text then return end
return "|W|T" .. texture .. ":0::::64:64:4:60:4:60|t " .. text .. "|w"
end
function state.debugformat( val )
if val == nil then return "nil" end
if type( val ) == "number" then return format( "%.2f", val ) end
return tostring( val )
end
-- Tooltip Parsing Utilities (10.0.2)
do
local CurrentBuild = Hekili.CurrentBuild
local tooltip = ns.Tooltip
local DisableText = {
_G.SPELL_FAILED_NOT_HERE,
_G.SPELL_FAILED_INCORRECT_AREA,
_G.SPELL_FAILED_NOT_IN_MAGE_TOWER,
_G.TOOLTIP_NOT_IN_MAGE_TOWER,
_G.LEVEL_LINKED_NOT_USABLE
}
local FindStringInTooltip = function( str, id, ttType, reverse, useMatch )
local data
if ttType == "spell" then data = C_TooltipInfo.GetSpellByID( id )
elseif ttType == "item" then data = C_TooltipInfo.GetItemByID( id )
elseif ttType == "inventory" then data = C_TooltipInfo.GetInventoryItem( "player", id )
elseif ttType == "conduit" then data = C_TooltipInfo.GetConduit( id, 0 )
else
Hekili:Error( "Usage: FindStringInTooltip( str, id, { spell | item | inventory | conduit }, reverse, useMatch )\n" ..
"Invalid tooltip type: '%s'", ttType or "nil" )
return
end
if not data then return end
if reverse then
for i = #data.lines, 1, -1 do
local line = data.lines[ i ]
if type( str ) == "table" then
for _, seek in ipairs( str ) do
if ( useMatch and line.leftText:match( seek ) ) or ( not useMatch and line.leftText == seek ) then return true end
end
else
if ( useMatch and line.leftText:match( str ) ) or ( not useMatch and line.leftText == str ) then return true end
end
end
return false
end
for _, line in ipairs( data ) do
if type( str ) == "table" then
for _, seek in ipairs( str ) do
if ( useMatch and line.leftText:match( seek ) ) or ( not useMatch and line.leftText == seek ) then return true end
end
else
if ( useMatch and line.leftText:match( str ) ) or ( not useMatch and line.leftText == str ) then return true end
end
end
return false
end
ns.FindStringInTooltip = FindStringInTooltip
local FindStringInSpellTooltip = function( str, spellID, reverse, useMatch )
return FindStringInTooltip( str, spellID, "spell", reverse, useMatch )
end
ns.FindStringInSpellTooltip = FindStringInSpellTooltip
local FindStringInItemTooltip = function( str, itemID, reverse, useMatch )
return FindStringInTooltip( str, itemID, "item", reverse, useMatch )
end
ns.FindStringInItemTooltip = FindStringInItemTooltip
-- Note, this is written to assume we're dealing with the player's inventory only; I'm not messing with inspect right now.
local FindStringInInventoryItemTooltip = function( str, slot, reverse, useMatch )
return FindStringInTooltip( str, slot, "inventory", reverse, useMatch )
end
ns.FindStringInInventoryItemTooltip = FindStringInInventoryItemTooltip
local FindStringInConduitTooltip = function( str, conduit, reverse, useMatch )
return FindStringInTooltip( str, conduit, "conduit", reverse, useMatch )
end
ns.FindStringInConduitTooltip = FindStringInConduitTooltip
local DisabledSpells = {}
local IsSpellDisabled = function( spellID )
if DisabledSpells[ spellID ] ~= nil then return DisabledSpells[ spellID ] end
local isDisabled = FindStringInSpellTooltip( DisableText, spellID, true, true )
DisabledSpells[ spellID ] = isDisabled
return isDisabled
end
ns.IsSpellDisabled = IsSpellDisabled
local DisabledItems = {}
local IsItemDisabled = function( itemID )
if DisabledItems[ itemID ] ~= nil then return DisabledItems[ itemID ] end
local isDisabled = FindStringInItemTooltip( DisableText, itemID, true, true )
DisabledItems[ itemID ] = isDisabled
return isDisabled
end
ns.IsItemDisabled = IsItemDisabled
local DisabledGear = {}
local IsInventoryItemDisabled = function( slot )
if DisabledGear[ slot ] ~= nil then return DisabledGear[ slot ] end
local isDisabled = FindStringInInventoryItemTooltip( DisableText, slot, true, true )
DisabledGear[ slot ] = isDisabled
return isDisabled
end
ns.IsInventoryItemDisabled = IsInventoryItemDisabled
local function IsAbilityDisabled( ability )
if ability.item then return IsItemDisabled( ability.item ) end
if ability.id > 0 then return IsSpellDisabled( ability.id ) end
return false
end
ns.IsAbilityDisabled = IsAbilityDisabled
local ResetDisabledGearAndSpells = function()
wipe( DisabledSpells )
wipe( DisabledItems )
wipe( DisabledGear )
end
ns.ResetDisabledGearAndSpells = ResetDisabledGearAndSpells
Hekili.FindStringInTooltip = FindStringInTooltip
Hekili.FindStringInSpellTooltip = FindStringInSpellTooltip
Hekili.FindStringInItemTooltip = FindStringInItemTooltip
Hekili.FindStringInInventoryItemTooltip = FindStringInInventoryItemTooltip
Hekili.FindStringInConduitTooltip = FindStringInConduitTooltip
Hekili.IsSpellDisabled = IsSpellDisabled
Hekili.IsItemDisabled = IsItemDisabled
Hekili.IsInventoryItemDisabled = IsInventoryItemDisabled
-- Check Covenant spells to disable them.
local CovenantSpells = {
[300728] = 1,
[304971] = 1,
[306830] = 1,
[307443] = 1,
[307865] = 1,
[308491] = 1,
[310454] = 1,
[311648] = 1,
[312202] = 1,
[312321] = 1,
[314791] = 1,
[314793] = 1,
[315443] = 1,
[316958] = 1,
[317009] = 1,
[317485] = 1,
[320674] = 1,
[321792] = 1,
[323546] = 1,
[323547] = 1,
[323639] = 1,
[323654] = 1,
[323673] = 1,
[323764] = 1,
[324128] = 1,
[324143] = 1,
[324149] = 1,
[324220] = 1,
[324386] = 1,
[324631] = 1,
[324724] = 1,
[325013] = 1,
[325020] = 1,
[325028] = 1,
[325216] = 1,
[325283] = 1,
[325289] = 1,
[325640] = 1,
[325886] = 1,
[326059] = 1,
[326434] = 1,
[326647] = 1,
[326860] = 1,
[327104] = 1,
[327661] = 1,
[328204] = 1,
[328231] = 1,
[328281] = 1,
[328282] = 1,
[328305] = 1,
[328547] = 1,
[328620] = 1,
[328622] = 1,
[328923] = 1,
[328930] = 1,
[330325] = 1,
[355589] = 1,
[356532] = 1,
}
local IsCovenantSpell = function( spellID )
return CovenantSpells[ spellID ] == 1
end
ns.IsCovenantSpell = IsCovenantSpell
local covenantsDisabled = nil
local AreCovenantsDisabled = function()
if covenantsDisabled == nil then
if FindStringInConduitTooltip( DisableText, 5, true, true ) then
covenantsDisabled = true
return true
end
covenantsDisabled = false
return false
end
return covenantsDisabled
end
ns.AreCovenantsDisabled = AreCovenantsDisabled
local IsDisabledCovenantSpell = function( spellID )
return CovenantSpells[ spellID ] and AreCovenantsDisabled()
end
ns.IsDisabledCovenantSpell = IsDisabledCovenantSpell
local WipeCovenantCache = function()
covenantsDisabled = nil
end
ns.WipeCovenantCache = WipeCovenantCache
end
do
local itemCache = {}
function ns.CachedGetItemInfo( id )
if itemCache[ id ] then
return unpack( itemCache[ id ] )
end
local item = { GetItemInfo( id ) }
if item and item[ 1 ] then
itemCache[ id ] = item
return unpack( item )
end
end
end
-- Atlas -> Texture Stuff
do
local db = {}
local function AddTexString( name, file, width, height, left, right, top, bottom )
local pctWidth = right - left
local realWidth = width / pctWidth
local lPoint = left * realWidth
local pctHeight = bottom - top
local realHeight = height / pctHeight
local tPoint = top * realHeight
db[ name ] = format( "|T%s:%%d:%%d:%%d:%%d:%d:%d:%d:%d:%d:%d:%%s|t", file, realWidth, realHeight, lPoint, lPoint + width, tPoint, tPoint + height )
end
local function GetTexString( name, width, height, x, y, r, g, b )
return db[ name ] and format( db[ name ], width or 0, height or 0, x or 0, y or 0, ( r and g and b and ( r .. ":" .. g .. ":" .. b ) or "" ) ) or ""
end
local function AtlasToString( atlas, width, height, x, y, r, g, b )
if db[ atlas ] then
return GetTexString( atlas, width, height, x, y, r, g, b )
end
local a = C_Texture.GetAtlasInfo( atlas )
if not a then return atlas end
AddTexString( atlas, a.file, a.width, a.height, a.leftTexCoord, a.rightTexCoord, a.topTexCoord, a.bottomTexCoord )
return GetTexString( atlas, width, height, x, y, r, g, b )
end
local function GetAtlasFile( atlas )
local a = C_Texture.GetAtlasInfo( atlas )
return a and a.file or atlas
end
local function GetAtlasCoords( atlas )
local a = C_Texture.GetAtlasInfo( atlas )
return a and { a.leftTexCoord, a.rightTexCoord, a.topTexCoord, a.bottomTexCoord }
end
ns.AddTexString, ns.GetTexString, ns.AtlasToString, ns.GetAtlasFile, ns.GetAtlasCoords = AddTexString, GetTexString, AtlasToString, GetAtlasFile, GetAtlasCoords
end
function Hekili:GetSpec()
return state.spec.id and class.specs[ state.spec.id ]
end
function Hekili:IsValidSpec()
return state.spec.id and class.specs[ state.spec.id ] ~= nil
end
local IsAddOnLoaded = C_AddOns.IsAddOnLoaded
function Hekili:GetLoadoutExportString()
-- Current as of 10.1.0.48480
local bitWidthHeaderVersion = 8
local bitWidthSpecID = 16
local bitWidthRanksPurchased = 6
-- Cannot force-load as needed without causing taint, so this simply replicates existing Blizzard functionality.
if IsAddOnLoaded( "Blizzard_ClassTalentUI" ) then
bitWidthHeaderVersion = ClassTalentImportExportMixin.bitWidthHeaderVersion
bitWidthSpecID = ClassTalentImportExportMixin.bitWidthSpecID
bitWidthRanksPurchased = ClassTalentImportExportMixin.bitWidthRanksPurchased
end
local es = ExportUtil.MakeExportDataStream()
local configID = C_ClassTalents.GetActiveConfigID() or -1
local configInfo = C_Traits.GetConfigInfo( configID )
if not configInfo then return "Export Unavailable" end
local currentSpecID = PlayerUtil.GetCurrentSpecID()
local treeID = configInfo.treeIDs[ 1 ]
local treeHash = C_Traits.GetTreeHash( treeID )
local serializationVersion = C_Traits.GetLoadoutSerializationVersion()
es:AddValue( bitWidthHeaderVersion, serializationVersion )
es:AddValue( bitWidthSpecID, currentSpecID )
-- treeHash is a 128bit hash, passed as an array of 16, 8-bit values
for i, hashVal in ipairs( treeHash ) do
es:AddValue( 8, hashVal )
end
local treeNodes = C_Traits.GetTreeNodes(treeID);
for i, treeNodeID in ipairs(treeNodes) do
local treeNode = C_Traits.GetNodeInfo(configID, treeNodeID);
local isNodeGranted = treeNode.activeRank - treeNode.ranksPurchased > 0;