112 lines
3.7 KiB
Lua
112 lines
3.7 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared HeimdallShared
|
|
---@cast addonname string
|
|
local ModuleName = "BonkDetector"
|
|
|
|
---@diagnostic disable-next-line: missing-fields
|
|
shared.BonkDetector = {}
|
|
function shared.BonkDetector.Init()
|
|
---@type table<string, number>
|
|
local lastReportTime = {}
|
|
|
|
local frame = CreateFrame("Frame")
|
|
frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
|
|
frame:SetScript("OnEvent", function(self, event, ...)
|
|
-- if Heimdall_Data.config.bonkDetector.debug then
|
|
-- print(string.format("[%s] Combat log event received", ModuleName))
|
|
-- end
|
|
-- if not Heimdall_Data.config.bonkDetector.enabled then
|
|
-- if Heimdall_Data.config.bonkDetector.debug then
|
|
-- print(string.format("[%s] Module disabled, ignoring combat event", ModuleName))
|
|
-- end
|
|
-- return
|
|
-- end
|
|
|
|
local subevent = select(2, ...)
|
|
if not subevent:find("_DAMAGE") then
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Not a damage event, ignoring: %s", ModuleName, subevent))
|
|
end
|
|
return
|
|
end
|
|
|
|
local source, err = CLEUParser.GetSourceName(...)
|
|
if err then
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Error getting source name: %s", ModuleName, err))
|
|
end
|
|
return
|
|
end
|
|
local sourceGUID = CLEUParser.GetSourceGUID(...)
|
|
if not string.find(sourceGUID, "Player") then
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Source %s is not a player, nothing to do", ModuleName, source))
|
|
end
|
|
return
|
|
end
|
|
|
|
local destination, err = CLEUParser.GetDestName(...)
|
|
if err then
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Error getting destination name: %s", ModuleName, err))
|
|
end
|
|
return
|
|
end
|
|
local destinationGUID = CLEUParser.GetDestGUID(...)
|
|
if not string.find(destinationGUID, "Player") then
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Destination %s is not a player, nothing to do", ModuleName, destination))
|
|
end
|
|
return
|
|
end
|
|
|
|
local currentTime = GetTime()
|
|
local throttle = Heimdall_Data.config.bonkDetector.throttle
|
|
|
|
if lastReportTime[source] and (currentTime - lastReportTime[source]) < throttle then
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
local timeLeft = throttle - (currentTime - lastReportTime[source])
|
|
print(string.format("[%s] Damage report throttled for %s (%.1f seconds remaining)",
|
|
ModuleName, source, timeLeft))
|
|
end
|
|
return
|
|
end
|
|
|
|
lastReportTime[source] = currentTime
|
|
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Processing damage event - Source: %s, Target: %s, Type: %s",
|
|
ModuleName, source, destination, subevent))
|
|
end
|
|
|
|
local notifyChannel = Heimdall_Data.config.bonkDetector.notifyChannel
|
|
local msg = string.format("%s hit %s (%s)", source, destination, subevent)
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Queueing message to Agent channel: %s", ModuleName, msg))
|
|
end
|
|
---@type Message
|
|
local message = {
|
|
channel = "CHANNEL",
|
|
data = notifyChannel,
|
|
message = string.format(shared.L.en.bonkDetected, source, destination, subevent),
|
|
}
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Queueing English message: %s", ModuleName, message.message))
|
|
end
|
|
table.insert(shared.messenger.queue, message)
|
|
|
|
-- Russian message
|
|
---@type Message
|
|
message = {
|
|
channel = "CHANNEL",
|
|
data = notifyChannel .. "ru",
|
|
message = string.format(shared.L.ru.bonkDetected, source, destination, subevent),
|
|
}
|
|
if Heimdall_Data.config.bonkDetector.debug then
|
|
print(string.format("[%s] Queueing Russian message: %s", ModuleName, message.message))
|
|
end
|
|
table.insert(shared.messenger.queue, message)
|
|
end)
|
|
|
|
print("[Heimdall] BonkDetector loaded")
|
|
end |