Refactor macroer to include "I see"
This commit is contained in:
@@ -5,86 +5,124 @@ local addonname, shared = ...
|
|||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
shared.Macroer = {}
|
shared.Macroer = {}
|
||||||
function shared.Macroer.Init()
|
function shared.Macroer.Init()
|
||||||
---@class stinky
|
---@class stinky
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field class string
|
---@field class string
|
||||||
---@field seenAt number
|
---@field seenAt number
|
||||||
|
---@field hostile boolean
|
||||||
|
|
||||||
---@type table<string, stinky>
|
---@type table<string, stinky>
|
||||||
local recentStinkies = {}
|
local recentStinkies = {}
|
||||||
|
|
||||||
local function FindOrCreateMacro(macroName)
|
local function FindOrCreateMacro(macroName)
|
||||||
local idx = GetMacroIndexByName(macroName)
|
local idx = GetMacroIndexByName(macroName)
|
||||||
if idx == 0 then
|
if idx == 0 then
|
||||||
CreateMacro(macroName, "INV_Misc_QuestionMark", "")
|
CreateMacro(macroName, "INV_Misc_QuestionMark", "")
|
||||||
end
|
end
|
||||||
idx = GetMacroIndexByName(macroName)
|
idx = GetMacroIndexByName(macroName)
|
||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param stinkies table<string, stinky>
|
---@param stinkies table<string, stinky>
|
||||||
local function FixMacro(stinkies)
|
local function FixMacro(stinkies)
|
||||||
local priorityMap = {}
|
local priorityMap = {}
|
||||||
for priority, className in ipairs(Heimdall_Data.config.macroer.priority) do
|
for priority, className in ipairs(Heimdall_Data.config.macroer.priority) do
|
||||||
priorityMap[className] = priority
|
priorityMap[className] = priority
|
||||||
end
|
end
|
||||||
local minPriority = #Heimdall_Data.config.macroer.priority + 1
|
local minPriority = #Heimdall_Data.config.macroer.priority + 1
|
||||||
|
|
||||||
local sortedStinkies = {}
|
local sortedStinkies = {}
|
||||||
for _, stinky in pairs(stinkies) do
|
for _, stinky in pairs(stinkies) do
|
||||||
table.insert(sortedStinkies, stinky)
|
table.insert(sortedStinkies, stinky)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.sort(sortedStinkies, function(a, b)
|
table.sort(sortedStinkies, function(a, b)
|
||||||
local aPriority = priorityMap[a.class] or minPriority
|
local aPriority = priorityMap[a.class] or minPriority
|
||||||
local bPriority = priorityMap[b.class] or minPriority
|
local bPriority = priorityMap[b.class] or minPriority
|
||||||
return aPriority > bPriority
|
return aPriority > bPriority
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local lines = { "/targetenemy" }
|
local lines = {"/targetenemy"}
|
||||||
for _, stinky in pairs(sortedStinkies) do
|
for _, stinky in pairs(sortedStinkies) do
|
||||||
if stinky.seenAt > GetTime() - 600 then
|
if stinky.seenAt > GetTime() - 600 then
|
||||||
print(string.format("Macroing %s", stinky.name))
|
print(string.format("Macroing %s", stinky.name))
|
||||||
lines[#lines + 1] = string.format("/tar %s", stinky.name)
|
lines[#lines + 1] = string.format("/tar %s", stinky.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local idx = FindOrCreateMacro("HeimdallTarget")
|
local idx = FindOrCreateMacro("HeimdallTarget")
|
||||||
local body = strjoin("\n", unpack(lines))
|
local body = strjoin("\n", unpack(lines))
|
||||||
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
||||||
end
|
end
|
||||||
|
|
||||||
local frame = CreateFrame("Frame")
|
---@param msg string
|
||||||
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
---@return table<string, stinky>
|
||||||
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
local function ParseWho(msg)
|
||||||
if not Heimdall_Data.config.macroer.enabled then return end
|
local stinkies = {}
|
||||||
local doUpdate = false
|
for name, class in string.gmatch(msg, "([^ -/]+)-?%w*/(%w+)") do
|
||||||
if string.find(msg, "^who:") then
|
stinkies[name] = {
|
||||||
for name, class in string.gmatch(msg, "([^ -/]+)-?%w*/(%w+)") do
|
name = name,
|
||||||
recentStinkies[name] = {
|
class = class,
|
||||||
name = name,
|
seenAt = GetTime(),
|
||||||
class = class,
|
hostile = true
|
||||||
seenAt = GetTime(),
|
}
|
||||||
}
|
end
|
||||||
doUpdate = true
|
return stinkies
|
||||||
end
|
end
|
||||||
end
|
---@param msg string
|
||||||
local name, class = string.match(msg, "I see (Hostile) ([^ -/]+)-?%w*/(%w+) of")
|
---@return table<string, stinky>
|
||||||
if not name then
|
local function ParseSee(msg)
|
||||||
name, class = string.match(msg, "^([^ -/]+)-?%w* of class (%w+)")
|
local stinkies = {}
|
||||||
end
|
local aggression, name, class = string.match(msg, "I see %((%w+)%) ([^ -/]+)-?%w*/(%w+)")
|
||||||
if name then
|
local stinky = {
|
||||||
name = strtrim(name)
|
name = name,
|
||||||
name = string.match(name, "^(.*)-?")
|
class = class,
|
||||||
recentStinkies[name] = {
|
seenAt = GetTime(),
|
||||||
name = name,
|
hostile = aggression == "Hostile"
|
||||||
class = class,
|
}
|
||||||
seenAt = GetTime(),
|
stinkies[name] = stinky
|
||||||
}
|
return stinkies
|
||||||
doUpdate = true
|
end
|
||||||
end
|
---@param msg string
|
||||||
if doUpdate then FixMacro(recentStinkies) end
|
---@return table<string, stinky>
|
||||||
end)
|
local function ParseArrived(msg)
|
||||||
|
local stinkies = {}
|
||||||
|
return stinkies
|
||||||
|
end
|
||||||
|
|
||||||
print("Heimdall - Macroer loaded")
|
local frame = CreateFrame("Frame")
|
||||||
|
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||||
|
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||||
|
if not Heimdall_Data.config.macroer.enabled then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local doUpdate = false
|
||||||
|
if string.find(msg, "^who:") then
|
||||||
|
local whoStinkies = ParseWho(msg)
|
||||||
|
for name, stinky in pairs(whoStinkies) do
|
||||||
|
if stinky.hostile then
|
||||||
|
recentStinkies[name] = stinky
|
||||||
|
doUpdate = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if string.find(msg, "^I see") then
|
||||||
|
local seeStinkies = ParseSee(msg)
|
||||||
|
for name, stinky in pairs(seeStinkies) do
|
||||||
|
if stinky.hostile then
|
||||||
|
recentStinkies[name] = stinky
|
||||||
|
doUpdate = true
|
||||||
|
end
|
||||||
|
if not stinky.hostile then
|
||||||
|
recentStinkies[name] = nil
|
||||||
|
doUpdate = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if doUpdate then
|
||||||
|
FixMacro(recentStinkies)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
print("Heimdall - Macroer loaded")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user