Refactor StinkyTracker to improve tracking and ignore functionality

This commit is contained in:
2025-05-18 10:51:33 +02:00
parent f70c5adfcf
commit 20a7c0eead
4 changed files with 338 additions and 236 deletions

View File

@@ -47,7 +47,7 @@ local function init()
---@field Echoer InitTable
---@field Macroer InitTable
---@field Commander InitTable
---@field StinkyTracker InitTable
---@field StinkyTracker StinkyTracker
---@field CombatAlerter InitTable
---@field Config InitTable
---@field Sniffer InitTable
@@ -183,6 +183,7 @@ local function init()
---@class HeimdallStinkyTrackerConfig
---@field enabled boolean
---@field debug boolean
---@field ignoredTimeout number
---@field channels string[]
---@class HeimdallCombatAlerterConfig
@@ -283,7 +284,8 @@ local function init()
---@field ignored table<string, boolean>
---@class HeimdallStinkyTrackerData
---@field stinkies ReactiveValue
---@field stinkies ReactiveValue<table<string, Stinky>>
---@field ignored ReactiveValue<table<string, number>>
---@class HeimdallNetworkData
---@field ticker number?

View File

@@ -53,7 +53,7 @@ function shared.CombatAlerter.Init()
print(string.format("[%s] Combat event source: %s", ModuleName, source))
end
if shared.stinkyTracker.stinkies and shared.stinkyTracker.stinkies[source] then
if shared.StinkyTracker.IsStinky(source) then
if Heimdall_Data.config.combatAlerter.debug then
print(
string.format(

View File

@@ -234,12 +234,40 @@ function shared.Commander.Init()
if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Adding stinky: %s/%s", ModuleName, name, tostring(class)))
end
shared.stinkyTracker.stinkies[name] = {
shared.StinkyTracker.Track({
name = name,
class = class or "unknown",
seenAt = GetTime(),
hostile = true,
}
})
if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Added stinky: %s/%s", ModuleName, name, tostring(class)))
end
end
return {}
end
---@param args string[]
local function IgnoreMacroTarget(args)
if Heimdall_Data.config.commander.debug then
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
print(string.format("[%s] Macroing: %s", ModuleName, strjoin(" ", unpack(args))))
end
if #args < 1 then
if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Invalid number of arguments for IgnoreMacroTarget", ModuleName))
end
return {}
end
table.remove(args, 1)
for i = 1, #args do
local stinky = strtrim(args[i])
local name = stinky:match("([^/]+)")
if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Ignoring stinky: %s", ModuleName, name))
end
shared.StinkyTracker.Ignore(name)
end
return {}
end
@@ -259,6 +287,7 @@ function shared.Commander.Init()
{ keywordRe = "^leavegroup$", commanderOnly = false, callback = LeaveGroup },
{ keywordRe = "^follow$", commanderOnly = false, callback = FollowTarget },
{ keywordRe = "^macro", commanderOnly = false, callback = MacroTarget },
{ keywordRe = "^ignore", commanderOnly = false, callback = IgnoreMacroTarget },
}
local commanderChannelFrame = CreateFrame("Frame")

View File

@@ -2,11 +2,76 @@ local _, shared = ...
---@cast shared HeimdallShared
local ModuleName = "StinkyTracker"
---@diagnostic disable-next-line: missing-fields
shared.StinkyTracker = {}
function shared.StinkyTracker.Init()
---@class Stinky
---@field name string
---@field class string
---@field seenAt number
---@field hostile boolean
---@class StinkyTracker
shared.StinkyTracker = {
---@param stinky Stinky
---@return boolean
Track = function(stinky)
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Request to track stinky: %s (%s)", ModuleName, stinky.name, stinky.class))
end
local ignored = shared.stinkyTracker.ignored[stinky.name]
-- TODO: Add a config option for the ignored timeout
if ignored and ignored > GetTime() - 60 then
if Heimdall_Data.config.stinkyTracker.debug then
print(
string.format(
"[%s] Stinky is ignored, not tracking: %s (%s)",
ModuleName,
stinky.name,
stinky.class
)
)
shared.dumpTable(shared.stinkyTracker.ignored)
shared.dumpTable(shared.stinkyTracker.stinkies)
end
return false
else
-- Timed out or was never ignored
shared.stinkyTracker.stinkies[stinky.name] = nil
end
shared.stinkyTracker.stinkies[stinky.name] = stinky
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Stinky is now tracked: %s (%s)", ModuleName, stinky.name, stinky.class))
shared.dumpTable(shared.stinkyTracker.stinkies)
shared.dumpTable(shared.stinkyTracker.ignored)
end
return true
end,
---@param name string
---@return nil
Ignore = function(name)
shared.stinkyTracker.ignored[name] = GetTime()
shared.stinkyTracker.stinkies[name] = nil
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Stinky is now ignored: %s", ModuleName, name))
shared.dumpTable(shared.stinkyTracker.ignored)
shared.dumpTable(shared.stinkyTracker.stinkies)
end
end,
---@param name string
---@return boolean
IsStinky = function(name)
if not shared.stinkyTracker.stinkies then return false end
if not shared.stinkyTracker.stinkies[name] then return false end
if shared.stinkyTracker.ignored[name] then return false end
return true
end,
Init = function()
shared.stinkyTracker = {
stinkies = ReactiveValue.new({}),
ignored = ReactiveValue.new({}),
}
local whoRegex = "([^ -/]+)-?%w*/(%w+)"
@@ -143,6 +208,7 @@ function shared.StinkyTracker.Init()
shared.dumpTable(Heimdall_Data.config.stinkyTracker)
end
local stinkies = {}
if string.find(msg, "^who:") then
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Processing WHO message from %s", ModuleName, sender))
@@ -150,16 +216,10 @@ function shared.StinkyTracker.Init()
local whoStinkies = ParseWho(msg)
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Found stinkies in WHO message", ModuleName))
shared.dumpTable(whoStinkies)
end
for name, stinky in pairs(whoStinkies) do
if stinky.hostile then
shared.stinkyTracker.stinkies[name] = stinky
if Heimdall_Data.config.stinkyTracker.debug then
print(
string.format("[%s] Added hostile stinky from WHO: %s (%s)", ModuleName, name, stinky.class)
)
end
end
stinkies[name] = stinky
end
end
if string.find(msg, "^I see") then
@@ -169,12 +229,10 @@ function shared.StinkyTracker.Init()
local seeStinkies = ParseSee(msg)
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Found stinkies in SEE message", ModuleName))
shared.dumpTable(seeStinkies)
end
for name, stinky in pairs(seeStinkies) do
shared.stinkyTracker.stinkies[name] = stinky
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Added hostile stinky from SEE: %s (%s)", ModuleName, name, stinky.class))
end
stinkies[name] = stinky
end
end
if string.find(msg, "arrived to") or string.find(msg, "moved to") then
@@ -184,11 +242,23 @@ function shared.StinkyTracker.Init()
local arrivedStinkies = ParseArrived(msg)
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Found stinkies in ARRIVED message", ModuleName))
shared.dumpTable(arrivedStinkies)
end
for name, stinky in pairs(arrivedStinkies) do
stinkies[name] = stinky
end
end
for name, stinky in pairs(stinkies) do
if shared.stinkyTracker.ignored[name] then
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Ignoring stinky: %s (%s)", ModuleName, name, stinky.class))
end
shared.stinkyTracker.ignored[name] = nil
else
shared.stinkyTracker.stinkies[name] = stinky
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Added stinky from ARRIVED: %s (%s)", ModuleName, name, stinky.class))
print(string.format("[%s] Added stinky: %s (%s)", ModuleName, name, stinky.class))
end
end
end
@@ -264,4 +334,5 @@ function shared.StinkyTracker.Init()
if Heimdall_Data.config.stinkyTracker.debug then print(string.format("[%s] Module initialized", ModuleName)) end
print("[Heimdall] StinkyTracker loaded")
end
end,
}