forked from Hekili/hekili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hekili.lua
398 lines (291 loc) · 11.3 KB
/
Hekili.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
-- 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.BuiltFor = 110000
Hekili.GameBuild = buildStr
ns.PTR = buildNum > 110000
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 |cFFFFD100Issue Reporting|r link below and submit all the necessary information to have your issue investigated.\n\n"
.. "Please do not submit tickets for routine priority updates (i.e., from SimulationCraft). I will routinely update those when they are published. Thanks!"
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 = {},
}
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 = "\nplayer_buffs:"
local now = GetTime()
local class = Hekili.Class
for i = 1, 40 do
local name, _, count, debuffType, duration, expirationTime, source, _, _, spellId, canApplyAura, isBossDebuff, castByPlayer = UnpackAuraData( GetBuffDataByIndex( "player", i ) )
if not name then break end
local aura = class.auras[ spellId ]
local key = aura and aura.key
if key and not state.auras.player.buff[ key ] then key = key .. " [MISSING]" end
auraString = format( "%s\n %6d - %-40s - %3d - %-6.2f", auraString, spellId, key or ( "*" .. formatKey( name ) ), count > 0 and count or 1, expirationTime > 0 and ( expirationTime - now ) or 3600 )
end
auraString = auraString .. "\n\nplayer_debuffs:"
for i = 1, 40 do
local name, _, count, debuffType, duration, expirationTime, source, _, _, spellId, canApplyAura, isBossDebuff, castByPlayer = UnpackAuraData( GetDebuffDataByIndex( "player", i ) )
if not name then break end
local aura = class.auras[ spellId ]
local key = aura and aura.key
if key and not state.auras.player.debuff[ key ] then key = key .. " [MISSING]" end
auraString = format( "%s\n %6d - %-40s - %3d - %-6.2f", auraString, spellId, key or ( "*" .. formatKey( name ) ), count > 0 and count or 1, expirationTime > 0 and ( expirationTime - now ) or 3600 )
end
if not UnitExists( "target" ) then
auraString = auraString .. "\n\ntarget_auras: target does not exist"
else
auraString = auraString .. "\n\ntarget_buffs:"
for i = 1, 40 do
local name, _, count, debuffType, duration, expirationTime, source, _, _, spellId, canApplyAura, isBossDebuff, castByPlayer = UnpackAuraData( GetBuffDataByIndex( "target", i ) )
if not name then break end
local aura = class.auras[ spellId ]
local key = aura and aura.key
if key and not state.auras.target.buff[ key ] then key = key .. " [MISSING]" end
auraString = format( "%s\n %6d - %-40s - %3d - %-6.2f", auraString, spellId, key or ( "*" .. formatKey( name ) ), count > 0 and count or 1, expirationTime > 0 and ( expirationTime - now ) or 3600 )
end
auraString = auraString .. "\n\ntarget_debuffs:"
for i = 1, 40 do
local name, _, count, debuffType, duration, expirationTime, source, _, _, spellId, canApplyAura, isBossDebuff, castByPlayer = UnpackAuraData( GetDebuffDataByIndex( "target", i, "PLAYER" ) )
if not name then break end
local aura = class.auras[ spellId ]
local key = aura and aura.key
if key and not state.auras.target.debuff[ key ] then key = key .. " [MISSING]" end
auraString = format( "%s\n %6d - %-40s - %3d - %-6.2f", auraString, spellId, key or ( "*" .. formatKey( name ) ), count > 0 and count or 1, expirationTime > 0 and ( expirationTime - now ) or 3600 )
end
end
insert( v.log, 1, auraString )
insert( v.log, 1, "targets: " .. ( Hekili.TargetDebug or "no data" ) )
insert( v.log, 1, self:GenerateProfile() )
local custom = ""
local pack = self.DB.profile.packs[ state.system.packName ]
if not pack.builtIn then
custom = format( " |cFFFFA700(Custom: %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 ", " ), class.abilities[ rec.actionName ].name, rec.time )
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 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 )