136 lines
4.1 KiB
Lua
136 lines
4.1 KiB
Lua
local _, shared = ...
|
|
---@cast shared HeimdallShared
|
|
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] Combat log event received", ModuleName))
|
|
end
|
|
if not Heimdall_Data.config.combatAlerter.enabled then
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Module disabled, ignoring combat event", ModuleName))
|
|
end
|
|
return
|
|
end
|
|
|
|
---@type string|nil, string, string
|
|
local err, source, destination
|
|
|
|
destination, err = CLEUParser.GetDestName(...)
|
|
if err then
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Error getting destination: %s", ModuleName, err))
|
|
end
|
|
return
|
|
end
|
|
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Combat event destination: %s", ModuleName, destination))
|
|
end
|
|
|
|
if destination ~= UnitName("player") then
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Ignoring event - not targeted at player", ModuleName))
|
|
end
|
|
return
|
|
end
|
|
|
|
source, err = CLEUParser.GetSourceName(...)
|
|
if err then
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Error getting source, using 'unknown': %s", ModuleName, err))
|
|
end
|
|
source = "unknown"
|
|
end
|
|
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Combat event source: %s", ModuleName, source))
|
|
end
|
|
|
|
if shared.stinkyTracker.stinkies and shared.stinkyTracker.stinkies[source] then
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(
|
|
string.format(
|
|
"[%s] Source is tracked stinky: %s (Already alerted: %s)",
|
|
ModuleName,
|
|
source,
|
|
tostring(alerted[source] or false)
|
|
)
|
|
)
|
|
end
|
|
if alerted[source] then return end
|
|
|
|
alerted[source] = true
|
|
local x, y = GetPlayerMapPosition("player")
|
|
local zone, subZone = GetZoneText(), GetSubZoneText()
|
|
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(
|
|
string.format(
|
|
"[%s] Player location: %s/%s at %.2f,%.2f",
|
|
ModuleName,
|
|
zone,
|
|
subZone,
|
|
x * 100,
|
|
y * 100
|
|
)
|
|
)
|
|
end
|
|
|
|
SetMapToCurrentZone()
|
|
SetMapByID(GetCurrentMapAreaID())
|
|
local areaId = GetCurrentMapAreaID()
|
|
|
|
for _, channel in pairs(Heimdall_Data.config.combatAlerter.channels) do
|
|
local locale = shared.GetLocaleForChannel(channel)
|
|
local text = string.format(
|
|
shared._L("combatAlerterInCombat", locale),
|
|
source,
|
|
shared._L("zone", locale),
|
|
shared._L("subZone", locale),
|
|
tostring(areaId),
|
|
x * 100,
|
|
y * 100
|
|
)
|
|
---@type Message
|
|
local msg = {
|
|
channel = "C",
|
|
data = channel,
|
|
message = text,
|
|
}
|
|
if Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Queuing alert message", ModuleName))
|
|
shared.dump(msg)
|
|
end
|
|
table.insert(shared.messenger.queue, msg)
|
|
end
|
|
elseif Heimdall_Data.config.combatAlerter.debug then
|
|
print(string.format("[%s] Source not in stinky list, ignoring: %s", ModuleName, source))
|
|
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] Combat state changed: %s", ModuleName, event))
|
|
if event == "PLAYER_REGEN_DISABLED" then
|
|
print(string.format("[%s] Entered combat - Resetting alerts", ModuleName))
|
|
else
|
|
print(string.format("[%s] Left combat - Resetting alerts", ModuleName))
|
|
end
|
|
end
|
|
alerted = {}
|
|
end)
|
|
|
|
if Heimdall_Data.config.combatAlerter.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
|
print("[Heimdall] CombatAlerter loaded")
|
|
end
|