feat: add spell traits

add_traits
João Fidalgo 7 months ago committed by vibe
parent 073a9e03b7
commit e4d7894e21
  1. 34
      src/Spell/Spell.lua
  2. 23
      src/SpellTrait/SpellTrait.lua
  3. 2
      src/_bastion.lua

@ -13,14 +13,7 @@ local Spell = {
conditions = {},
target = false,
release_at = false,
traits = {
ignoreChanneling = false,
ignoreFacing = false,
ignoreLoS = false,
ignoreGCD = false,
ignoreMoving = false,
targeted = false
}
traits = {},
}
local usableExcludes = {
@ -341,6 +334,10 @@ 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
@ -701,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

@ -0,0 +1,23 @@
local Tinkr, Bastion = ...
---@class SpellTrait
local SpellTrait = {}
SpellTrait.__index = SpellTrait
-- Constructor
---@param func function
---@return SpellTrait
function SpellTrait:New(func)
local self = setmetatable({}, SpellTrait)
self.func = func
return self
end
-- Evaluate the trait
---@param spell Spell
---@return boolean
function SpellTrait:Evaluate(spell)
return self.func(spell)
end
return SpellTrait

@ -96,6 +96,8 @@ function Bastion.Bootstrap()
---@type SpellBook
Bastion.SpellBook = Bastion.require("SpellBook")
Bastion.Globals.SpellBook = Bastion.SpellBook:New()
---@type SpellTrait
Bastion.SpellTrait = Bastion.require("SpellTrait")
---@type Item
Bastion.Item = Bastion.require("Item")
---@type ItemBook

Loading…
Cancel
Save