Clean up Unit `self.id` references

main
jeffi 10 months ago
parent ab44f60401
commit cfd67584e7
  1. 27
      src/Unit/Unit.lua

@ -6,7 +6,7 @@ Bastion = ...
-- Create a new Unit class -- Create a new Unit class
---@class Bastion.Unit ---@class Bastion.Unit
---@field cache Bastion.Cache ---@field cache Bastion.Cache
---@field id boolean | number ---@field id false | number
---@field ttd_ticker false | cbObject ---@field ttd_ticker false | cbObject
---@field unit? TinkrObjectReference ---@field unit? TinkrObjectReference
---@field aura_table Bastion.AuraTable | nil ---@field aura_table Bastion.AuraTable | nil
@ -840,14 +840,11 @@ function Unit:InMelee(unit)
end end
-- Get object id -- Get object id
---@return number
function Unit:GetID() function Unit:GetID()
if self.id ~= false then if self.id ~= false then
---@type number
return self.id return self.id
end end
self.id = ObjectID(self:GetOMToken()) self.id = ObjectID(self:GetOMToken())
---@type number
return self.id or 0 return self.id or 0
end end
@ -1435,10 +1432,13 @@ end
---@param npcId? number ---@param npcId? number
---@return boolean ---@return boolean
function Unit:IsInBossList(npcId) function Unit:IsInBossList(npcId)
npcId = npcId or self:GetID() local id = npcId or self:GetID()
if not id then
return false
end
for i = 1, 4 do for i = 1, 4 do
local thisUnit = Bastion.UnitManager:Get(string.format("boss%d", i)) local thisUnit = Bastion.UnitManager:Get(string.format("boss%d", i))
if thisUnit:Exists() and thisUnit:GetID() == npcId then if thisUnit:Exists() and thisUnit:GetID() == id then
return true return true
end end
end end
@ -1462,11 +1462,15 @@ end
---@param hp? number ---@param hp? number
---@return boolean ---@return boolean
function Unit:CheckHPFromBossList(npcId, hp) function Unit:CheckHPFromBossList(npcId, hp)
npcId = npcId or self:GetID() local id = npcId or self:GetID()
if not id then
return false
end
local thisHP = hp or 100 local thisHP = hp or 100
for i = 1, 4 do for i = 1, 4 do
local thisUnit = Bastion.UnitManager:Get(string.format("boss%d", i)) local thisUnit = Bastion.UnitManager:Get(string.format("boss%d", i))
if thisUnit:Exists() and thisUnit:GetID() == npcId and thisUnit:GetHealthPercent() <= thisHP then if thisUnit:Exists() and thisUnit:GetID() == id and thisUnit:GetHealthPercent() <= thisHP then
return true return true
end end
end end
@ -1547,9 +1551,12 @@ function Unit:TimeToDie2(minSamples)
ttd = {} ttd = {}
unitInfo.TTD = ttd unitInfo.TTD = ttd
end end
local v local v
if not ttd[minSamples] then local id = self:GetID()
v = self:TimeToX(self:SpecialTTDPercentage(self:GetID()), minSamples)
if not ttd[minSamples] and id then
v = self:TimeToX(self:SpecialTTDPercentage(id), minSamples)
if v >= 0 then if v >= 0 then
ttd[minSamples] = v ttd[minSamples] = v
Bastion.Globals.UnitInfo:Set(unitGuid, unitInfo, .5) Bastion.Globals.UnitInfo:Set(unitGuid, unitInfo, .5)

Loading…
Cancel
Save