Rework deathreporter
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
local addonname, data = ...
|
||||
---@cast data HeimdallData
|
||||
local addonname, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
---@cast addonname string
|
||||
|
||||
data.DeathReporter = {}
|
||||
function data.DeathReporter.Init()
|
||||
if not data.config.deathReporter.enabled then
|
||||
print("Heimdall - DeathReporter disabled")
|
||||
return
|
||||
end
|
||||
shared.DeathReporter = {}
|
||||
function shared.DeathReporter.Init()
|
||||
-- if not Heimdall_Data.config.deathReporter.enabled then
|
||||
-- print("Heimdall - DeathReporter disabled")
|
||||
-- return
|
||||
-- end
|
||||
|
||||
---@type table<string, number>
|
||||
local recentDeaths = {}
|
||||
@@ -17,20 +17,20 @@ function data.DeathReporter.Init()
|
||||
---@param source string
|
||||
---@param destination string
|
||||
---@param spellName string
|
||||
---@param overkill number
|
||||
local function RegisterDeath(source, destination, spellName, overkill)
|
||||
local function RegisterDeath(source, destination, spellName)
|
||||
if not Heimdall_Data.config.deathReporter.enabled then return end
|
||||
if recentDeaths[destination]
|
||||
and GetTime() - recentDeaths[destination] < data.config.deathReporter.throttle then
|
||||
and GetTime() - recentDeaths[destination] < Heimdall_Data.config.deathReporter.throttle then
|
||||
return
|
||||
end
|
||||
|
||||
if recentDuels[destination]
|
||||
and GetTime() - recentDuels[destination] < data.config.deathReporter.duelThrottle then
|
||||
and GetTime() - recentDuels[destination] < Heimdall_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
|
||||
and GetTime() - recentDuels[source] < Heimdall_Data.config.deathReporter.duelThrottle then
|
||||
print(string.format("Cancelling death reports for %s and %s because of recent duel", source, destination))
|
||||
return
|
||||
end
|
||||
@@ -38,17 +38,17 @@ function data.DeathReporter.Init()
|
||||
recentDeaths[destination] = GetTime()
|
||||
C_Timer.NewTimer(3, function()
|
||||
if recentDuels[destination]
|
||||
and GetTime() - recentDuels[destination] < data.config.deathReporter.duelThrottle then
|
||||
and GetTime() - recentDuels[destination] < Heimdall_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
|
||||
and GetTime() - recentDuels[source] < Heimdall_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
|
||||
local zone = Heimdall_Data.config.deathReporter.zoneOverride
|
||||
if not zone then
|
||||
zone = string.format("%s (%s)", GetZoneText(), GetSubZoneText())
|
||||
end
|
||||
@@ -62,19 +62,19 @@ function data.DeathReporter.Init()
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = data.config.deathReporter.notifyChannel,
|
||||
data = Heimdall_Data.config.deathReporter.notifyChannel,
|
||||
message = text,
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
|
||||
if data.config.deathReporter.doWhisper then
|
||||
for _, name in pairs(data.config.whisperNotify) do
|
||||
if Heimdall_Data.config.deathReporter.doWhisper then
|
||||
for _, name in pairs(Heimdall_Data.config.whisperNotify) do
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = name,
|
||||
message = text,
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -83,6 +83,7 @@ function data.DeathReporter.Init()
|
||||
local cleuFrame = CreateFrame("Frame")
|
||||
cleuFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
|
||||
cleuFrame:SetScript("OnEvent", function(self, event, ...)
|
||||
if not Heimdall_Data.config.deathReporter.enabled then return end
|
||||
local overkill, err = CLEUParser.GetOverkill(...)
|
||||
if not err and overkill > 0 then
|
||||
local source, err = CLEUParser.GetSourceName(...)
|
||||
@@ -95,13 +96,14 @@ function data.DeathReporter.Init()
|
||||
if err or not string.match(sourceGUID, "Player") then return end
|
||||
local destinationGUID, err = CLEUParser.GetDestGUID(...)
|
||||
if err or not string.match(destinationGUID, "Player") then return end
|
||||
RegisterDeath(source, destination, spellName, overkill)
|
||||
RegisterDeath(source, destination, spellName)
|
||||
end
|
||||
end)
|
||||
|
||||
local systemMessageFrame = CreateFrame("Frame")
|
||||
systemMessageFrame:RegisterEvent("CHAT_MSG_SYSTEM")
|
||||
systemMessageFrame:SetScript("OnEvent", function(self, event, msg)
|
||||
if not Heimdall_Data.config.deathReporter.enabled then return end
|
||||
local source, destination = string.match(msg, "(.+) has defeated (.+) in a duel")
|
||||
if source and destination then
|
||||
print(string.format("Detected duel between %s and %s", source, destination))
|
||||
|
||||
Reference in New Issue
Block a user