Rework spotter

This commit is contained in:
2025-01-01 14:24:58 +01:00
parent 5e779cc5f9
commit e32966bee2
2 changed files with 26 additions and 25 deletions

View File

@@ -4,10 +4,10 @@ local addonname, shared = ...
shared.Messenger = {} shared.Messenger = {}
function shared.Messenger.Init() function shared.Messenger.Init()
-- if not Heimdall_Data.config.messenger.enabled then -- if not Heimdall_Data.config.messenger.enabled then
-- print("Heimdall - Messenger disabled") -- print("Heimdall - Messenger disabled")
-- return -- return
-- end -- end
---@class Message ---@class Message
---@field message string ---@field message string

View File

@@ -1,13 +1,13 @@
local addonname, data = ... local addonname, shared = ...
---@cast data HeimdallData ---@cast shared HeimdallShared
---@cast addonname string ---@cast addonname string
data.Spotter = {} shared.Spotter = {}
function data.Spotter.Init() function shared.Spotter.Init()
if not data.config.spotter.enabled then -- if not Heimdall_Data.config.spotter.enabled then
print("Heimdall - Spotter disabled") -- print("Heimdall - Spotter disabled")
return -- return
end -- end
local function FormatHP(hp) local function FormatHP(hp)
if hp > 1e9 then if hp > 1e9 then
@@ -31,16 +31,16 @@ function data.Spotter.Init()
---@return boolean ---@return boolean
---@return string? error ---@return string? error
local function ShouldNotify(unit, name, faction, hostile) local function ShouldNotify(unit, name, faction, hostile)
if data.config.spotter.stinky then if Heimdall_Data.config.spotter.stinky then
if data.config.stinkies[name] then return true end if Heimdall_Data.config.stinkies[name] then return true end
end end
if data.config.spotter.alliance then if Heimdall_Data.config.spotter.alliance then
if faction == "Alliance" then return true end if faction == "Alliance" then return true end
end end
if data.config.spotter.hostile then if Heimdall_Data.config.spotter.hostile then
if hostile then return true end if hostile then return true end
end end
return data.config.spotter.everyone return Heimdall_Data.config.spotter.everyone
end end
---@param unit string ---@param unit string
@@ -53,17 +53,17 @@ function data.Spotter.Init()
if not name then return string.format("Could not find name for unit %s", tostring(unit)) end if not name then return string.format("Could not find name for unit %s", tostring(unit)) end
local time = GetTime() local time = GetTime()
if throttleTable[name] and time - throttleTable[name] < data.config.spotter.throttleTime then if throttleTable[name] and time - throttleTable[name] < Heimdall_Data.config.spotter.throttleTime then
return string.format("Throttled %s", tostring(name)) return string.format("Throttled %s", tostring(name))
end end
throttleTable[name] = time throttleTable[name] = time
local race = UnitRace(unit) local race = UnitRace(unit)
if not race then return string.format("Could not find race for unit %s", tostring(unit)) end if not race then return string.format("Could not find race for unit %s", tostring(unit)) end
local faction = data.raceMap[race] local faction = shared.raceMap[race]
if not faction then return string.format("Could not find faction for race %s", tostring(race)) end if not faction then return string.format("Could not find faction for race %s", tostring(race)) end
local hostile = UnitCanAttack("player", unit) local hostile = UnitCanAttack("player", unit) == 1
local doNotify = ShouldNotify(unit, name, faction, hostile) local doNotify = ShouldNotify(unit, name, faction, hostile)
if not doNotify then return string.format("Not notifying for %s", tostring(name)) end if not doNotify then return string.format("Not notifying for %s", tostring(name)) end
@@ -73,7 +73,7 @@ function data.Spotter.Init()
local maxHp = UnitHealthMax(unit) local maxHp = UnitHealthMax(unit)
if not maxHp then return string.format("Could not find maxHp for unit %s", tostring(unit)) end if not maxHp then return string.format("Could not find maxHp for unit %s", tostring(unit)) end
local location = data.config.spotter.zoneOverride local location = Heimdall_Data.config.spotter.zoneOverride
if not location then if not location then
local zone = GetZoneText() local zone = GetZoneText()
if not zone then return string.format("Could not find zone for unit %s", tostring(unit)) end if not zone then return string.format("Could not find zone for unit %s", tostring(unit)) end
@@ -82,7 +82,7 @@ function data.Spotter.Init()
location = string.format("%s (%s)", zone, subzone) location = string.format("%s (%s)", zone, subzone)
end end
local stinky = data.config.stinkies[name] or false local stinky = Heimdall_Data.config.stinkies[name] or false
local text = string.format("I see (%s) %s %s of race %s (%s) with health %s/%s at %s", local text = string.format("I see (%s) %s %s of race %s (%s) with health %s/%s at %s",
hostile and "Hostile" or "Friendly", hostile and "Hostile" or "Friendly",
stinky and string.format("(%s)", "!!!!") or "", stinky and string.format("(%s)", "!!!!") or "",
@@ -96,17 +96,18 @@ function data.Spotter.Init()
---@type Message ---@type Message
local msg = { local msg = {
channel = "CHANNEL", channel = "CHANNEL",
data = data.config.spotter.notifyChannel, data = Heimdall_Data.config.spotter.notifyChannel,
message = text message = text
} }
data.dumpTable(msg) --shared.dumpTable(msg)
table.insert(data.messenger.queue, msg) table.insert(shared.messenger.queue, msg)
end end
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("NAME_PLATE_UNIT_ADDED") frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
frame:RegisterEvent("TARGET_UNIT_CHANGED") frame:RegisterEvent("TARGET_UNIT_CHANGED")
frame:SetScript("OnEvent", function(self, event, unit) frame:SetScript("OnEvent", function(self, event, unit)
if not Heimdall_Data.config.spotter.enabled then return end
local err = NotifySpotted(unit) local err = NotifySpotted(unit)
if err then if err then
print(string.format("Error notifying %s: %s", tostring(unit), tostring(err))) print(string.format("Error notifying %s: %s", tostring(unit), tostring(err)))