From 073a9e03b7691c9cfe3cc7496c8b98be000001b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fidalgo?= Date: Sat, 8 Jun 2024 02:11:45 +0100 Subject: [PATCH] feat: add spell traits --- src/Spell/Spell.lua | 59 +++++++++++++++++++++++++++++++++++-- src/SpellBook/SpellBook.lua | 6 ++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/Spell/Spell.lua b/src/Spell/Spell.lua index 0aad894..4f134de 100644 --- a/src/Spell/Spell.lua +++ b/src/Spell/Spell.lua @@ -12,7 +12,15 @@ local Spell = { lastCastAt = false, conditions = {}, target = false, - release_at = false + release_at = false, + traits = { + ignoreChanneling = false, + ignoreFacing = false, + ignoreLoS = false, + ignoreGCD = false, + ignoreMoving = false, + targeted = false + } } local usableExcludes = { @@ -48,12 +56,20 @@ end -- Constructor ---@param id number +---@param traits? table ---@return Spell -function Spell:New(id) +function Spell:New(id, traits) local self = setmetatable({}, Spell) self.spellID = id + if traits == nil then traits = {} end + for k in pairs(traits) do + if self.traits[k] ~= nil and traits[k] ~= nil then + self.traits[k] = traits[k] + end + end + return self end @@ -329,7 +345,44 @@ function Spell:Castable() return self:GetCastableFunction()(self) end - return self:IsKnownAndUsable() + if not self:IsKnownAndUsable() then return false end + + local player = Bastion.UnitManager:Get("player") + + if self.traits.targeted then + local target = self:GetTarget() + + if not target or + not target:Exists() then return false end + + if not self:IsInRange(target) then return false end + + if not self.traits.ignoreFacing then + if not player:IsFacing(target) then return false end + end + + if not self.traits.ignoreLoS then + if not player:CanSee(target) then return false end + end + end + + if not self.traits.ignoreCasting then + if player:IsCasting() then return false end + end + + if not self.traits.ignoreChanneling then + if player:IsChanneling() then return false end + end + + if not self.traits.ignoreGCD then + if player:GetGCD() > C_Spell.GetSpellQueueWindow() then return false end + end + + if not self.traits.ignoreMoving then + if self:GetCastLength() > 0 and player:IsMoving() then return false end + end + + return true end -- Set a script to check if the spell is castable diff --git a/src/SpellBook/SpellBook.lua b/src/SpellBook/SpellBook.lua index 243a4bd..06e79d4 100644 --- a/src/SpellBook/SpellBook.lua +++ b/src/SpellBook/SpellBook.lua @@ -14,10 +14,12 @@ function SpellBook:New() end -- Get a spell from the spellbook +---@param id number +---@param traits? table ---@return Spell -function SpellBook:GetSpell(id) +function SpellBook:GetSpell(id, traits) if self.spells[id] == nil then - self.spells[id] = Bastion.Spell:New(id) + self.spells[id] = Bastion.Spell:New(id, traits) end return self.spells[id]