Rework spotter to work with hostile units too (ie. horde)

This commit is contained in:
2024-12-12 13:52:52 +01:00
parent 31bc0f5287
commit b8f97fb8a4
2 changed files with 52 additions and 32 deletions

View File

@@ -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,21 +34,21 @@ if not Heimdall_Data then Heimdall_Data = {} end
--- Data ---
---@class HeimdallMessengerData
---@field queue table<string, Message>
---@field ticker number
---@field ticker number?
data = {
messenger = {
queue = {},
ticker = nil
},
config = {
data.messenger = {
queue = {}
}
data.config = {
spotter = {
enabled = true,
allyOnly = false,
stinkyOnly = false,
hostile = true,
alliance = false,
stinky = false,
notifyChannel = "Foobar",
zoneOverride = nil,
throttleTime = 10
throttleTime = 1
},
who = {
enabled = true
@@ -56,7 +57,6 @@ data = {
enabled = true
}
}
}
data.raceMap = {
["Orc"] = "Horde",

View File

@@ -18,6 +18,25 @@ end
---@type table<string, number>
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