Rework spotter to work with hostile units too (ie. horde)
This commit is contained in:
40
Spotter.lua
40
Spotter.lua
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user