71 lines
2.6 KiB
Lua
71 lines
2.6 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared HeimdallShared
|
|
---@cast addonname string
|
|
local ModuleName = "CombatAlerter"
|
|
|
|
---@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 Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Received event: %s", ModuleName, event))
|
|
shared.dumpTable(Heimdall_Data.config.combatAlerter)
|
|
end
|
|
if not Heimdall_Data.config.combatAlerter.enabled then return end
|
|
local destination, err = CLEUParser.GetDestName(...)
|
|
if err then return end
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Destination: %s", ModuleName, destination))
|
|
end
|
|
if destination ~= UnitName("player") then return end
|
|
local source, err = CLEUParser.GetSourceName(...)
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Source: %s", ModuleName, source))
|
|
end
|
|
if err then source = "unknown" end
|
|
|
|
if shared.stinkyTracker.stinkies and shared.stinkyTracker.stinkies[source] then
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Alerted status for %s: %s", ModuleName, source, alerted[source]))
|
|
end
|
|
if alerted[source] then return end
|
|
alerted[source] = true
|
|
local x, y = GetPlayerMapPosition("player")
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Player position: %2.2f,%2.2f", ModuleName, x, y))
|
|
end
|
|
---@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
|
|
),
|
|
}
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Message:", ModuleName))
|
|
shared.dumpTable(msg)
|
|
end
|
|
table.insert(shared.messenger.queue, msg)
|
|
end
|
|
end)
|
|
|
|
local combatTriggerFrame = CreateFrame("Frame")
|
|
combatTriggerFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
|
|
combatTriggerFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
|
|
combatTriggerFrame:SetScript("OnEvent", function(self, event, ...)
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("%s: Received event: %s", ModuleName, event))
|
|
shared.dumpTable(Heimdall_Data.config.combatAlerter)
|
|
end
|
|
alerted = {}
|
|
end)
|
|
|
|
print("Heimdall - CombatAlerter loaded")
|
|
end
|