Refactor CombatAlerter, Commander, Inviter, Macroer, Sniffer modules for improved structure and clarity
This commit is contained in:
@@ -1,96 +1,102 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
|
||||
---@class HeimdallMacroerConfig
|
||||
---@field enabled boolean
|
||||
---@field debug boolean
|
||||
---@field priority string[]
|
||||
|
||||
local ModuleName = "Macroer"
|
||||
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Macroer = {}
|
||||
function shared.Macroer.Init()
|
||||
local function FindOrCreateMacro(macroName)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Finding or creating macro: %s", ModuleName, macroName))
|
||||
end
|
||||
local idx = GetMacroIndexByName(macroName)
|
||||
if idx == 0 then
|
||||
---@class Macroer
|
||||
shared.Macroer = {
|
||||
Init = function()
|
||||
local function FindOrCreateMacro(macroName)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Creating new macro: %s", ModuleName, macroName))
|
||||
print(string.format("[%s] Finding or creating macro: %s", ModuleName, macroName))
|
||||
end
|
||||
CreateMacro(macroName, "INV_Misc_QuestionMark", "")
|
||||
end
|
||||
idx = GetMacroIndexByName(macroName)
|
||||
if Heimdall_Data.config.macroer.debug then print(string.format("[%s] Macro index: %d", ModuleName, idx)) end
|
||||
return idx
|
||||
end
|
||||
|
||||
---@param stinkies table<string, Stinky>
|
||||
local function FixMacro(stinkies)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Fixing macro with %d stinkies", ModuleName, #stinkies))
|
||||
end
|
||||
if not Heimdall_Data.config.macroer.enabled then
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Module disabled, skipping macro update", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
if InCombatLockdown() then
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] In combat, skipping macro update", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local priorityMap = {}
|
||||
for priority, className in ipairs(Heimdall_Data.config.macroer.priority) do
|
||||
priorityMap[className] = priority
|
||||
end
|
||||
local minPriority = #Heimdall_Data.config.macroer.priority + 1
|
||||
|
||||
local sortedStinkies = {}
|
||||
for _, stinky in pairs(stinkies) do
|
||||
if not shared.AgentTracker.IsAgent(stinky.name) then sortedStinkies[#sortedStinkies + 1] = stinky end
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Processing %d non-agent stinkies", ModuleName, #sortedStinkies))
|
||||
end
|
||||
|
||||
table.sort(sortedStinkies, function(a, b)
|
||||
local aPriority = priorityMap[a.class] or minPriority
|
||||
local bPriority = priorityMap[b.class] or minPriority
|
||||
return aPriority > bPriority
|
||||
end)
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Sorted stinkies: %d", ModuleName, #sortedStinkies))
|
||||
shared.dumpTable(sortedStinkies)
|
||||
end
|
||||
local lines = { "/targetenemy" }
|
||||
for _, stinky in pairs(sortedStinkies) do
|
||||
if stinky.seenAt > GetTime() - 600 then
|
||||
local idx = GetMacroIndexByName(macroName)
|
||||
if idx == 0 then
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Adding target macro for: %s", ModuleName, stinky.name))
|
||||
print(string.format("[%s] Creating new macro: %s", ModuleName, macroName))
|
||||
end
|
||||
lines[#lines + 1] = string.format("/tar %s", stinky.name)
|
||||
CreateMacro(macroName, "INV_Misc_QuestionMark", "")
|
||||
end
|
||||
idx = GetMacroIndexByName(macroName)
|
||||
if Heimdall_Data.config.macroer.debug then print(string.format("[%s] Macro index: %d", ModuleName, idx)) end
|
||||
return idx
|
||||
end
|
||||
|
||||
local idx = FindOrCreateMacro("HeimdallTarget")
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local body = strjoin("\n", unpack(lines))
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Updating macro with %d lines", ModuleName, #lines))
|
||||
end
|
||||
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
||||
end
|
||||
---@param stinkies table<string, Stinky>
|
||||
local function FixMacro(stinkies)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Fixing macro with %d stinkies", ModuleName, #stinkies))
|
||||
end
|
||||
if not Heimdall_Data.config.macroer.enabled then
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Module disabled, skipping macro update", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
if InCombatLockdown() then
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] In combat, skipping macro update", ModuleName))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
shared.StinkyTracker.OnChange(function(stinkies)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Stinkies changed, updating macro", ModuleName))
|
||||
shared.dumpTable(stinkies)
|
||||
end
|
||||
FixMacro(stinkies)
|
||||
end)
|
||||
local priorityMap = {}
|
||||
for priority, className in ipairs(Heimdall_Data.config.macroer.priority) do
|
||||
priorityMap[className] = priority
|
||||
end
|
||||
local minPriority = #Heimdall_Data.config.macroer.priority + 1
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
print("[Heimdall] Macroer loaded")
|
||||
end
|
||||
local sortedStinkies = {}
|
||||
for _, stinky in pairs(stinkies) do
|
||||
if not shared.AgentTracker.IsAgent(stinky.name) then sortedStinkies[#sortedStinkies + 1] = stinky end
|
||||
end
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Processing %d non-agent stinkies", ModuleName, #sortedStinkies))
|
||||
end
|
||||
|
||||
table.sort(sortedStinkies, function(a, b)
|
||||
local aPriority = priorityMap[a.class] or minPriority
|
||||
local bPriority = priorityMap[b.class] or minPriority
|
||||
return aPriority > bPriority
|
||||
end)
|
||||
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Sorted stinkies: %d", ModuleName, #sortedStinkies))
|
||||
shared.dumpTable(sortedStinkies)
|
||||
end
|
||||
local lines = { "/targetenemy" }
|
||||
for _, stinky in pairs(sortedStinkies) do
|
||||
if stinky.seenAt > GetTime() - 600 then
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Adding target macro for: %s", ModuleName, stinky.name))
|
||||
end
|
||||
lines[#lines + 1] = string.format("/tar %s", stinky.name)
|
||||
end
|
||||
end
|
||||
|
||||
local idx = FindOrCreateMacro("HeimdallTarget")
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local body = strjoin("\n", unpack(lines))
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Updating macro with %d lines", ModuleName, #lines))
|
||||
end
|
||||
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
||||
end
|
||||
|
||||
shared.StinkyTracker.OnChange(function(stinkies)
|
||||
if Heimdall_Data.config.macroer.debug then
|
||||
print(string.format("[%s] Stinkies changed, updating macro", ModuleName))
|
||||
shared.dumpTable(stinkies)
|
||||
end
|
||||
FixMacro(stinkies)
|
||||
end)
|
||||
if Heimdall_Data.config.macroer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
||||
print("[Heimdall] Macroer loaded")
|
||||
end,
|
||||
}
|
||||
|
Reference in New Issue
Block a user