From b344f6176bd4af8baa4fce1cd485e06dbbbc4f1c Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 12 Dec 2024 23:53:36 +0100 Subject: [PATCH] Rework duel detectioner The prevoius implementation was so stupid... --- DeathReporter.lua | 21 +++++++++++++-------- Heimdall.lua | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/DeathReporter.lua b/DeathReporter.lua index ca98f44..bcf32a9 100644 --- a/DeathReporter.lua +++ b/DeathReporter.lua @@ -13,8 +13,6 @@ function data.DeathReporter.Init() local recentDeaths = {} ---@type table local recentDuels = {} - ---@type table - 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 diff --git a/Heimdall.lua b/Heimdall.lua index 15eb964..7cbe23f 100644 --- a/Heimdall.lua +++ b/Heimdall.lua @@ -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",