main
ck 1 year ago
parent aa34c9e647
commit a972a0c372
  1. 8
      src/APL/APL.lua
  2. 11
      src/Aura/Aura.lua
  3. 4
      src/AuraTable/AuraTable.lua
  4. 3
      src/Module/Module.lua
  5. 20
      src/SpellBook/SpellBook.lua
  6. 23
      src/Unit/Unit.lua
  7. 42
      src/UnitManager/UnitManager.lua
  8. 2
      src/_bastion.lua

@ -1,12 +1,12 @@
-- Create an APL trait for the APL class -- Create an APL trait for the APL class
---@class APLTrait ---@class APLTrait
---@field cb fun(actor?: APLActor):boolean ---@field cb fun(actor?: APLActorTable):boolean
---@field lastcall number ---@field lastcall number
local APLTrait = {} local APLTrait = {}
APLTrait.__index = APLTrait APLTrait.__index = APLTrait
-- Constructor -- Constructor
---@param cb fun(actor?: APLActor):boolean ---@param cb fun(actor?: APLActorTable):boolean
---@return APLTrait ---@return APLTrait
function APLTrait:New(cb) function APLTrait:New(cb)
local self = setmetatable({}, APLTrait) local self = setmetatable({}, APLTrait)
@ -18,7 +18,7 @@ function APLTrait:New(cb)
end end
-- Evaulate the APL trait -- Evaulate the APL trait
---@param actor? APLActor ---@param actor? APLActorTable
---@return boolean ---@return boolean
function APLTrait:Evaluate(actor) function APLTrait:Evaluate(actor)
if GetTime() - self.lastcall > 0.1 then if GetTime() - self.lastcall > 0.1 then
@ -80,7 +80,7 @@ end
---@return boolean ---@return boolean
function APLActor:Evaluate() function APLActor:Evaluate()
for _, trait in ipairs(self.traits) do for _, trait in ipairs(self.traits) do
if not trait:Evaluate(self) then if not trait:Evaluate(self:GetActor()) then
return false return false
end end
end end

@ -116,7 +116,6 @@ 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
[3] = EMOTE36_TOKEN, -- DRINK
[4] = TUTORIAL_TITLE12, -- Drink [4] = TUTORIAL_TITLE12, -- Drink
} }
@ -128,17 +127,13 @@ function Aura:IsFoodOrDrink()
if cachedFoodAndDrinkIDs[self.aura.spellId] then if cachedFoodAndDrinkIDs[self.aura.spellId] then
return cachedFoodAndDrinkIDs[self.aura.spellId] return cachedFoodAndDrinkIDs[self.aura.spellId]
else else
local auraName = self.aura.name if self.aura.name then
if auraName then
print("Aura Name", auraName)
for i = 1, #foodAndDrinkStrings do 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 cachedFoodAndDrinkIDs[self.aura.spellId] = true
return true return true
end end
end end
else
print("No Aura Name", self.aura.spellId)
end end
end end
end end
@ -260,7 +255,7 @@ end
-- Get the auras remaining time -- Get the auras remaining time
---@return number ---@return number
function Aura:GetRemainingTime() function Aura:GetRemainingTime()
local remainingTime = self.aura.expirationTime - GetTime() local remainingTime = self:GetExpirationTime() - GetTime()
if remainingTime < 0 then if remainingTime < 0 then
remainingTime = 0 remainingTime = 0

@ -4,6 +4,7 @@ local Tinkr, Bastion = ...
-- 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>>
local AuraTable = {} local AuraTable = {}
AuraTable.__index = AuraTable AuraTable.__index = AuraTable
@ -69,6 +70,7 @@ function AuraTable:OnUpdate(auras)
self:RemoveInstanceID(removedAuras[i]) self:RemoveInstanceID(removedAuras[i])
end end
end end
Bastion.EventManager:TriggerEvent("AURAS_UPDATED")
end end
---@param instanceID number ---@param instanceID number
@ -207,6 +209,7 @@ function AuraTable:Update()
-- self.auras = self.auras -- self.auras = self.auras
-- self.playerAuras = self.playerAuras -- self.playerAuras = self.playerAuras
Bastion.EventManager:TriggerEvent("AURAS_UPDATED_FULL")
end end
-- Get a units auras -- Get a units auras
@ -234,7 +237,6 @@ function AuraTable:GetUnitAuras()
end end
-- Get a units auras -- Get a units auras
---@return table
function AuraTable:GetMyUnitAuras() function AuraTable:GetMyUnitAuras()
if not self.did then if not self.did then
self.did = true self.did = true

