Rework spotter to work with hostile units too (ie. horde)
This commit is contained in:
44
Heimdall.lua
44
Heimdall.lua
@@ -18,8 +18,9 @@ if not Heimdall_Data then Heimdall_Data = {} end
|
|||||||
|
|
||||||
---@class HeimdallSpotterConfig
|
---@class HeimdallSpotterConfig
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
---@field allyOnly boolean
|
---@field hostile boolean
|
||||||
---@field stinkyOnly boolean
|
---@field alliance boolean
|
||||||
|
---@field stinky boolean
|
||||||
---@field notifyChannel string
|
---@field notifyChannel string
|
||||||
---@field zoneOverride string?
|
---@field zoneOverride string?
|
||||||
---@field throttleTime number
|
---@field throttleTime number
|
||||||
@@ -33,28 +34,27 @@ if not Heimdall_Data then Heimdall_Data = {} end
|
|||||||
--- Data ---
|
--- Data ---
|
||||||
---@class HeimdallMessengerData
|
---@class HeimdallMessengerData
|
||||||
---@field queue table<string, Message>
|
---@field queue table<string, Message>
|
||||||
---@field ticker number
|
---@field ticker number?
|
||||||
|
|
||||||
data = {
|
data.messenger = {
|
||||||
messenger = {
|
queue = {}
|
||||||
queue = {},
|
}
|
||||||
ticker = nil
|
|
||||||
|
data.config = {
|
||||||
|
spotter = {
|
||||||
|
enabled = true,
|
||||||
|
hostile = true,
|
||||||
|
alliance = false,
|
||||||
|
stinky = false,
|
||||||
|
notifyChannel = "Foobar",
|
||||||
|
zoneOverride = nil,
|
||||||
|
throttleTime = 1
|
||||||
},
|
},
|
||||||
config = {
|
who = {
|
||||||
spotter = {
|
enabled = true
|
||||||
enabled = true,
|
},
|
||||||
allyOnly = false,
|
messenger = {
|
||||||
stinkyOnly = false,
|
enabled = true
|
||||||
notifyChannel = "Foobar",
|
|
||||||
zoneOverride = nil,
|
|
||||||
throttleTime = 10
|
|
||||||
},
|
|
||||||
who = {
|
|
||||||
enabled = true
|
|
||||||
},
|
|
||||||
messenger = {
|
|
||||||
enabled = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
Spotter.lua
40
Spotter.lua
@@ -18,6 +18,25 @@ end
|
|||||||
---@type table<string, number>
|
---@type table<string, number>
|
||||||
local throttleTable = {}
|
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
|
---@param unit string
|
||||||
---@return string?
|
---@return string?
|
||||||
local function NotifySpotted(unit)
|
local function NotifySpotted(unit)
|
||||||
@@ -38,15 +57,8 @@ local function NotifySpotted(unit)
|
|||||||
local faction = data.raceMap[race]
|
local faction = data.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 doNotify = true
|
local hostile = UnitCanAttack("player", unit)
|
||||||
if data.config.spotter.allyOnly then
|
local doNotify = ShouldNotify(unit, name, faction, hostile)
|
||||||
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
|
|
||||||
if not doNotify then return string.format("Not notifying %s", tostring(name)) end
|
if not doNotify then return string.format("Not notifying %s", tostring(name)) end
|
||||||
|
|
||||||
local hp = UnitHealth(unit)
|
local hp = UnitHealth(unit)
|
||||||
@@ -64,13 +76,21 @@ local function NotifySpotted(unit)
|
|||||||
location = string.format("%s (%s)", zone, subzone)
|
location = string.format("%s (%s)", zone, subzone)
|
||||||
end
|
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
|
---@type Message
|
||||||
local msg = {
|
local msg = {
|
||||||
channel = "CHANNEL",
|
channel = "CHANNEL",
|
||||||
data = data.config.spotter.notifyChannel,
|
data = data.config.spotter.notifyChannel,
|
||||||
message = text
|
message = text
|
||||||
}
|
}
|
||||||
|
data.dumpTable(msg)
|
||||||
table.insert(data.messenger.queue, msg)
|
table.insert(data.messenger.queue, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user