|
|
|
@ -12,7 +12,8 @@ local Spell = { |
|
|
|
|
lastCastAt = false, |
|
|
|
|
conditions = {}, |
|
|
|
|
target = false, |
|
|
|
|
release_at = false |
|
|
|
|
release_at = false, |
|
|
|
|
traits = {}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
local usableExcludes = { |
|
|
|
@ -48,12 +49,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 |
|
|
|
|
|
|
|
|
@ -325,11 +334,52 @@ end |
|
|
|
|
-- Check if the spell is castable |
|
|
|
|
---@return boolean |
|
|
|
|
function Spell:Castable() |
|
|
|
|
if #self.traits > 0 then |
|
|
|
|
return self:EvaluateTraits() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if self:GetCastableFunction() then |
|
|
|
|
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 |
|
|
|
@ -648,4 +698,25 @@ function Spell:IsFree() |
|
|
|
|
return self:GetCost() == 0 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- AddTraits |
|
|
|
|
---@param traits table |
|
|
|
|
---@return Spell |
|
|
|
|
function Spell:AddTraits(traits) |
|
|
|
|
for _, trait in ipairs(traits) do |
|
|
|
|
table.insert(self.traits, trait) |
|
|
|
|
end |
|
|
|
|
return self |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- EvaluateTraits |
|
|
|
|
---@return boolean |
|
|
|
|
function Spell:EvaluateTraits() |
|
|
|
|
for _, trait in ipairs(self.traits) do |
|
|
|
|
if not trait:Evaluate(self) then |
|
|
|
|
return false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
return true |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
return Spell |
|
|
|
|