Implement macroer logic
This commit is contained in:
@@ -5,6 +5,14 @@ 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
|
||||||
|
---@field name string
|
||||||
|
---@field class string
|
||||||
|
---@field seenAt number
|
||||||
|
|
||||||
|
---@type table<string, stinky>
|
||||||
|
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
|
||||||
@@ -14,35 +22,69 @@ function shared.Macroer.Init()
|
|||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type table<string, number>
|
---@param stinkies table<string, stinky>
|
||||||
local recentStinkies = {}
|
local function FixMacro(stinkies)
|
||||||
|
local lines = {}
|
||||||
|
for name, info in pairs(stinkies) do
|
||||||
|
if info.seenAt > GetTime() - 600 then
|
||||||
|
print(string.format("Macroing %s", name))
|
||||||
|
lines[#lines + 1] = string.format("/tar %s", name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local idx = FindOrCreateMacro("HeimdallTarget")
|
||||||
|
local body = strjoin("\n", unpack(lines))
|
||||||
|
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
||||||
|
print("Updated macro")
|
||||||
|
end
|
||||||
|
|
||||||
local frame = CreateFrame("Frame")
|
local frame = CreateFrame("Frame")
|
||||||
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||||
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||||
if not Heimdall_Data.config.macroer.enabled then return end
|
if not Heimdall_Data.config.macroer.enabled then return end
|
||||||
local stinky = string.match(msg, "I see (Hostile) (.*) of")
|
local doUpdate = false
|
||||||
if not stinky then
|
if string.find(msg, "^who:") then
|
||||||
stinky = string.match(msg, "^(.*) of class")
|
for name, class in string.gmatch(msg, "([^ -/]+)-?%w*/(%w+)") do
|
||||||
|
recentStinkies[name] = {
|
||||||
|
name = name,
|
||||||
|
class = class,
|
||||||
|
seenAt = GetTime(),
|
||||||
|
}
|
||||||
|
doUpdate = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if stinky then
|
local name, class = string.match(msg, "I see (Hostile) (.+)/(%w+) of")
|
||||||
stinky = strtrim(stinky)
|
if not name then
|
||||||
stinky = string.match(stinky, "^(.*)-?")
|
name, class = string.match(msg, "^(.+) of class (%w+)")
|
||||||
recentStinkies[stinky] = GetTime()
|
end
|
||||||
|
if name then
|
||||||
|
name = strtrim(name)
|
||||||
|
name = string.match(name, "^(.*)-?")
|
||||||
|
recentStinkies[name] = {
|
||||||
|
name = name,
|
||||||
|
class = class,
|
||||||
|
seenAt = GetTime(),
|
||||||
|
}
|
||||||
|
doUpdate = true
|
||||||
|
end
|
||||||
|
if doUpdate then
|
||||||
|
FixMacro(recentStinkies)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hooksecurefunc("JumpOrAscendStart", function()
|
hooksecurefunc("JumpOrAscendStart", function()
|
||||||
local idx = FindOrCreateMacro("HeimdallTarget")
|
FixMacro({
|
||||||
local stinkies = {}
|
["茶杯鸭跳芭蕾"] = {
|
||||||
for stinky, time in pairs(recentStinkies) do
|
name = "茶杯鸭跳芭蕾",
|
||||||
if time > GetTime() - 10 then
|
class = "Paladin",
|
||||||
stinkies[#stinkies + 1] = string.format("/tar %s", stinky)
|
seenAt = GetTime(),
|
||||||
end
|
},
|
||||||
end
|
["Asen"] = {
|
||||||
local body = strjoin("\n", unpack(stinkies))
|
name = "Asen",
|
||||||
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
class = "Warlock",
|
||||||
print("Jumped")
|
seenAt = GetTime(),
|
||||||
|
},
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
print("Heimdall - Macroer loaded")
|
print("Heimdall - Macroer loaded")
|
||||||
|
Reference in New Issue
Block a user