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

Loading…
Cancel
Save