local addonname, shared = ... ---@cast shared HeimdallShared ---@cast addonname string ---@diagnostic disable-next-line: missing-fields shared.Macroer = {} function shared.Macroer.Init() ---@class stinky ---@field name string ---@field class string ---@field seenAt number ---@field hostile boolean ---@type table local recentStinkies = {} local function FindOrCreateMacro(macroName) local idx = GetMacroIndexByName(macroName) if idx == 0 then CreateMacro(macroName, "INV_Misc_QuestionMark", "") end idx = GetMacroIndexByName(macroName) return idx end ---@param stinkies table local function FixMacro(stinkies) if not Heimdall_Data.config.macroer.enabled then return end if InCombatLockdown() then 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 table.insert(sortedStinkies, stinky) 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) local lines = { "/targetenemy" } for _, stinky in pairs(sortedStinkies) do if stinky.seenAt > GetTime() - 600 then print(string.format("Macroing %s", stinky.name)) lines[#lines + 1] = string.format("/tar %s", stinky.name) end end local idx = FindOrCreateMacro("HeimdallTarget") local body = strjoin("\n", unpack(lines)) EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body) end shared.stinkyTracker.stinkies:onChange(function(value) FixMacro(value) end) print("Heimdall - Macroer loaded") end