Refactor macroer to include "I see"
This commit is contained in:
@@ -9,6 +9,7 @@ function shared.Macroer.Init()
|
|||||||
---@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 = {}
|
||||||
@@ -54,36 +55,73 @@ function shared.Macroer.Init()
|
|||||||
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
EditMacro(idx, "HeimdallTarget", "INV_Misc_QuestionMark", body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param msg string
|
||||||
|
---@return table<string, stinky>
|
||||||
|
local function ParseWho(msg)
|
||||||
|
local stinkies = {}
|
||||||
|
for name, class in string.gmatch(msg, "([^ -/]+)-?%w*/(%w+)") do
|
||||||
|
stinkies[name] = {
|
||||||
|
name = name,
|
||||||
|
class = class,
|
||||||
|
seenAt = GetTime(),
|
||||||
|
hostile = true
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return stinkies
|
||||||
|
end
|
||||||
|
---@param msg string
|
||||||
|
---@return table<string, stinky>
|
||||||
|
local function ParseSee(msg)
|
||||||
|
local stinkies = {}
|
||||||
|
local aggression, name, class = string.match(msg, "I see %((%w+)%) ([^ -/]+)-?%w*/(%w+)")
|
||||||
|
local stinky = {
|
||||||
|
name = name,
|
||||||
|
class = class,
|
||||||
|
seenAt = GetTime(),
|
||||||
|
hostile = aggression == "Hostile"
|
||||||
|
}
|
||||||
|
stinkies[name] = stinky
|
||||||
|
return stinkies
|
||||||
|
end
|
||||||
|
---@param msg string
|
||||||
|
---@return table<string, stinky>
|
||||||
|
local function ParseArrived(msg)
|
||||||
|
local stinkies = {}
|
||||||
|
return stinkies
|
||||||
|
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 doUpdate = false
|
local doUpdate = false
|
||||||
if string.find(msg, "^who:") then
|
if string.find(msg, "^who:") then
|
||||||
for name, class in string.gmatch(msg, "([^ -/]+)-?%w*/(%w+)") do
|
local whoStinkies = ParseWho(msg)
|
||||||
recentStinkies[name] = {
|
for name, stinky in pairs(whoStinkies) do
|
||||||
name = name,
|
if stinky.hostile then
|
||||||
class = class,
|
recentStinkies[name] = stinky
|
||||||
seenAt = GetTime(),
|
|
||||||
}
|
|
||||||
doUpdate = true
|
doUpdate = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local name, class = string.match(msg, "I see (Hostile) ([^ -/]+)-?%w*/(%w+) of")
|
|
||||||
if not name then
|
|
||||||
name, class = string.match(msg, "^([^ -/]+)-?%w* of class (%w+)")
|
|
||||||
end
|
end
|
||||||
if name then
|
if string.find(msg, "^I see") then
|
||||||
name = strtrim(name)
|
local seeStinkies = ParseSee(msg)
|
||||||
name = string.match(name, "^(.*)-?")
|
for name, stinky in pairs(seeStinkies) do
|
||||||
recentStinkies[name] = {
|
if stinky.hostile then
|
||||||
name = name,
|
recentStinkies[name] = stinky
|
||||||
class = class,
|
|
||||||
seenAt = GetTime(),
|
|
||||||
}
|
|
||||||
doUpdate = true
|
doUpdate = true
|
||||||
end
|
end
|
||||||
if doUpdate then FixMacro(recentStinkies) end
|
if not stinky.hostile then
|
||||||
|
recentStinkies[name] = nil
|
||||||
|
doUpdate = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if doUpdate then
|
||||||
|
FixMacro(recentStinkies)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
print("Heimdall - Macroer loaded")
|
print("Heimdall - Macroer loaded")
|
||||||
|
|||||||
Reference in New Issue
Block a user