@ -1,6 +1,9 @@
-- Create a module class for a bastion module -- Create a module class for a bastion module
---@class Module ---@class Module
---@field name string
---@field enabled boolean
---@field synced function[]
local Module = {} local Module = {}
Module.__index = Module Module.__index = Module

@ -1,3 +1,4 @@
---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
-- Create a new SpellBook class -- Create a new SpellBook class
@ -11,16 +12,33 @@ SpellBook.__index = SpellBook
function SpellBook:New() function SpellBook:New()
local self = setmetatable({}, SpellBook) local self = setmetatable({}, SpellBook)
self.spells = {} self.spells = {}
--[[ Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", function(...)
self:SpellCastSucceeded(...)
end) ]]
return self return self
end 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 -- Get a spell from the spellbook
---@return Spell ---@return Spell
function SpellBook:GetSpell(id) function SpellBook:GetSpell(id)
local override = FindSpellOverrideByID(id)
if self.spells[id] == nil then if self.spells[id] == nil then
self.spells[id] = Bastion.Spell:New(id) self.spells[id] = Bastion.Spell:New(id)
end 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] return self.spells[id]
end end
@ -55,7 +73,7 @@ end
---@return Spell ---@return Spell
function SpellBook:GetIfRegistered(id) function SpellBook:GetIfRegistered(id)
return self.spells[id] return self.spells[id] or self.spells[FindSpellOverrideByID(id)]
end end
return SpellBook return SpellBook

