|
|
|
@ -12,6 +12,8 @@ local Tinkr, Bastion = ... |
|
|
|
|
---@field lastCastAttempt number | false |
|
|
|
|
---@field target Unit | false |
|
|
|
|
---@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 = { |
|
|
|
|
CastableIfFunc = false, |
|
|
|
|
PreCastFunc = false, |
|
|
|
@ -21,8 +23,17 @@ local Spell = { |
|
|
|
|
wasLooking = false, |
|
|
|
|
lastCastAt = false, |
|
|
|
|
conditions = {}, |
|
|
|
|
buffs = {}, |
|
|
|
|
debuffs = {}, |
|
|
|
|
auras = {}, |
|
|
|
|
overrides = {}, |
|
|
|
|
traits = { |
|
|
|
|
cast = { |
|
|
|
|
moving = true, |
|
|
|
|
dead = false, |
|
|
|
|
global = false, |
|
|
|
|
casting = false, |
|
|
|
|
channeling = false, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
target = false, |
|
|
|
|
release_at = 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 |
|
|
|
|
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 |
|
|
|
|
---@param func fun(self:Spell) |
|
|
|
|
---@return Spell |
|
|
|
@ -97,10 +116,9 @@ function Spell:PostCast(func) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Get the spells name |
|
|
|
|
---@param byId? boolean |
|
|
|
|
---@return string |
|
|
|
|
function Spell:GetName(byId) |
|
|
|
|
return select(1, GetSpellInfo((byId ~= nil and byId) and self:GetID() or self:GetID())) |
|
|
|
|
function Spell:GetName() |
|
|
|
|
return Bastion.Globals.SpellName[self:GetID()] or select(1, GetSpellInfo(self:GetID())) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Get the spells icon |
|
|
|
@ -113,7 +131,7 @@ end |
|
|
|
|
---@param byId? boolean |
|
|
|
|
---@return number |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
-- Return the castable function |
|
|
|
@ -135,7 +153,7 @@ end |
|
|
|
|
---@param byId? boolean |
|
|
|
|
---@return number |
|
|
|
|
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 |
|
|
|
|
return 0 |
|
|
|
|
end |
|
|
|
@ -162,6 +180,12 @@ function Spell:ClearCastableFunction() |
|
|
|
|
return self |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
---@param spell Spell |
|
|
|
|
---@param func fun(self: Spell): boolean |
|
|
|
|
function Spell:AddOverrideSpell(spell, func) |
|
|
|
|
self.overrides[spell:GetID()] = func |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Cast the spell |
|
|
|
|
---@param unit Unit |
|
|
|
|
---@param condition? string|fun(self:Spell):boolean |
|
|
|
@ -261,10 +285,9 @@ end |
|
|
|
|
---@param includeOverrides? boolean |
|
|
|
|
---@return boolean |
|
|
|
|
function Spell:IsKnown(includeOverrides) |
|
|
|
|
includeOverrides = includeOverrides ~= nil and includeOverrides or true |
|
|
|
|
local isKnown = includeOverrides and IsSpellKnownOrOverridesKnown(self:GetID()) or IsSpellKnown(self:GetID()) |
|
|
|
|
local isPlayerSpell = IsPlayerSpell(self:GetID()) |
|
|
|
|
return isKnown or isPlayerSpell |
|
|
|
|
local isKnown = includeOverrides and IsSpellKnownOrOverridesKnown(self:GetID()) or IsSpellKnown(self:GetID()) or |
|
|
|
|
IsPlayerSpell(self:GetID()) |
|
|
|
|
return isKnown |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Check if the spell is on cooldown |
|
|
|
@ -292,13 +315,27 @@ end |
|
|
|
|
---@param override? boolean |
|
|
|
|
---@return boolean |
|
|
|
|
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) |
|
|
|
|
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 |
|
|
|
|
---@return boolean |
|
|
|
|
function Spell:Castable() |
|
|
|
|
if not self:EvaluateTraits() then |
|
|
|
|
return true |
|
|
|
|
end |
|
|
|
|
if self:GetCastableFunction() then |
|
|
|
|
return self:GetCastableFunction()(self) |
|
|
|
|
end |
|
|
|
@ -615,10 +652,49 @@ function Spell:Damage() |
|
|
|
|
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 |
|
|
|
|
function Spell:GetAura(unit, source) |
|
|
|
|
return source and unit:GetAuras():FindFrom(self, source) or unit:GetAuras():FindAny(self) |
|
|
|
|
---@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 target? Unit |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
return Spell |
|
|
|
|