Rework duel detectioner

The prevoius implementation was so stupid...
This commit is contained in:
2024-12-12 23:53:36 +01:00
parent cdff4ff1dc
commit b344f6176b
2 changed files with 15 additions and 9 deletions

View File

@@ -13,8 +13,6 @@ function data.DeathReporter.Init()
local recentDeaths = {}
---@type table<string, number>
local recentDuels = {}
---@type table<string, number>
local notifyTimers = {}
---@param source string
---@param destination string
@@ -38,7 +36,18 @@ function data.DeathReporter.Init()
end
recentDeaths[destination] = GetTime()
local timer = C_Timer.NewTimer(3, function()
C_Timer.NewTimer(3, function()
if recentDuels[destination]
and GetTime() - recentDuels[destination] < data.config.deathReporter.duelThrottle then
print(string.format("Cancelling death reports for %s and %s because of recent duel", source, destination))
return
end
if recentDuels[source]
and GetTime() - recentDuels[source] < data.config.deathReporter.duelThrottle then
print(string.format("Cancelling death reports for %s and %s because of recent duel", source, destination))
return
end
local zone = data.config.deathReporter.zoneOverride
if not zone then
zone = string.format("%s (%s)", GetZoneText(), GetSubZoneText())
@@ -68,9 +77,7 @@ function data.DeathReporter.Init()
table.insert(data.messenger.queue, msg)
end
end
notifyTimers[destination] = nil
end)
notifyTimers[destination] = timer
end
local cleuFrame = CreateFrame("Frame")
@@ -97,9 +104,7 @@ function data.DeathReporter.Init()
systemMessageFrame:SetScript("OnEvent", function(self, event, msg)
local source, destination = string.match(msg, "(.+) has defeated (.+) in a duel")
if source and destination then
print(string.format("Cancelling death reports for %s and %s", source, destination))
if notifyTimers[source] then notifyTimers[source]:Cancel() end
if notifyTimers[destination] then notifyTimers[destination]:Cancel() end
print(string.format("Detected duel between %s and %s", source, destination))
local now = GetTime()
recentDuels[source] = now
recentDuels[destination] = now

View File

@@ -7,6 +7,7 @@ local addonname, data = ...
-- Take last N seconds of combatlog into account ie. count who does damage to who
-- Maybe even make an alert when someone does too much damage to someone else...
-- But that would not be trivial as of now, I can't think of a way to do it sensibly
-- TODO: Implement auto grouping via agent, maybe find "+" or something
local function init()
---@class Heimdall_Data
@@ -148,7 +149,7 @@ local function init()
doWhisper = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "doWhisper" }, true),
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "notifyChannel" }, "Agent"),
zoneOverride = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "zoneOverride" }, nil),
duelThrottle = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "duelThrottle" }, 2),
duelThrottle = data.GetOrDefault(Heimdall_Data, { "config", "deathReporter", "duelThrottle" }, 5),
},
whisperNotify = data.GetOrDefault(Heimdall_Data, { "config", "whisperNotify" }, {
"Extazyk",