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] 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 local 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 local 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()) ---@type Message local msg = { channel = "CHANNEL", data = Heimdall_Data.config.combatAlerter.masterChannel, message = string.format(shared.L.en.combatAlerterInCombat, source, zone, subZone, tostring(GetCurrentMapAreaID()), x * 100, y * 100 ), } if Heimdall_Data.config.combatAlerter.debug then print(string.format("[%s] Queuing alert message: '%s'", ModuleName, msg.message)) end table.insert(shared.messenger.queue, msg) if not shared.L.ru.zones[zone] then print(string.format("[%s] Zone %s not found in ru.zones", ModuleName, zone)) end zone = shared.L.ru.zones[zone] or zone if not shared.L.ru.zones[subZone] then print(string.format("[%s] Subzone %s not found in ru.zones", ModuleName, subZone)) end subZone = shared.L.ru.zones[subZone] or subZone ---@type Message msg = { channel = "CHANNEL", data = Heimdall_Data.config.combatAlerter.masterChannel .. "ru", message = string.format(shared.L.ru.combatAlerterInCombat, source, zone, subZone, tostring(GetCurrentMapAreaID()), x * 100, y * 100 ), } table.insert(shared.messenger.queue, msg) 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