-
-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathHekili.lua
More file actions
666 lines (493 loc) · 21.4 KB
/
Copy pathHekili.lua
File metadata and controls
666 lines (493 loc) · 21.4 KB
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
-- Hekili.lua
-- July 2024
local addon, ns = ...
Hekili = LibStub("AceAddon-3.0"):NewAddon( "Hekili", "AceConsole-3.0", "AceSerializer-3.0" )
Hekili.Version = C_AddOns.GetAddOnMetadata( "Hekili", "Version" )
Hekili.Flavor = C_AddOns.GetAddOnMetadata( "Hekili", "X-Flavor" ) or "Retail"
local format = string.format
local insert, concat = table.insert, table.concat
local GetBuffDataByIndex, GetDebuffDataByIndex = C_UnitAuras.GetBuffDataByIndex, C_UnitAuras.GetDebuffDataByIndex
local UnpackAuraData = AuraUtil.UnpackAuraData
local buildStr, _, _, buildNum = GetBuildInfo()
Hekili.CurrentBuild = buildNum
if Hekili.Version == ( "@" .. "project-version" .. "@" ) then
Hekili.Version = format( "Dev-%s (%s)", buildStr, date( "%Y%m%d" ) )
Hekili.IsDev = true
end
Hekili.AllowSimCImports = true
Hekili.IsRetail = function()
return Hekili.Flavor == "Retail"
end
Hekili.IsWrath = function()
return Hekili.Flavor == "Wrath"
end
Hekili.IsClassic = function()
return Hekili.IsWrath()
end
Hekili.IsDragonflight = function()
return buildNum >= 100000
end
Hekili.IsTWW = function()
return buildNum >= 110000
end
Hekili.IsMidnight = function()
return buildNum >= 120000
end
Hekili.BuiltFor = 110200
Hekili.GameBuild = buildStr
ns.PTR = buildNum > 110200
Hekili.IsPTR = ns.PTR
ns.Patrons = "|cFFFFD100Current Status|r\n\n"
.. "All existing specializations are currently supported, though healer priorities are experimental and focused on rotational DPS only.\n\n"
.. "If you find odd recommendations or other issues, please follow the |cFFFFD100Report Issue|r link below and submit all the necessary information to have your issue investigated.\n\n"
.. "Please |cffff0000do not|r submit tickets for routine priority updates (i.e., from SimulationCraft). They are routinely updated."
do
local cpuProfileDB = {}
function Hekili:ProfileCPU( name, func )
cpuProfileDB[ name ] = func
end
ns.cpuProfile = cpuProfileDB
local frameProfileDB = {}
function Hekili:ProfileFrame( name, f )
frameProfileDB[ name ] = f
end
ns.frameProfile = frameProfileDB
end
ns.lib = {
Format = {}
}
-- 04072017: Let's go ahead and cache aura information to reduce overhead.
ns.auras = {
target = {
buff = {},
debuff = {}
},
player = {
buff = {},
debuff = {}
}
}
Hekili.Class = {
specs = {},
num = 0,
file = "NONE",
initialized = false,
resources = {},
resourceAuras = {},
talents = {},
pvptalents = {},
auras = {},
auraList = {},
powers = {},
gear = {},
setBonuses = {},
knownAuraAttributes = {},
stateExprs = {},
stateFuncs = {},
stateTables = {},
abilities = {},
abilityByName = {},
abilityList = {},
itemList = {},
itemMap = {},
itemPack = {
lists = {
items = {}
}
},
packs = {},
pets = {},
totems = {},
potions = {},
potionList = {},
hooks = {},
range = 8,
settings = {},
stances = {},
toggles = {},
variables = {},
}
local class = Hekili.Class
Hekili.Scripts = {
DB = {},
Channels = {},
PackInfo = {},
}
Hekili.State = {}
ns.hotkeys = {}
ns.keys = {}
ns.queue = {}
ns.targets = {}
ns.TTD = {}
ns.UI = {
Displays = {},
Buttons = {}
}
ns.debug = {}
ns.snapshots = {}
function Hekili:Query( ... )
local output = ns
for i = 1, select( '#', ... ) do
output = output[ select( i, ... ) ]
end
return output
end
function Hekili:Run( ... )
local n = select( "#", ... )
local fn = select( n, ... )
local func = ns
for i = 1, fn - 1 do
func = func[ select( i, ... ) ]
end
return func( select( fn, ... ) )
end
local debug = ns.debug
local active_debug
local current_display
local lastIndent = 0
function Hekili:SetupDebug( display )
if not self.ActiveDebug then return end
if not display then return end
current_display = display
debug[ current_display ] = debug[ current_display ] or {
log = {},
index = 1
}
active_debug = debug[ current_display ]
active_debug.index = 1
lastIndent = 0
local pack = self.State.system.packName
if not pack then return end
self:Debug( "New Recommendations for [ %s ] requested at %s ( %.2f ); using %s( %s ) priority.", display, date( "%H:%M:%S"), GetTime(), self.DB.profile.packs[ pack ].builtIn and "built-in " or "", pack )
end
function Hekili:Debug( ... )
if not self.ActiveDebug then return end
if not active_debug then return end
local indent, text = ...
local start
if type( indent ) ~= "number" then
indent = lastIndent
text = ...
start = 2
else
lastIndent = indent
start = 3
end
local prepend = format( indent > 0 and ( "%" .. ( indent * 4 ) .. "s" ) or "%s", "" )
text = text:gsub("\n", "\n" .. prepend )
text = format( "%" .. ( indent > 0 and ( 4 * indent ) or "" ) .. "s", "" ) .. text
if select( start, ... ) ~= nil then
active_debug.log[ active_debug.index ] = format( text, select( start, ... ) )
else
active_debug.log[ active_debug.index ] = text
end
active_debug.index = active_debug.index + 1
end
local snapshots = ns.snapshots
local hasScreenshotted = false
function Hekili:SaveDebugSnapshot( dispName )
local snapped = false
local formatKey = ns.formatKey
local state = Hekili.State
for k, v in pairs( debug ) do
if not dispName or dispName == k then
for i = #v.log, v.index, -1 do
v.log[ i ] = nil
end
-- Store previous spell data.
local prevString = "\nprevious_spells:"
-- Skip over the actions in the "prev" table that were added to computed the next recommended ability in the queue.
local i, j = ( #state.predictions + 1 ), 1
local spell = state.prev[i].spell or "no_action"
if spell == "no_action" then
prevString = prevString .. " no history available"
else
local numHistory = #state.prev.history
while i <= numHistory and spell ~= "no_action" do
prevString = format( "%s\n %d - %s", prevString, j, spell )
i, j = i + 1, j + 1
spell = state.prev[i].spell or "no_action"
end
end
prevString = prevString .. "\n\n"
insert( v.log, 1, prevString )
-- Store aura data.
local auraString = "\n### Auras ###\n"
local now = GetTime()
local playerBuffs = {}
local pbOrder = {}
local longestKey, longestName = 0, 0
AuraUtil.ForEachAura( "player", "HELPFUL", nil, function( aura )
if aura.isFromPlayerOrPlayerPet then
local model = class.auras[ aura.spellId ]
local key = model and model.key or formatKey( aura.name )
local offset = 0
local newKey = key
while( playerBuffs[ newKey ] ) do
offset = offset + 1
newKey = format( "%s_%d", key, offset )
end
if newKey ~= key then key = newKey end
pbOrder[ #pbOrder + 1 ] = key
longestKey = max( longestKey, key:len() )
longestName = max( longestName, aura.name:len() )
playerBuffs[ key ] = {}
local elem = playerBuffs[ key ]
elem.spellId = aura.spellId
elem.key = key
elem.name = aura.name
elem.count = aura.applications > 0 and aura.applications or 1
elem.remains = aura.expirationTime > 0 and ( aura.expirationTime - now ) or 3600
local scraped = state.auras.player.buff[ model and model.key or key ]
if scraped and scraped.applied > 0 then
elem.sCount = scraped.count > 0 and scraped.count or 1
elem.sRemains = scraped.expires > 0 and ( scraped.expires - now ) or 3600
end
end
end, true )
for token, caught in pairs( state.auras.player.buff ) do
if not playerBuffs[ token ] and caught.expires > 0 then
playerBuffs[ token ] = {
spellId = caught.id,
key = caught.key,
name = "",
count = 0,
remains = 0,
sCount = caught.count > 0 and caught.count or 1,
sRemains = caught.expires > 0 and ( caught.expires - now ) or 3600
}
pbOrder[ #pbOrder + 1 ] = token
longestKey = max( longestKey, token:len() )
end
end
sort( pbOrder )
local playerDebuffs = {}
local pdOrder = {}
AuraUtil.ForEachAura( "player", "HARMFUL", nil, function( aura )
local model = class.auras[ aura.spellId ]
local key = model and model.key or formatKey( aura.name )
local offset = 0
local newKey = key
while( playerDebuffs[ newKey ] ) do
offset = offset + 1
newKey = format( "%s_%d", key, offset )
end
if newKey ~= key then key = newKey end
pdOrder[ #pdOrder + 1 ] = key
longestKey = max( longestKey, key:len() )
longestName = max( longestName, aura.name:len() )
playerDebuffs[ key ] = {}
local elem = playerDebuffs[ key ]
elem.spellId = aura.spellId
elem.key = key
elem.name = aura.name
elem.count = aura.applications > 0 and aura.applications or 1
elem.remains = aura.expirationTime > 0 and ( aura.expirationTime - now ) or 3600
local scraped = state.auras.player.debuff[ model and model.key or key ]
if scraped and scraped.applied > 0 then
elem.sCount = scraped.count > 0 and scraped.count or 1
elem.sRemains = scraped.expires > 0 and ( scraped.expires - now ) or 3600
end
end, true )
for token, caught in pairs( state.auras.player.debuff ) do
if not playerDebuffs[ token ] and caught.expires > 0 then
playerDebuffs[ token ] = {
spellId = caught.id,
key = caught.key,
name = "",
count = 0,
remains = 0,
sCount = caught.count > 0 and caught.count or 1,
sRemains = caught.expires > 0 and ( caught.expires - now ) or 3600
}
pdOrder[ #pdOrder + 1 ] = token
longestKey = max( longestKey, token:len() )
end
end
sort( pdOrder )
local targetBuffs = {}
local tbOrder = {}
AuraUtil.ForEachAura( "target", "HELPFUL", nil, function( aura )
local model = class.auras[ aura.spellId ]
local key = model and model.key or formatKey( aura.name )
local offset = 0
local newKey = key
while( targetBuffs[ newKey ] ) do
offset = offset + 1
newKey = format( "%s_%d", key, offset )
end
if newKey ~= key then key = newKey end
tbOrder[ #tbOrder + 1 ] = key
longestKey = max( longestKey, key:len() )
longestName = max( longestName, aura.name:len() )
targetBuffs[ key ] = {}
local elem = targetBuffs[ key ]
elem.spellId = aura.spellId
elem.key = key
elem.name = aura.name
elem.count = aura.applications > 0 and aura.applications or 1
elem.remains = aura.expirationTime > 0 and ( aura.expirationTime - now ) or 3600
local scraped = state.auras.target.buff[ model and model.key or key ]
if scraped and scraped.applied > 0 then
elem.sCount = scraped.count > 0 and scraped.count or 1
elem.sRemains = scraped.expires > 0 and ( scraped.expires - now ) or 3600
end
end, true )
for token, caught in pairs( state.auras.target.buff ) do
if not targetBuffs[ token ] and caught.expires > 0 then
targetBuffs[ token ] = {
spellId = caught.id,
key = caught.key,
name = "",
count = 0,
remains = 0,
sCount = caught.count > 0 and caught.count or 1,
sRemains = caught.expires > 0 and ( caught.expires - now ) or 3600
}
tbOrder[ #tbOrder + 1 ] = token
longestKey = max( longestKey, token:len() )
end
end
sort( tbOrder )
local targetDebuffs = {}
local tdOrder = {}
AuraUtil.ForEachAura( "target", "HARMFUL", nil, function( aura )
if aura.isFromPlayerOrPlayerPet then
local model = class.auras[ aura.spellId ]
local key = model and model.key or formatKey( aura.name )
local offset = 0
local newKey = key
while( targetDebuffs[ newKey ] ) do
offset = offset + 1
newKey = format( "%s_%d", key, offset )
end
if newKey ~= key then key = newKey end
tdOrder[ #tdOrder + 1 ] = key
longestKey = max( longestKey, key:len() )
longestName = max( longestName, aura.name:len() )
targetDebuffs[ key ] = {}
local elem = targetDebuffs[ key ]
elem.spellId = aura.spellId
elem.key = key
elem.name = aura.name
elem.count = aura.applications > 0 and aura.applications or 1
elem.remains = aura.expirationTime > 0 and ( aura.expirationTime - now ) or 3600
local scraped = state.auras.target.debuff[ model and model.key or key ]
if scraped and scraped.applied > 0 then
elem.sCount = scraped.count > 0 and scraped.count or 1
elem.sRemains = scraped.expires > 0 and ( scraped.expires - now ) or 3600
end
end
end, true )
for token, caught in pairs( state.auras.target.debuff ) do
if not targetDebuffs[ token ] and caught.expires > 0 then
targetDebuffs[ token ] = {
spellId = caught.id,
key = caught.key,
name = "",
count = 0,
remains = 0,
sCount = caught.count > 0 and caught.count or 1,
sRemains = caught.expires > 0 and ( caught.expires - now ) or 3600
}
tdOrder[ #tdOrder + 1 ] = token
longestKey = max( longestKey, token:len() )
end
end
sort( tdOrder )
local header = " n | ID | Token" .. string.rep( " ", longestKey - 4 ) .. " | Name" .. string.rep( " ", longestName - 4 ) .. " | A. Count | A. Remains | S. Count | S. Remains\n"
.. " --- | ------- | " .. string.rep( "-", longestKey + 1 ) .. " | " .. string.rep( "-", longestName ) .. " | -------- | ---------- | -------- | ----------"
if #pbOrder > 0 then
auraString = auraString .. "\nplayer_buffs:\n" .. header
for i, token in ipairs( pbOrder ) do
local aura = playerBuffs[ token ]
auraString = format( "%s\n %-2d | %7d | %s%-" .. longestKey .. "s | %-" .. longestName .. "s | %8d | %10.2f | %8d | %10.2f",
auraString, i, class.auras[ token ] and class.auras[ token ].id or -1, ( class.auras[ token ] and " " or "*" ), token, aura.name, aura.count, aura.remains, aura.sCount or -1, aura.sRemains or - 1 )
end
else
auraString = auraString .. "\nplayer_buffs: none"
end
if #pdOrder > 0 then
auraString = auraString .. "\n\nplayer_debuffs:\n" .. header
for i, token in ipairs( pdOrder ) do
local aura = playerDebuffs[ token ]
auraString = format( "%s\n %-2d | %7d | %s%-" .. longestKey .. "s | %-" .. longestName .. "s | %8d | %10.2f | %8d | %10.2f",
auraString, i, class.auras[ token ] and class.auras[ token ].id or -1, ( class.auras[ token ] and " " or "*" ), token, aura.name, aura.count, aura.remains, aura.sCount or -1, aura.sRemains or - 1 )
end
else
auraString = auraString .. "\n\nplayer_debuffs: none"
end
if #tbOrder > 0 then
auraString = auraString .. "\n\ntarget_buffs:\n" .. header
for i, token in ipairs( tbOrder ) do
local aura = targetBuffs[ token ]
local model = class.auras[ token ]
auraString = format( "%s\n %-2d | %7d | %s%-" .. longestKey .. "s | %-" .. longestName .. "s | %8d | %10.2f | %8d | %10.2f",
auraString, i, model and model.id or -1, model and " " or "*", token, aura.name, aura.count, aura.remains, aura.sCount or -1, aura.sRemains or - 1 )
end
else
auraString = auraString .. "\n\ntarget_buffs: none"
end
if #tdOrder > 0 then
auraString = auraString .. "\n\ntarget_debuffs:\n" .. header
for i, token in ipairs( tdOrder ) do
local aura = targetDebuffs[ token ]
auraString = format( "%s\n %-2d | %7d | %s%-" .. longestKey .. "s | %-" .. longestName .. "s | %8d | %10.2f | %8d | %10.2f",
auraString, i, class.auras[ token ] and class.auras[ token ].id or -1, ( class.auras[ token ] and " " or "*" ), token, aura.name, aura.count, aura.remains, aura.sCount or -1, aura.sRemains or - 1 )
end
else
auraString = auraString .. "\n\ntarget_debuffs: none"
end
insert( v.log, 1, auraString )
insert( v.log, 1, "\n### Targets ###\n\ndetected_targets: " .. ( Hekili.TargetDebug or "no data" ) )
insert( v.log, 1, self:GenerateProfile() )
local performance
local pInfo = HekiliEngine.threadUpdates
-- TODO: Include # of active displays, number of icons displayed.
if pInfo then
performance = string.format( "\n\nPerformance\n"
.. "|| Updates || Updates / sec || Avg. Work || Avg. Time || Avg. Frames || Peak Work || Peak Time || Peak Frames || FPS || Work Cap ||\n"
.. "|| %7d || %13.2f || %9.2f || %9.2f || %11.2f || %9.2f || %9.2f || %11.2f || %3d || %8.2f ||",
pInfo.updates, pInfo.updatesPerSec, pInfo.meanWorkTime, pInfo.meanClockTime, pInfo.meanFrames, pInfo.peakWorkTime, pInfo.peakClockTime, pInfo.peakFrames, GetFramerate() or 0, Hekili.maxFrameTime or 0 )
end
if performance then insert( v.log, performance ) end
local custom = ""
local pack = self.DB.profile.packs[ state.system.packName ]
if not pack.builtIn then
custom = format( " |cFFFFA700(*%s[%d])|r", state.spec.name, state.spec.id )
end
local overview = format( "%s%s; %s|r", state.system.packName, custom, dispName or state.display )
local recs = Hekili.DisplayPool[ dispName or state.display ].Recommendations
for i, rec in ipairs( recs ) do
if not rec.actionName then
if i == 1 then
overview = format( "%s - |cFF666666N/A|r", overview )
end
break
end
overview = format( "%s%s%s|cFFFFD100(%0.2f)|r", overview, ( i == 1 and " - " or ", " ), rec.actionName, rec.time or rec.exact_time or -1 )
end
insert( v.log, 1, overview )
local snap = {
header = "|cFFFFD100[" .. date( "%H:%M:%S" ) .. "]|r " .. overview,
log = concat( v.log, "\n" ),
data = ns.tableCopy( v.log ),
recs = {}
}
insert( snapshots, snap )
snapped = true
end
end
-- Limit screenshot to once per login.
if snapped then
if Hekili.DB.profile.screenshot and ( not hasScreenshotted or Hekili.ManualSnapshot ) then
Screenshot()
hasScreenshotted = true
end
return true
end
return false
end
Hekili.Snapshots = ns.snapshots
ns.Tooltip = CreateFrame( "GameTooltip", "HekiliTooltip", UIParent, "GameTooltipTemplate" )
Hekili:ProfileFrame( "HekiliTooltip", ns.Tooltip )