diff --git a/Heimdall.lua b/Heimdall.lua index 8b1b3ef..f1f79a7 100644 --- a/Heimdall.lua +++ b/Heimdall.lua @@ -18,8 +18,9 @@ if not Heimdall_Data then Heimdall_Data = {} end ---@class HeimdallSpotterConfig ---@field enabled boolean ----@field allyOnly boolean ----@field stinkyOnly boolean +---@field hostile boolean +---@field alliance boolean +---@field stinky boolean ---@field notifyChannel string ---@field zoneOverride string? ---@field throttleTime number @@ -33,28 +34,27 @@ if not Heimdall_Data then Heimdall_Data = {} end --- Data --- ---@class HeimdallMessengerData ---@field queue table ----@field ticker number +---@field ticker number? -data = { - messenger = { - queue = {}, - ticker = nil +data.messenger = { + queue = {} +} + +data.config = { + spotter = { + enabled = true, + hostile = true, + alliance = false, + stinky = false, + notifyChannel = "Foobar", + zoneOverride = nil, + throttleTime = 1 }, - config = { - spotter = { - enabled = true, - allyOnly = false, - stinkyOnly = false, - notifyChannel = "Foobar", - zoneOverride = nil, - throttleTime = 10 - }, - who = { - enabled = true - }, - messenger = { - enabled = true - } + who = { + enabled = true + }, + messenger = { + enabled = true } } diff --git a/Spotter.lua b/Spotter.lua index c42c6a4..4a1a747 100644 --- a/Spotter.lua +++ b/Spotter.lua @@ -18,6 +18,25 @@ end ---@type table local throttleTable = {} +---@param unit string +---@param name string +---@param faction string +---@param hostile boolean +---@return boolean +---@return string? error +local function ShouldNotify(unit, name, faction, hostile) + if data.config.spotter.stinky then + if data.stinkies[name] then return true end + end + if data.config.spotter.alliance then + if faction == "Alliance" then return true end + end + if data.config.spotter.hostile then + if hostile then return true end + end + return false +end + ---@param unit string ---@return string? local function NotifySpotted(unit) @@ -38,15 +57,8 @@ local function NotifySpotted(unit) local faction = data.raceMap[race] if not faction then return string.format("Could not find faction for race %s", tostring(race)) end - local doNotify = true - if data.config.spotter.allyOnly then - doNotify = false - if faction == "Alliance" then doNotify = true end - end - if data.config.spotter.stinkyOnly then - doNotify = false - if data.stinkies[name] then doNotify = true end - end + local hostile = UnitCanAttack("player", unit) + local doNotify = ShouldNotify(unit, name, faction, hostile) if not doNotify then return string.format("Not notifying %s", tostring(name)) end local hp = UnitHealth(unit) @@ -64,13 +76,21 @@ local function NotifySpotted(unit) location = string.format("%s (%s)", zone, subzone) end - local text = string.format("I see %s of race (%s) with health %s/%s at %s", name, race, FormatHP(hp), FormatHP(maxHp), location) + local text = string.format("I see (%s) %s of race (%s) with health %s/%s at %s", + hostile and "Hostile" or "Friendly", + name, + race, + FormatHP(hp), + FormatHP(maxHp), + location) + ---@type Message local msg = { channel = "CHANNEL", data = data.config.spotter.notifyChannel, message = text } + data.dumpTable(msg) table.insert(data.messenger.queue, msg) end