Implement nameplate sussing

This commit is contained in:
2024-11-05 21:37:12 +01:00
parent bf82421580
commit 98322f6b76
3 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
--NAME_PLATE_UNIT_ADDED
function(e, unit)
if not UnitIsPlayer(unit) then return end
local name = UnitName(unit)
local health = UnitHealth(unit)
local player = aura_env.GetPlayer(name)
player.health = health
player:QueryIfNecessary()
WeakAurasSaved.Cyka.Players[name] = player
end

View File

@@ -2,7 +2,8 @@
function()
for i = 1, GetNumWhoResults() do
local name, guild, level, race, class, zone = GetWhoInfo(i)
local player = WeakAurasSaved.Cyka.Players[name] or Player.new(name)
print(string.format("Got player info for %s", name))
local player = aura_env.GetPlayer(name)
player.guild = guild
player.race = race
WeakAurasSaved.Cyka.Players[name] = player

View File

@@ -1,9 +1,20 @@
---@class aura_env
---@field config table
---@field whoQueued boolean
---@field GetPlayer fun(name: string): Player
local channelname = aura_env.config.channelname or "lAKDJjZfNgobMblAangc"
aura_env.whoQueued = false
if not WeakAurasSaved.Cyka then WeakAurasSaved.Cyka = {} end
if not WeakAurasSaved.Cyka.RaceCache then WeakAurasSaved.Cyka.RaceCache = {} end
aura_env.GetPlayer = function(name)
local player = WeakAurasSaved.Cyka.RaceCache[name] or Player.new(name)
WeakAurasSaved.Cyka.RaceCache[name] = player
return player
end
---@class Player
---@field name string
---@field guild string|nil
@@ -22,6 +33,11 @@ Player = {
self.health = 0
return self
end,
QueryIfNecessary = function(self)
if self.whoQueued then return end
if self.race ~= nil then return end
self:QueryWho()
end,
QueryWho = function(self)
if aura_env.whoQueued then
print(string.format("There is already a who query queued, waiting for player %s", self.name))