Type Updates, Spell optimizations, New (HeroLib) TTD calc

main
ck 1 year ago
parent 4d0719b869
commit 09a2fd2e63
  1. 28
      src/Aura/Aura.lua
  2. 18
      src/AuraTable/AuraTable.lua
  3. 11
      src/Cacheable/Cacheable.lua
  4. 3
      src/ItemBook/ItemBook.lua
  5. 2
      src/Refreshable/Refreshable.lua
  6. 106
      src/Spell/Spell.lua
  7. 29
      src/SpellBook/SpellBook.lua
  8. 27
      src/TimeToDie/TimeToDie.lua
  9. 57
      src/Unit/Unit.lua
  10. 13
      src/UnitManager/UnitManager.lua
  11. 12
      src/_bastion.lua

@ -2,8 +2,30 @@
---@type Tinkr, Bastion ---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
---@class AuraAuraData
---@field auraInstanceID? number
---@field name? string
---@field icon? number
---@field count number
---@field dispelType? string
---@field duration number
---@field expirationTime number
---@field source? string
---@field isStealable boolean
---@field nameplateShowPersonal boolean
---@field spellId number
---@field canApplyAura boolean
---@field isBossDebuff boolean
---@field castByPlayer boolean
---@field nameplateShowAll boolean
---@field timeMod number
---@field points table
---@field index? number
---@field type? string
-- Create a new Aura class -- Create a new Aura class
---@class Aura ---@class Aura
---@field aura AuraAuraData
local Aura = {} local Aura = {}
function Aura:__index(k) function Aura:__index(k)
@ -116,8 +138,8 @@ end
local foodAndDrinkStrings = { local foodAndDrinkStrings = {
[5] = "Refreshment", [5] = "Refreshment",
[1] = MINIMAP_TRACKING_VENDOR_FOOD, -- Food & Drink [1] = MINIMAP_TRACKING_VENDOR_FOOD, -- Food & Drink
[2] = POWER_TYPE_FOOD, -- Food [2] = POWER_TYPE_FOOD, -- Food
[4] = TUTORIAL_TITLE12, -- Drink [4] = TUTORIAL_TITLE12, -- Drink
} }
---@type { [number]: boolean } ---@type { [number]: boolean }
@ -155,7 +177,7 @@ function Aura:CreateFromUnitAuraInfo(unitAuraInfo)
maxCharges maxCharges
]] ]]
-- --
--print(unitAuraInfo.name, unitAuraInfo.sourceUnit, unitAuraInfo.expirationTime, unitAuraInfo.duration)
self.aura = { self.aura = {
auraInstanceID = unitAuraInfo.auraInstanceID, auraInstanceID = unitAuraInfo.auraInstanceID,
canApplyAura = unitAuraInfo.canApplyAura, canApplyAura = unitAuraInfo.canApplyAura,

@ -1,10 +1,16 @@
---@type Tinkr, Bastion ---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
---@alias auraInstanceId integer
---@class AuraInstanceTable
---@field [spellId] { [auraInstanceId]: Aura }
-- Create a new AuraTable class -- Create a new AuraTable class
---@class AuraTable ---@class AuraTable
---@field unit Unit ---@field unit Unit
---@field playerAuras table<number, table<number, Aura>> ---@field playerAuras AuraInstanceTable
---@field auras AuraInstanceTable
local AuraTable = {} local AuraTable = {}
AuraTable.__index = AuraTable AuraTable.__index = AuraTable
@ -275,7 +281,7 @@ function AuraTable:Find(spell)
local aurasub = auras[spell:GetID()] local aurasub = auras[spell:GetID()]
if not aurasub then if not aurasub then
return Bastion.Aura:New() return self:FindMy(spell)
end end
for k, a in pairs(aurasub) do for k, a in pairs(aurasub) do
@ -321,14 +327,18 @@ end
-- Check if the unit has a specific aura -- Check if the unit has a specific aura
---@param spell Spell ---@param spell Spell
---@param source Unit ---@param source "any" | Unit
---@return Aura ---@return Aura
function AuraTable:FindFrom(spell, source) function AuraTable:FindFrom(spell, source)
if type(source) == "string" or source == "any" then
return self:FindAny(spell)
end
local auras = self:GetUnitAuras() local auras = self:GetUnitAuras()
local aurasub = auras[spell:GetID()] local aurasub = auras[spell:GetID()]
if not aurasub then if not aurasub then
return Bastion.Aura:New() return self:FindMy(spell)
end end
for k, a in pairs(aurasub) do for k, a in pairs(aurasub) do

@ -1,10 +1,9 @@
---@type Tinkr, Bastion ---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
-- Define a Cacheable class
---@class Cacheable<V>: { value: V, cache: Cache, callback?: fun(): V }
---@class Cacheable<V> ---@class Cacheable
---@field cache? Cache
local Cacheable = { local Cacheable = {
cache = nil, cache = nil,
callback = nil, callback = nil,
@ -33,15 +32,15 @@ function Cacheable:__index(k)
end end
-- When the object is accessed return the value -- When the object is accessed return the value
---@return string
function Cacheable:__tostring() function Cacheable:__tostring()
return "Bastion.__Cacheable(" .. tostring(self.value) .. ")" return "Bastion.__Cacheable(" .. tostring(self.value) .. ")"
end end
-- Create -- Create
---@generic V : Cacheable, V ---@generic V
---@param value V ---@param value V
---@param cb fun(): V ---@param cb fun(): V
---@return V
function Cacheable:New(value, cb) function Cacheable:New(value, cb)
local self = setmetatable({}, Cacheable) local self = setmetatable({}, Cacheable)
@ -55,7 +54,6 @@ function Cacheable:New(value, cb)
end end
-- Try to update the value -- Try to update the value
---@return nil
function Cacheable:TryUpdate() function Cacheable:TryUpdate()
if self.cache:IsCached("value") then if self.cache:IsCached("value") then
self.value = self.callback() self.value = self.callback()
@ -63,7 +61,6 @@ function Cacheable:TryUpdate()
end end
-- Update the value -- Update the value
---@return nil
function Cacheable:Update() function Cacheable:Update()
self.value = self.callback() self.value = self.callback()
end end

@ -1,8 +1,11 @@
---@type Tinkr, Bastion ---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
---@alias itemId integer
-- Create a new ItemBook class -- Create a new ItemBook class
---@class ItemBook ---@class ItemBook
---@field items table<itemId, Item>
local ItemBook = {} local ItemBook = {}
ItemBook.__index = ItemBook ItemBook.__index = ItemBook

@ -31,7 +31,7 @@ end
-- Create -- Create
---@generic V ---@generic V
---@param value V ---@param value V
---@param cb function ---@param cb fun(): V
---@return V ---@return V
function Refreshable:New(value, cb) function Refreshable:New(value, cb)
local self = setmetatable({}, Refreshable) local self = setmetatable({}, Refreshable)

@ -12,6 +12,8 @@ local Tinkr, Bastion = ...
---@field lastCastAttempt number | false ---@field lastCastAttempt number | false
---@field target Unit | false ---@field target Unit | false
---@field damageFormula false | fun(self:Spell):number ---@field damageFormula false | fun(self:Spell):number
---@field overrides { [spellId]: fun(self: Spell): Spell }
---@field auras { [spellId]: { spell: Spell, source?: Unit, target?: Unit, lastApplied: number } }
local Spell = { local Spell = {
CastableIfFunc = false, CastableIfFunc = false,
PreCastFunc = false, PreCastFunc = false,
@ -21,8 +23,17 @@ local Spell = {
wasLooking = false, wasLooking = false,
lastCastAt = false, lastCastAt = false,
conditions = {}, conditions = {},
buffs = {}, auras = {},
debuffs = {}, overrides = {},
traits = {
cast = {
moving = true,
dead = false,
global = false,
casting = false,
channeling = false,
},
},
target = false, target = false,
release_at = false, release_at = false,
damageFormula = false, damageFormula = false,
@ -88,6 +99,14 @@ function Spell:GetID(ignoreOverride)
return ignoreOverride and self.spellID or self:IsOverridden() and self:OverrideSpellID() or self.spellID return ignoreOverride and self.spellID or self:IsOverridden() and self:OverrideSpellID() or self.spellID
end end
function Spell:SetTraits(traits)
if traits.cast and type(traits.cast) == "table" then
for k, v in pairs(traits.cast) do
self.traits.cast[k] = v
end
end
end
-- Add post cast func -- Add post cast func
---@param func fun(self:Spell) ---@param func fun(self:Spell)
---@return Spell ---@return Spell
@ -97,10 +116,9 @@ function Spell:PostCast(func)
end end
-- Get the spells name -- Get the spells name
---@param byId? boolean
---@return string ---@return string
function Spell:GetName(byId) function Spell:GetName()
return select(1, GetSpellInfo((byId ~= nil and byId) and self:GetID() or self:GetID())) return Bastion.Globals.SpellName[self:GetID()] or select(1, GetSpellInfo(self:GetID()))
end end
-- Get the spells icon -- Get the spells icon
@ -113,7 +131,7 @@ end
---@param byId? boolean ---@param byId? boolean
---@return number ---@return number
function Spell:GetCooldown(byId) function Spell:GetCooldown(byId)
return select(2, GetSpellCooldown((byId ~= nil and byId) and self:GetID() or self:GetName(byId))) return select(2, GetSpellCooldown(byId and self:GetID() or self:GetName()))
end end
-- Return the castable function -- Return the castable function
@ -135,7 +153,7 @@ end
---@param byId? boolean ---@param byId? boolean
---@return number ---@return number
function Spell:GetCooldownRemaining(byId) function Spell:GetCooldownRemaining(byId)
local start, duration = GetSpellCooldown((byId ~= nil and byId) and self:GetID() or self:GetName()) local start, duration = GetSpellCooldown(byId and self:GetID() or self:GetName())
if start == 0 then if start == 0 then
return 0 return 0
end end
@ -162,6 +180,12 @@ function Spell:ClearCastableFunction()
return self return self
end end
---@param spell Spell
---@param func fun(self: Spell): boolean
function Spell:AddOverrideSpell(spell, func)
self.overrides[spell:GetID()] = func
end
-- Cast the spell -- Cast the spell
---@param unit Unit ---@param unit Unit
---@param condition? string|fun(self:Spell):boolean ---@param condition? string|fun(self:Spell):boolean
@ -261,10 +285,9 @@ end
---@param includeOverrides? boolean ---@param includeOverrides? boolean
---@return boolean ---@return boolean
function Spell:IsKnown(includeOverrides) function Spell:IsKnown(includeOverrides)
includeOverrides = includeOverrides ~= nil and includeOverrides or true local isKnown = includeOverrides and IsSpellKnownOrOverridesKnown(self:GetID()) or IsSpellKnown(self:GetID()) or
local isKnown = includeOverrides and IsSpellKnownOrOverridesKnown(self:GetID()) or IsSpellKnown(self:GetID()) IsPlayerSpell(self:GetID())
local isPlayerSpell = IsPlayerSpell(self:GetID()) return isKnown
return isKnown or isPlayerSpell
end end
-- Check if the spell is on cooldown -- Check if the spell is on cooldown
@ -292,13 +315,27 @@ end
---@param override? boolean ---@param override? boolean
---@return boolean ---@return boolean
function Spell:IsKnownAndUsable(override) function Spell:IsKnownAndUsable(override)
override = override ~= nil and override or false
return self:IsKnown(override) and not self:IsOnCooldown() and self:IsUsable(override and false or true) return self:IsKnown(override) and not self:IsOnCooldown() and self:IsUsable(override and false or true)
end end
function Spell:EvaluateTraits()
local player = Bastion.UnitManager["player"]
return (
(self.traits.cast.dead or player:IsAlive()) and
(self.traits.cast.moving or not player:IsMoving()) and
(self.traits.cast.global or player:GetGCD() == 0) and
(self.traits.cast.casting or not player:IsCasting()) and
(self.traits.cast.channeling or not player:IsChanneling())
)
end
-- Check if the spell is castable -- Check if the spell is castable
---@return boolean ---@return boolean
function Spell:Castable() function Spell:Castable()
if not self:EvaluateTraits() then
return true
end
if self:GetCastableFunction() then if self:GetCastableFunction() then
return self:GetCastableFunction()(self) return self:GetCastableFunction()(self)
end end
@ -615,10 +652,49 @@ function Spell:Damage()
end end
end end
---@param unit Unit ---@param target Unit
---@param source? "any" | Unit
function Spell:GetAura(target, source)
if type(source) == "nil" then
source = Bastion.UnitManager["player"]
end
return target:GetAuras():FindFrom(self, source)
end
---@param spell Spell
---@param source? Unit
---@param target? Unit
function Spell:TrackAura(spell, source, target)
self.auras[spell:GetID()] = {
spell = spell,
source = source,
target = target,
lastApplied = 0,
}
end
---@param aura Spell
---@param source? Unit
---@param target? Unit
function Spell:CheckAuraStatus(aura, source, target)
for id, trackedAura in pairs(self.auras) do
if aura:GetID() == id then
return true
end
end
return false
end
---@param spell Spell
---@param source? Unit ---@param source? Unit
function Spell:GetAura(unit, source) ---@param target? Unit
return source and unit:GetAuras():FindFrom(self, source) or unit:GetAuras():FindAny(self) function Spell:UpdateAura(spell, source, target)
if not self.auras[spell:GetID()] then
self:TrackAura(spell, source, target)
end
self.auras[spell:GetID()].lastApplied = GetTime()
end end
return Spell return Spell

@ -4,6 +4,7 @@ local Tinkr, Bastion = ...
-- Create a new SpellBook class -- Create a new SpellBook class
---@class SpellBook ---@class SpellBook
---@field spells table<number, Spell> ---@field spells table<number, Spell>
---@field auras { [spellId]: { [spellId]: { spell: Spell, source?: Unit, target?: Unit, lastApplied: number } } }
local SpellBook = {} local SpellBook = {}
SpellBook.__index = SpellBook SpellBook.__index = SpellBook
@ -43,7 +44,7 @@ function SpellBook:GetSpell(id)
return self.spells[id] return self.spells[id]
end end
---@param ... number[] ---@param ... integer
---@return Spell, ... Spell ---@return Spell, ... Spell
function SpellBook:GetSpells(...) function SpellBook:GetSpells(...)
local spells = {} local spells = {}
@ -54,7 +55,20 @@ function SpellBook:GetSpells(...)
return unpack(spells) return unpack(spells)
end end
---@param ... number[] ---@param aura Spell
---@return Spell[]
function SpellBook:GetAuraSpells(aura)
local spells = {}
for _, spell in pairs(self.spells) do
if spell:CheckAuraStatus(aura) then
table.insert(spells, spell)
end
end
return spells
end
---@param ... integer
---@return List ---@return List
function SpellBook:GetList(...) function SpellBook:GetList(...)
local spells = {} local spells = {}
@ -73,9 +87,16 @@ function SpellBook:GetSpellByName(name)
end end
---@param id integer ---@param id integer
---@return Spell
function SpellBook:GetIfRegistered(id) function SpellBook:GetIfRegistered(id)
return self.spells[id] or self.spells[FindSpellOverrideByID(id)] if self.spells[id] then
return self.spells[id]
end
if self.spells[FindSpellOverrideByID(id)] then
return self.spells[FindSpellOverrideByID(id)]
end
return false
end end
return SpellBook return SpellBook

@ -1,22 +1,27 @@
---@type Tinkr, Bastion ---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
local Cache = Bastion.Caches
local Player = Bastion.UnitManager:Get("player") local Player = Bastion.UnitManager:Get("player")
local Target = Bastion.UnitManager:Get("target") local Target = Bastion.UnitManager:Get("target")
if not Bastion.Globals.UnitInfo then
Bastion.Globals.UnitInfo = Bastion.Cache:New()
end
local Cache = Bastion.Globals.UnitInfo
--- An attempt to integrate HeroLib TTD timers. --- An attempt to integrate HeroLib TTD timers.
---@class TimeToDie ---@class TimeToDie
local TimeToDie = { local TimeToDie = {
Settings = { Settings = {
-- Refresh time (seconds) : min=0.1, max=2, default = 0.1 -- Refresh time (seconds) : min=0.1, max=2, default = 0.1
Refresh = 0.1, Refresh = 0.5,
-- History time (seconds) : min=5, max=120, default = 10+0.4 -- History time (seconds) : min=5, max=120, default = 10+0.4
HistoryTime = 10 + 0.4, HistoryTime = 10 + 0.4,
-- Max history count : min=20, max=500, default = 100 -- Max history count : min=20, max=500, default = 100
HistoryCount = 100 HistoryCount = 100
}, },
Cache = {}, -- A cache of unused { time, value } tables to reduce garbage due to table creation Cache = {}, -- A cache of unused { time, value } tables to reduce garbage due to table creation
---@type table<string, {[1]: {[1]: number[], [2]: number}, [2]: number }> ---@type table<string, {[1]: {[1]: {[1]: number, [2]: number}, [2]: number}, [2]: number }>
Units = {}, -- Used to track units, Units = {}, -- Used to track units,
---@type table<string, boolean> ---@type table<string, boolean>
ExistingUnits = {}, -- Used to track GUIDs of currently existing units (to be compared with tracked units) ExistingUnits = {}, -- Used to track GUIDs of currently existing units (to be compared with tracked units)
@ -30,12 +35,12 @@ end
function TimeToDie:Refresh() function TimeToDie:Refresh()
local currentTime = GetTime() local currentTime = GetTime()
local historyCount = self.Settings.HistoryCount local historyCount = TimeToDie.Settings.HistoryCount
local historyTime = self.Settings.HistoryTime local historyTime = TimeToDie.Settings.HistoryTime
local ttdCache = self.Cache local ttdCache = TimeToDie.Cache
local iterableUnits = self:IterableUnits() local iterableUnits = TimeToDie:IterableUnits()
local units = self.Units local units = TimeToDie.Units
local existingUnits = self.ExistingUnits local existingUnits = TimeToDie.ExistingUnits
wipe(existingUnits) wipe(existingUnits)
@ -72,7 +77,7 @@ function TimeToDie:Refresh()
value[1] = time value[1] = time
value[2] = healthPercentage value[2] = healthPercentage
end end
tableinsert(values, 1, value) table.insert(values, 1, value)
local n = #values local n = #values
-- Delete values that are no longer valid -- Delete values that are no longer valid
while (n > historyCount) or (time - values[n][1] > historyTime) do while (n > historyCount) or (time - values[n][1] > historyTime) do
@ -268,7 +273,7 @@ function TimeToDie.FilteredFightRemains(enemies, operator, value, checkIfValid,
return false return false
end end
return Utils.CompareThis(operator, fightRemains, value) or false return Bastion.Utils.CompareThis(operator, fightRemains, value) or false
end end
-- Returns if the current boss fight length meets the requirements, 11111 if not a boss fight. -- Returns if the current boss fight length meets the requirements, 11111 if not a boss fight.

@ -518,7 +518,7 @@ local losFlag = bit.bor(0x10)
-- Check if the unit can see another unit -- Check if the unit can see another unit
---@param targetUnit Unit ---@param targetUnit Unit
---@return boolean ---@return boolean
function Unit:CanSee2(targetUnit) function Unit:CanSee(targetUnit)
local npcId = targetUnit:GetID() local npcId = targetUnit:GetID()
if npcId and losBlacklist[npcId] then if npcId and losBlacklist[npcId] then
return true return true
@ -554,22 +554,29 @@ function Unit:GetHitSpherePointFor(destination)
return contactPoint return contactPoint
end end
---@param destinationUnit Unit ---@param unit Unit
function Unit:CanSee(destinationUnit) function Unit:CanSee2(unit)
local src = self:GetPosition() local ax, ay, az = ObjectPosition(self:GetOMToken())
local dst = destinationUnit:GetPosition() local ah = ObjectHeight(self:GetOMToken())
if ObjectType(self:GetOMToken()) == 6 then local attx, atty, attz = GetUnitAttachmentPosition(unit:GetOMToken(), 34)
src.z = src.z + ObjectHeight(self:GetOMToken())
else if not attx or not ax then
dst = self:GetHitSpherePointFor(destinationUnit) return false
end end
if (src.x == 0 and src.y == 0 and src.z == 0) or (dst.x == 0 and dst.y == 0 and dst.z == 0) then if not ah then
return false
end
if (ax == 0 and ay == 0 and az == 0) or (attx == 0 and atty == 0 and attz == 0) then
return true return true
end end
local x, y, z = TraceLine(src.x, src.y, src.z, dst.x, dst.y, dst.z, losFlag) if not attx or not ax then
return false
end
local x, y, z = TraceLine(ax, ay, az + ah, attx, atty, attz, losFlag)
if x ~= 0 or y ~= 0 or z ~= 0 then if x ~= 0 or y ~= 0 or z ~= 0 then
return false return false
else else
@ -904,19 +911,20 @@ end
---@return number ---@return number
function Unit:GetMeleeBoost() function Unit:GetMeleeBoost()
local meleeBoost = 0
if IsPlayerSpell(197524) then if IsPlayerSpell(197524) then
local astralNode = C_Traits.GetNodeInfo(C_ClassTalents.GetActiveConfigID() or 0, 82210) local astralInfluenceNode = C_Traits.GetNodeInfo(C_ClassTalents.GetActiveConfigID() or 0, 82210)
local currentSpec = select(1, GetSpecializationInfo(GetSpecialization())) local currentSpec = select(1, GetSpecializationInfo(GetSpecialization()))
if astralNode then if astralInfluenceNode then
local currentRank = astralNode.activeRank local currentRank = astralInfluenceNode.activeRank
if currentRank > 0 then if currentRank > 0 then
return ((currentSpec == 103 or currentSpec == 104) and 1 or 3) + (currentRank == 2 and 2 or 0) meleeBoost = ((currentSpec == 103 or currentSpec == 104) and 1 or 3) + (currentRank == 2 and 2 or 0)
end end
end end
elseif IsPlayerSpell(196924) then elseif IsPlayerSpell(196924) then
return 3 meleeBoost = 3
end end
return 0 return meleeBoost
end end
function Unit:GetModelId() function Unit:GetModelId()
@ -956,13 +964,12 @@ function Unit:InMelee(unit)
end end
-- Get object id -- Get object id
---@return number
function Unit:GetID() function Unit:GetID()
if self.id then if self.id then
return self.id --[[ @as number ]] return self.id
end end
self.id = ObjectID(self:GetOMToken()) self.id = ObjectID(self:GetOMToken())
return self.id --[[ @as number ]] return self.id or 0
end end
-- In party -- In party
@ -1110,7 +1117,6 @@ end
-- Set last combat time -- Set last combat time
---@param time number ---@param time number
---@return nil
function Unit:SetLastCombatTime(time) function Unit:SetLastCombatTime(time)
self.last_combat_time = time self.last_combat_time = time
end end
@ -1524,7 +1530,7 @@ local dummyUnits = {
function Unit:IsDummy() function Unit:IsDummy()
local npcId = self:GetID() local npcId = self:GetID()
return npcId >= 0 and dummyUnits[npcId] == true return npcId and npcId >= 0 and dummyUnits[npcId] == true or false
end end
---@param npcId? number ---@param npcId? number
@ -1567,7 +1573,7 @@ end
function Unit:TimeToX(percentage, minSamples) function Unit:TimeToX(percentage, minSamples)
if self:IsDummy() then return 6666 end if self:IsDummy() then return 6666 end
if self:IsPlayer() and Player:CanAttack(self) then return 25 end if self:IsPlayer() and Bastion.UnitManager:Get("player"):CanAttack(self) then return 25 end
local seconds = 8888 local seconds = 8888
local unitGuid = self:GetGUID() local unitGuid = self:GetGUID()
if not unitGuid then if not unitGuid then
@ -1624,7 +1630,8 @@ function Unit:TimeToDie2(minSamples)
minSamples = minSamples or 3 minSamples = minSamples or 3
---@type {TTD: {[number]: number}} ---@type {TTD: {[number]: number}}
local unitInfo = Cache.UnitInfo:IsCached(unitGuid) and Cache.UnitInfo:Get(unitGuid) or {} local unitInfo = Bastion.Globals.UnitInfo:IsCached(unitGuid) and
Bastion.Globals.UnitInfo:Get(unitGuid) or {}
local ttd = unitInfo.TTD local ttd = unitInfo.TTD
if not ttd then if not ttd then
@ -1635,7 +1642,7 @@ function Unit:TimeToDie2(minSamples)
ttd[minSamples] = self:TimeToX(self:SpecialTTDPercentage(self:GetID()), minSamples) ttd[minSamples] = self:TimeToX(self:SpecialTTDPercentage(self:GetID()), minSamples)
end end
Bastion.Caches.UnitInfo:Set(unitGuid, unitInfo, .5) Bastion.Globals.UnitInfo:Set(unitGuid, unitInfo, .5)
return ttd[minSamples] return ttd[minSamples]
end end

@ -5,12 +5,14 @@ local ObjectManager = Tinkr.Util.ObjectManager
local Unit = Bastion.Unit local Unit = Bastion.Unit
---@class CacheableUnit<U> : Cacheable<Unit> ---@class UnitManager.CustomUnit
---@field unit Cacheable | Unit
---@field cb fun(): Unit
-- Create a new UnitManager class -- Create a new UnitManager class
---@class UnitManager : { [UnitId]: Unit } ---@class UnitManager : { [UnitId]: Unit }
---@field units table<string, Unit> ---@field units table<string, Unit>
---@field customUnits table<string, { unit: Cacheable<Unit>, cb: fun(unit: Unit): Unit }> ---@field customUnits table<string, UnitManager.CustomUnit>
---@field objects table<string, Unit> ---@field objects table<string, Unit>
---@field cache Cache ---@field cache Cache
local UnitManager = { local UnitManager = {
@ -107,7 +109,7 @@ function UnitManager:Get(token)
end end
-- Get a unit by guid -- Get a unit by guid
---@param guid string ---@param guid string | WowGameObject
---@return Unit ---@return Unit
function UnitManager:GetObject(guid) function UnitManager:GetObject(guid)
return self.objects[guid] return self.objects[guid]
@ -120,13 +122,12 @@ function UnitManager:SetObject(unit)
end end
-- Create a custom unit and cache it for .5 seconds -- Create a custom unit and cache it for .5 seconds
---@generic V :Unit
---@param token string ---@param token string
---@param cb fun(unit: Unit?): Unit ---@param cb fun(): Unit
---@return Unit
function UnitManager:CreateCustomUnit(token, cb) function UnitManager:CreateCustomUnit(token, cb)
local unit = cb() local unit = cb()
local cachedUnit = Bastion.Cacheable:New(unit, cb) local cachedUnit = Bastion.Cacheable:New(unit, cb)
if unit == nil then if unit == nil then
error("UnitManager:CreateCustomUnit - Invalid unit: " .. token) error("UnitManager:CreateCustomUnit - Invalid unit: " .. token)
end end

@ -127,9 +127,6 @@ Bastion.Notifications = Bastion.NotificationsList:New()
Bastion.Config = Bastion.require("Config") Bastion.Config = Bastion.require("Config")
Bastion.TimeToDie = Bastion.require("TimeToDie") Bastion.TimeToDie = Bastion.require("TimeToDie")
Bastion.Caches = {
UnitInfo = Bastion.Cache:New()
}
---@enum (key) CompareThisTable ---@enum (key) CompareThisTable
local compareThisTable = { local compareThisTable = {
@ -183,6 +180,9 @@ end)
local pguid = UnitGUID("player") local pguid = UnitGUID("player")
local missed = {} local missed = {}
---@class Bastion.Globals.SpellName : { [spellId]: string }
Bastion.Globals.SpellName = {}
Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function() Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
local args = { CombatLogGetCurrentEventInfo() } local args = { CombatLogGetCurrentEventInfo() }
@ -193,6 +193,12 @@ Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", fun
local destGUID = args[8] local destGUID = args[8]
---@type number ---@type number
local spellID = args[12] local spellID = args[12]
---@type string
local spellName = args[13]
if not Bastion.Globals.SpellName[spellID] or Bastion.Globals.SpellName[spellID] ~= spellName then
Bastion.Globals.SpellName[spellID] = spellName
end
-- if sourceGUID == pguid then -- if sourceGUID == pguid then
-- local args = { CombatLogGetCurrentEventInfo() } -- local args = { CombatLogGetCurrentEventInfo() }

Loading…
Cancel
Save