50 lines
1.7 KiB
Lua
50 lines
1.7 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared HeimdallShared
|
|
---@cast addonname string
|
|
|
|
---@diagnostic disable-next-line: missing-fields
|
|
shared.CombatAlerter = {}
|
|
function shared.CombatAlerter.Init()
|
|
local alerted = {}
|
|
local combatAlerterFrame = CreateFrame("Frame")
|
|
combatAlerterFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
|
|
combatAlerterFrame:SetScript("OnEvent", function(self, event, ...)
|
|
if not Heimdall_Data.config.combatAlerter.enabled then return end
|
|
local destination, err = CLEUParser.GetDestName(...)
|
|
if err then return end
|
|
if destination ~= UnitName("player") then return end
|
|
local source, err = CLEUParser.GetSourceName(...)
|
|
if err then source = "unknown" end
|
|
|
|
if shared.stinkyTracker.stinkies and shared.stinkyTracker.stinkies[source] then
|
|
if alerted[source] then return end
|
|
alerted[source] = true
|
|
local x, y = GetPlayerMapPosition("player")
|
|
---@type Message
|
|
local msg = {
|
|
channel = "CHANNEL",
|
|
data = Heimdall_Data.config.combatAlerter.masterChannel,
|
|
message = string.format("%s is attacking me in %s(%s) at %2.2f,%2.2f ",
|
|
source,
|
|
GetZoneText(), GetSubZoneText(),
|
|
x * 100, y * 100
|
|
),
|
|
}
|
|
table.insert(shared.messenger.queue, msg)
|
|
end
|
|
end)
|
|
|
|
local combatTriggerFrame = CreateFrame("Frame")
|
|
combatTriggerFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
|
|
combatTriggerFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
|
|
-- We want to only alert once per target per combat encounter
|
|
-- Even a small throttle would probably spam too much here
|
|
-- ....but maybe we can call it a 120 second throttle or something?
|
|
-- We will see
|
|
combatTriggerFrame:SetScript("OnEvent", function(self, event, ...)
|
|
alerted = {}
|
|
end)
|
|
|
|
print("Heimdall - CombatAlerter loaded")
|
|
end
|