From a972a0c372bb2aee9dba8608aa3a77be22bfc73f Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 2 Nov 2023 02:32:50 -0500 Subject: [PATCH] Updates. --- src/APL/APL.lua | 8 +++---- src/Aura/Aura.lua | 11 +++------ src/AuraTable/AuraTable.lua | 4 +++- src/Module/Module.lua | 3 +++ src/SpellBook/SpellBook.lua | 20 +++++++++++++++- src/Unit/Unit.lua | 23 ++++++++++++------ src/UnitManager/UnitManager.lua | 42 ++++++++++----------------------- src/_bastion.lua | 2 ++ 8 files changed, 63 insertions(+), 50 deletions(-) diff --git a/src/APL/APL.lua b/src/APL/APL.lua index 539a76c..19a71d6 100644 --- a/src/APL/APL.lua +++ b/src/APL/APL.lua @@ -1,12 +1,12 @@ -- Create an APL trait for the APL class ---@class APLTrait ----@field cb fun(actor?: APLActor):boolean +---@field cb fun(actor?: APLActorTable):boolean ---@field lastcall number local APLTrait = {} APLTrait.__index = APLTrait -- Constructor ----@param cb fun(actor?: APLActor):boolean +---@param cb fun(actor?: APLActorTable):boolean ---@return APLTrait function APLTrait:New(cb) local self = setmetatable({}, APLTrait) @@ -18,7 +18,7 @@ function APLTrait:New(cb) end -- Evaulate the APL trait ----@param actor? APLActor +---@param actor? APLActorTable ---@return boolean function APLTrait:Evaluate(actor) if GetTime() - self.lastcall > 0.1 then @@ -80,7 +80,7 @@ end ---@return boolean function APLActor:Evaluate() for _, trait in ipairs(self.traits) do - if not trait:Evaluate(self) then + if not trait:Evaluate(self:GetActor()) then return false end end diff --git a/src/Aura/Aura.lua b/src/Aura/Aura.lua index c062f44..33ad2ae 100644 --- a/src/Aura/Aura.lua +++ b/src/Aura/Aura.lua @@ -116,7 +116,6 @@ local foodAndDrinkStrings = { [5] = "Refreshment", [1] = MINIMAP_TRACKING_VENDOR_FOOD, -- Food & Drink [2] = POWER_TYPE_FOOD, -- Food - [3] = EMOTE36_TOKEN, -- DRINK [4] = TUTORIAL_TITLE12, -- Drink } @@ -128,17 +127,13 @@ function Aura:IsFoodOrDrink() if cachedFoodAndDrinkIDs[self.aura.spellId] then return cachedFoodAndDrinkIDs[self.aura.spellId] else - local auraName = self.aura.name - if auraName then - print("Aura Name", auraName) + if self.aura.name then for i = 1, #foodAndDrinkStrings do - if auraName:upper():find(foodAndDrinkStrings[i]:upper()) then + if self.aura.name:find(foodAndDrinkStrings[i]) then cachedFoodAndDrinkIDs[self.aura.spellId] = true return true end end - else - print("No Aura Name", self.aura.spellId) end end end @@ -260,7 +255,7 @@ end -- Get the auras remaining time ---@return number function Aura:GetRemainingTime() - local remainingTime = self.aura.expirationTime - GetTime() + local remainingTime = self:GetExpirationTime() - GetTime() if remainingTime < 0 then remainingTime = 0 diff --git a/src/AuraTable/AuraTable.lua b/src/AuraTable/AuraTable.lua index 67a1c94..9ef5b9d 100644 --- a/src/AuraTable/AuraTable.lua +++ b/src/AuraTable/AuraTable.lua @@ -4,6 +4,7 @@ local Tinkr, Bastion = ... -- Create a new AuraTable class ---@class AuraTable ---@field unit Unit +---@field playerAuras table> local AuraTable = {} AuraTable.__index = AuraTable @@ -69,6 +70,7 @@ function AuraTable:OnUpdate(auras) self:RemoveInstanceID(removedAuras[i]) end end + Bastion.EventManager:TriggerEvent("AURAS_UPDATED") end ---@param instanceID number @@ -207,6 +209,7 @@ function AuraTable:Update() -- self.auras = self.auras -- self.playerAuras = self.playerAuras + Bastion.EventManager:TriggerEvent("AURAS_UPDATED_FULL") end -- Get a units auras @@ -234,7 +237,6 @@ function AuraTable:GetUnitAuras() end -- Get a units auras ----@return table function AuraTable:GetMyUnitAuras() if not self.did then self.did = true diff --git a/src/Module/Module.lua b/src/Module/Module.lua index e7b7919..8f0ca29 100644 --- a/src/Module/Module.lua +++ b/src/Module/Module.lua @@ -1,6 +1,9 @@ -- Create a module class for a bastion module ---@class Module +---@field name string +---@field enabled boolean +---@field synced function[] local Module = {} Module.__index = Module diff --git a/src/SpellBook/SpellBook.lua b/src/SpellBook/SpellBook.lua index d946e2b..a525998 100644 --- a/src/SpellBook/SpellBook.lua +++ b/src/SpellBook/SpellBook.lua @@ -1,3 +1,4 @@ +---@type Tinkr, Bastion local Tinkr, Bastion = ... -- Create a new SpellBook class @@ -11,16 +12,33 @@ SpellBook.__index = SpellBook function SpellBook:New() local self = setmetatable({}, SpellBook) self.spells = {} + --[[ Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", function(...) + self:SpellCastSucceeded(...) + end) ]] return self end +--[[ function SpellBook:SpellCastSucceeded(...) + local unit, castGUID, spellId = ... + if self.spells[spellId] then + self.spells[spellId].lastCastAt = GetTime() + end +end ]] + -- Get a spell from the spellbook ---@return Spell function SpellBook:GetSpell(id) + local override = FindSpellOverrideByID(id) if self.spells[id] == nil then self.spells[id] = Bastion.Spell:New(id) end + if override and override ~= id then + if self.spells[override] == nil then + self.spells[override] = Bastion.Spell:New(override) + end + end + return self.spells[id] end @@ -55,7 +73,7 @@ end ---@return Spell function SpellBook:GetIfRegistered(id) - return self.spells[id] + return self.spells[id] or self.spells[FindSpellOverrideByID(id)] end return SpellBook diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index b424137..6c08d9b 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -6,10 +6,10 @@ local Tinkr, Bastion = ... ---@field id boolean | number ---@field ttd_ticker false | cbObject ---@field unit TinkrObjectReference +---@field aura_table AuraTable | nil local Unit = { ---@type Cache cache = nil, - ---@type AuraTable aura_table = nil, ---@type UnitId | WowGameObject unit = nil, @@ -148,7 +148,7 @@ function Unit:GetPowerType() end -- Get the units power ----@param powerType number | nil +---@param powerType? number ---@return number function Unit:GetPower(powerType) local powerType = powerType or self:GetPowerType() @@ -156,7 +156,7 @@ function Unit:GetPower(powerType) end -- Get the units max power ----@param powerType number | nil +---@param powerType? number ---@return number function Unit:GetMaxPower(powerType) local powerType = powerType or self:GetPowerType() @@ -504,7 +504,7 @@ function Unit:IsInterruptible() end -- Check if unit is interruptible ----@param percent number +---@param percent? number ---@param ignoreInterruptible? boolean ---@return boolean function Unit:IsInterruptibleAt(percent, ignoreInterruptible) @@ -609,7 +609,7 @@ function Unit:IsMovingAtAll() return ObjectMovementFlag(self:GetOMToken()) ~= 0 end ----@param unit Unit | nil +---@param unit? Unit ---@return number function Unit:GetComboPoints(unit) if Tinkr.classic or Tinkr.era then @@ -618,7 +618,7 @@ function Unit:GetComboPoints(unit) end return GetComboPoints(self:GetOMToken(), unit:GetOMToken()) end - return UnitPower(self:GetOMToken(), 4) + return UnitPower(self:GetOMToken(), Enum.PowerType.ComboPoints) end ---@return number @@ -960,7 +960,16 @@ function Unit:IsStealthed() local Shadowmeld = Bastion.Globals.SpellBook:GetSpell(58984) local Sepsis = Bastion.Globals.SpellBook:GetSpell(328305) - return self:GetAuras():FindAny(Stealth):IsUp() or self:GetAuras():FindAny(ShadowDance):IsUp() + local stealthList = Bastion.List:New({ + Stealth, + Vanish, + ShadowDance, + Subterfuge, + Shadowmeld, + Sepsis, + }) + + return self:GetAuras():FindAnyOf(stealthList):IsUp() end -- Get unit swing timers diff --git a/src/UnitManager/UnitManager.lua b/src/UnitManager/UnitManager.lua index cc48142..f31ae03 100644 --- a/src/UnitManager/UnitManager.lua +++ b/src/UnitManager/UnitManager.lua @@ -1,3 +1,4 @@ +---@type Tinkr, Bastion local Tinkr, Bastion = ... local ObjectManager = Tinkr.Util.ObjectManager @@ -10,19 +11,19 @@ local UnitManager = { units = {}, customUnits = {}, objects = {}, - cache = {} + cache = {}, } function UnitManager:__index(k) - if k == 'none' then - return self:Get('none') + if k == "none" then + return self:Get("none") end if UnitManager[k] then return UnitManager[k] end - local k = k or 'none' + local k = k or "none" -- if custom unit exists, return it it's cache expired return a new one if self.customUnits[k] then @@ -52,7 +53,7 @@ function UnitManager:__index(k) end end - return self.objects['none'] + return self.objects["none"] end -- Constructor @@ -65,7 +66,6 @@ function UnitManager:New() return self end - -- Get or create a unit ---@param token string ---@return Unit @@ -77,8 +77,8 @@ function UnitManager:Get(token) local tguid = ObjectGUID(token) if tguid and self.objects[tguid] == nil then - if token == 'none' then - self.objects['none'] = Unit:New() + if token == "none" then + self.objects["none"] = Unit:New() else self.objects[tguid] = Unit:New(Object(tguid)) end @@ -88,8 +88,8 @@ function UnitManager:Get(token) local tguid = ObjectGUID(token) or "none" if self.objects[tguid] == nil then - if token == 'none' then - self.objects['none'] = Unit:New() + if token == "none" then + self.objects["none"] = Unit:New() else self.objects[tguid] = Unit:New(Object(tguid)) end @@ -127,7 +127,7 @@ function UnitManager:CreateCustomUnit(token, cb) if self.customUnits[token] == nil then self.customUnits[token] = { unit = cachedUnit, - cb = cb + cb = cb, } end @@ -303,15 +303,7 @@ function UnitManager:FindFriendsCentroid(radius, range) return unit:GetPosition() end - local _, _, z = TraceLine( - centroid.x, - centroid.y, - centroid.z + 5, - centroid.x, - centroid.y, - centroid.z - 5, - 0x100151 - ) + local _, _, z = TraceLine(centroid.x, centroid.y, centroid.z + 5, centroid.x, centroid.y, centroid.z - 5, 0x100151) centroid.z = z + 0.01 @@ -342,15 +334,7 @@ function UnitManager:FindEnemiesCentroid(radius, range) return unit:GetPosition() end - local _, _, z = TraceLine( - centroid.x, - centroid.y, - centroid.z + 5, - centroid.x, - centroid.y, - centroid.z - 5, - 0x100151 - ) + local _, _, z = TraceLine(centroid.x, centroid.y, centroid.z + 5, centroid.x, centroid.y, centroid.z - 5, 0x100151) centroid.z = z + 0.01 diff --git a/src/_bastion.lua b/src/_bastion.lua index 085f50e..32a7d6a 100644 --- a/src/_bastion.lua +++ b/src/_bastion.lua @@ -149,11 +149,13 @@ Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New() Bastion.Notifications = Bastion.NotificationsList:New() local LIBRARIES = {} +---@type Module[] local MODULES = {} Bastion.Enabled = false Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_AURA", function(unit, auras) + ---@type Unit | nil local u = Bastion.UnitManager[unit] if u then