Bastion aims to serve as a highly performant, simplisitic, and expandable World of Warcraft data visualization framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Bastion/src/Aura/Aura.lua

384 lines
9.1 KiB

-- Document with emmy lua: https://emmylua.github.io/
local Tinkr, Bastion = ...
-- Create a new Aura class
---@class Aura
local Aura = {}
function Aura:__index(k)
local response = Bastion.ClassMagic:Resolve(Aura, k)
if response == nil then
response = rawget(self, k)
end
if response == nil then
error("Aura:__index: " .. k .. " does not exist")
end
return response
end
-- Equals
---@param other Aura | Spell
---@return boolean
function Aura:__eq(other)
if getmetatable(other) == Aura then
return self:GetSpell():GetID() == other:GetSpell():GetID()
end
if getmetatable(other) == Bastion.Spell then
return self:GetSpell():GetID() == other:GetID()
end
return false
end
-- tostring
---@return string
function Aura:__tostring()
return "Bastion.__Aura(" .. self:GetSpell():GetID() .. ")" .. " - " .. (self:GetName() or "''")
end
-- Constructor
---@param unit? Unit
---@param index? number
---@param type? string
function Aura:New(unit, index, type)
if unit == nil or index == nil or type == nil then
---@class Aura
local self = setmetatable({}, Aura)
self.aura = {
name = nil,
icon = nil,
count = 0,
dispelType = nil,
duration = 0,
expirationTime = 0,
source = nil,
isStealable = false,
nameplateShowPersonal = false,
spellId = 0,
canApplyAura = false,
isBossDebuff = false,
castByPlayer = false,
nameplateShowAll = false,
timeMod = 0,
points = {},
index = nil,
type = nil,
}
if self.aura.spellId then
Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
end
return self
end
local name, icon, count, dispelType, duration, expirationTime, source, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, castByPlayer, nameplateShowAll, timeMod, v1, v2, v3, v4 =
UnitAura(unit:GetOMToken(), index, type)
---@class Aura
local self = setmetatable({}, Aura)
self.aura = {
name = name,
icon = icon,
count = count,
dispelType = dispelType,
duration = duration,
expirationTime = expirationTime,
source = source,
isStealable = isStealable,
nameplateShowPersonal = nameplateShowPersonal,
spellId = spellId,
canApplyAura = canApplyAura,
isBossDebuff = isBossDebuff,
castByPlayer = castByPlayer,
nameplateShowAll = nameplateShowAll,
timeMod = timeMod,
auraInstanceID = nil,
points = {
[1] = v1,
[2] = v2,
[3] = v3,
[4] = v4,
},
index = index,
type = type,
}
if self.aura.spellId then
Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
end
return self
end
local foodAndDrinkStrings = {
[5] = "Refreshment",
[1] = MINIMAP_TRACKING_VENDOR_FOOD, -- Food & Drink
[2] = POWER_TYPE_FOOD, -- Food
[3] = EMOTE36_TOKEN, -- DRINK
[4] = TUTORIAL_TITLE12, -- Drink
}
---@type { [number]: boolean }
local cachedFoodAndDrinkIDs = {}
function Aura:IsFoodOrDrink()
if self.aura.spellId and self.aura.spellId > 0 and self:IsValid() and self:IsUp() then
if cachedFoodAndDrinkIDs[self.aura.spellId] then
return cachedFoodAndDrinkIDs[self.aura.spellId]
else
local auraName = self.aura.name
if auraName then
print("Aura Name", auraName)
for i = 1, #foodAndDrinkStrings do
if auraName:upper():find(foodAndDrinkStrings[i]:upper()) then
cachedFoodAndDrinkIDs[self.aura.spellId] = true
return true
end
end
else
print("No Aura Name", self.aura.spellId)
end
end
end
return false
end
-- Constructor
---@param unitAuraInfo AuraData
---@return Aura
function Aura:CreateFromUnitAuraInfo(unitAuraInfo)
---@class Aura
local self = setmetatable({}, Aura)
--[[
applications
charges
isNameplateOnly
isRaid
maxCharges
]]
--
self.aura = {
auraInstanceID = unitAuraInfo.auraInstanceID,
canApplyAura = unitAuraInfo.canApplyAura,
castByPlayer = unitAuraInfo.isFromPlayerOrPlayerPet,
count = unitAuraInfo.applications,
dispelType = unitAuraInfo.dispelName or "",
duration = unitAuraInfo.duration,
expirationTime = unitAuraInfo.expirationTime,
icon = unitAuraInfo.icon,
isBossDebuff = unitAuraInfo.isBossAura,
isStealable = unitAuraInfo.isStealable,
name = unitAuraInfo.name,
nameplateShowAll = unitAuraInfo.nameplateShowAll,
nameplateShowPersonal = unitAuraInfo.nameplateShowPersonal,
points = unitAuraInfo.points,
source = unitAuraInfo.sourceUnit,
spellId = unitAuraInfo.spellId,
timeMod = unitAuraInfo.timeMod,
index = nil,
type = unitAuraInfo.isHarmful and "HARMFUL" or "HELPFUL",
}
-- Register spell in spellbook
Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
return self
end
-- Check if the aura is valid
---@return boolean
function Aura:IsValid()
return self.aura.name ~= nil
end
-- Check if the aura is up
---@return boolean
function Aura:IsUp()
return self:IsValid() and (self:GetDuration() == 0 or self:GetRemainingTime() > 0)
end
-- Check if the aura is down
---@return boolean
function Aura:IsDown()
return not self:IsUp()
end
-- Get the auras index
---@return number
function Aura:GetIndex()
return self.aura.index
end
-- Get the auras type
---@return string
function Aura:GetType()
return self.aura.type
end
-- Get the auras name
---@return string
function Aura:GetName()
return self.aura.name
end
-- Get the auras icon
---@return number
function Aura:GetIcon()
return self.aura.icon
end
-- Get the auras count
---@return number
function Aura:GetCount()
return self.aura.count
end
-- Get the auras dispel type
---@return string
function Aura:GetDispelType()
return self.aura.dispelType
end
-- Get the auras duration
---@return number
function Aura:GetDuration()
return self.aura.duration
end
-- Get the auras refresh status
---@return boolean
function Aura:Refreshable()
if not self:IsUp() then
return true
end
return self:GetRemainingTime() < self:GetDuration() * 0.3
end
-- Get the auras remaining time
---@return number
function Aura:GetRemainingTime()
local remainingTime = self.aura.expirationTime - GetTime()
if remainingTime < 0 then
remainingTime = 0
end
return remainingTime
end
-- Get the auras expiration time
---@return number
function Aura:GetExpirationTime()
return self.aura.expirationTime
end
-- Get the auras source
---@return Unit
function Aura:GetSource()
return Bastion.UnitManager[self.aura.source]
end
-- Get the auras stealable status
---@return boolean
function Aura:GetIsStealable()
return self.aura.isStealable
end
-- Get the auras nameplate show personal status
---@return boolean
function Aura:GetNameplateShowPersonal()
return self.aura.nameplateShowPersonal
end
-- Get the auras spell id
---@return Spell
function Aura:GetSpell()
return Bastion.Globals.SpellBook:GetSpell(self.aura.spellId)
end
-- Get the auras can apply aura status
---@return boolean
function Aura:GetCanApplyAura()
return self.aura.canApplyAura
end
-- Get the auras is boss debuff status
---@return boolean
function Aura:GetIsBossDebuff()
return self.aura.isBossDebuff
end
-- Get the auras cast by player status
---@return boolean
function Aura:GetCastByPlayer()
return self.aura.castByPlayer
end
-- Get the auras nameplate show all status
---@return boolean
function Aura:GetNameplateShowAll()
return self.aura.nameplateShowAll
end
-- Get the auras time mod
---@return number
function Aura:GetTimeMod()
return self.aura.timeMod
end
-- Check if the aura is a buff
---@return boolean
function Aura:IsBuff()
return self.aura.type == "HELPFUL"
end
-- Check if the aura is a debuff
---@return boolean
function Aura:IsDebuff()
return self.aura.type == "HARMFUL"
end
-- Get aura instance id
---@return number
function Aura:GetAuraInstanceID()
return self.aura.auraInstanceID
end
-- Check if the aura is dispelable by a spell
---@param spell Spell
function Aura:IsDispelableBySpell(spell)
if
(self:GetDispelType() == "" or self:GetDispelType() == nil)
and self:GetIsStealable()
and spell:IsEnrageDispel()
then
return true
end
if self:GetDispelType() == nil then
return false
end
if self:GetDispelType() == "Magic" and spell:IsMagicDispel() then
return true
end
if self:GetDispelType() == "Curse" and spell:IsCurseDispel() then
return true
end
if self:GetDispelType() == "Poison" and spell:IsPoisonDispel() then
return true
end
if self:GetDispelType() == "Disease" and spell:IsDiseaseDispel() then
return true
end
return false
end
return Aura