@ -6,10 +6,10 @@ local Tinkr, Bastion = ...
---@field id boolean | number ---@field id boolean | number
---@field ttd_ticker false | cbObject ---@field ttd_ticker false | cbObject
---@field unit TinkrObjectReference ---@field unit TinkrObjectReference
---@field aura_table AuraTable | nil
local Unit = { local Unit = {
---@type Cache ---@type Cache
cache = nil, cache = nil,
---@type AuraTable
aura_table = nil, aura_table = nil,
---@type UnitId | WowGameObject ---@type UnitId | WowGameObject
unit = nil, unit = nil,
@ -148,7 +148,7 @@ function Unit:GetPowerType()
end end
-- Get the units power -- Get the units power
---@param powerType number | nil ---@param powerType? number
---@return number ---@return number
function Unit:GetPower(powerType) function Unit:GetPower(powerType)
local powerType = powerType or self:GetPowerType() local powerType = powerType or self:GetPowerType()
@ -156,7 +156,7 @@ function Unit:GetPower(powerType)
end end
-- Get the units max power -- Get the units max power
---@param powerType number | nil ---@param powerType? number
---@return number ---@return number
function Unit:GetMaxPower(powerType) function Unit:GetMaxPower(powerType)
local powerType = powerType or self:GetPowerType() local powerType = powerType or self:GetPowerType()
@ -504,7 +504,7 @@ function Unit:IsInterruptible()
end end
-- Check if unit is interruptible -- Check if unit is interruptible
---@param percent number ---@param percent? number
---@param ignoreInterruptible? boolean ---@param ignoreInterruptible? boolean
---@return boolean ---@return boolean
function Unit:IsInterruptibleAt(percent, ignoreInterruptible) function Unit:IsInterruptibleAt(percent, ignoreInterruptible)
@ -609,7 +609,7 @@ function Unit:IsMovingAtAll()
return ObjectMovementFlag(self:GetOMToken()) ~= 0 return ObjectMovementFlag(self:GetOMToken()) ~= 0
end end
---@param unit Unit | nil ---@param unit? Unit
---@return number ---@return number
function Unit:GetComboPoints(unit) function Unit:GetComboPoints(unit)
if Tinkr.classic or Tinkr.era then if Tinkr.classic or Tinkr.era then
@ -618,7 +618,7 @@ function Unit:GetComboPoints(unit)
end end
return GetComboPoints(self:GetOMToken(), unit:GetOMToken()) return GetComboPoints(self:GetOMToken(), unit:GetOMToken())
end end
return UnitPower(self:GetOMToken(), 4) return UnitPower(self:GetOMToken(), Enum.PowerType.ComboPoints)
end end
---@return number ---@return number
@ -960,7 +960,16 @@ function Unit:IsStealthed()
local Shadowmeld = Bastion.Globals.SpellBook:GetSpell(58984) local Shadowmeld = Bastion.Globals.SpellBook:GetSpell(58984)
local Sepsis = Bastion.Globals.SpellBook:GetSpell(328305) 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 end
-- Get unit swing timers -- Get unit swing timers

@ -1,3 +1,4 @@
---@type Tinkr, Bastion
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
local ObjectManager = Tinkr.Util.ObjectManager local ObjectManager = Tinkr.Util.ObjectManager
@ -10,19 +11,19 @@ local UnitManager = {
units = {}, units = {},
customUnits = {}, customUnits = {},
objects = {}, objects = {},
cache = {} cache = {},
} }
function UnitManager:__index(k) function UnitManager:__index(k)
if k == 'none' then if k == "none" then
return self:Get('none') return self:Get("none")
end end
if UnitManager[k] then if UnitManager[k] then
return UnitManager[k] return UnitManager[k]
end 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 custom unit exists, return it it's cache expired return a new one
if self.customUnits[k] then if self.customUnits[k] then
@ -52,7 +53,7 @@ function UnitManager:__index(k)
end end
end end
return self.objects['none'] return self.objects["none"]
end end
-- Constructor -- Constructor
@ -65,7 +66,6 @@ function UnitManager:New()
return self return self
end end
-- Get or create a unit -- Get or create a unit
---@param token string ---@param token string
---@return Unit ---@return Unit
@ -77,8 +77,8 @@ function UnitManager:Get(token)
local tguid = ObjectGUID(token) local tguid = ObjectGUID(token)
if tguid and self.objects[tguid] == nil then if tguid and self.objects[tguid] == nil then
if token == 'none' then if token == "none" then
self.objects['none'] = Unit:New() self.objects["none"] = Unit:New()
else else
self.objects[tguid] = Unit:New(Object(tguid)) self.objects[tguid] = Unit:New(Object(tguid))
end end
@ -88,8 +88,8 @@ function UnitManager:Get(token)
local tguid = ObjectGUID(token) or "none" local tguid = ObjectGUID(token) or "none"
if self.objects[tguid] == nil then if self.objects[tguid] == nil then
if token == 'none' then if token == "none" then
self.objects['none'] = Unit:New() self.objects["none"] = Unit:New()
else else
self.objects[tguid] = Unit:New(Object(tguid)) self.objects[tguid] = Unit:New(Object(tguid))
end end
@ -127,7 +127,7 @@ function UnitManager:CreateCustomUnit(token, cb)
if self.customUnits[token] == nil then if self.customUnits[token] == nil then
self.customUnits[token] = { self.customUnits[token] = {
unit = cachedUnit, unit = cachedUnit,
cb = cb cb = cb,
} }
end end
@ -303,15 +303,7 @@ function UnitManager:FindFriendsCentroid(radius, range)
return unit:GetPosition() return unit:GetPosition()
end end
local _, _, z = TraceLine( local _, _, z = TraceLine(centroid.x, centroid.y, centroid.z + 5, centroid.x, centroid.y, centroid.z - 5, 0x100151)
centroid.x,
centroid.y,
centroid.z + 5,
centroid.x,
centroid.y,
centroid.z - 5,
0x100151
)
centroid.z = z + 0.01 centroid.z = z + 0.01
@ -342,15 +334,7 @@ function UnitManager:FindEnemiesCentroid(radius, range)
return unit:GetPosition() return unit:GetPosition()
end end
local _, _, z = TraceLine( local _, _, z = TraceLine(centroid.x, centroid.y, centroid.z + 5, centroid.x, centroid.y, centroid.z - 5, 0x100151)
centroid.x,
centroid.y,
centroid.z + 5,
centroid.x,
centroid.y,
centroid.z - 5,
0x100151
)
centroid.z = z + 0.01 centroid.z = z + 0.01

@ -149,11 +149,13 @@ Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New()
Bastion.Notifications = Bastion.NotificationsList:New() Bastion.Notifications = Bastion.NotificationsList:New()
local LIBRARIES = {} local LIBRARIES = {}
---@type Module[]
local MODULES = {} local MODULES = {}
Bastion.Enabled = false Bastion.Enabled = false
Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_AURA", function(unit, auras) Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_AURA", function(unit, auras)
---@type Unit | nil
local u = Bastion.UnitManager[unit] local u = Bastion.UnitManager[unit]
if u then if u then

Loading…
Cancel
Save