34 lines
1.1 KiB
Lua
34 lines
1.1 KiB
Lua
--- @class SpellcasterBehavior : Behavior
|
|
--- @field spellbook Spell[] собственный набор спеллов персонажа
|
|
--- @field cast Spell | nil ссылка на активный спелл из спеллбука
|
|
--- @field state "idle" | "casting" | "running"
|
|
local behavior = {}
|
|
behavior.__index = behavior
|
|
behavior.id = "spellcaster"
|
|
behavior.state = "idle"
|
|
|
|
---@param spellbook Spell[] | nil
|
|
---@return SpellcasterBehavior
|
|
function behavior.new(spellbook)
|
|
local spb = require "lib.spellbook" --- @todo временное добавление ходьбы (и читов) всем персонажам
|
|
local t = {}
|
|
t.spellbook = spellbook or spb.of { spb.walk, spb.regenerateMana, spb.attack }
|
|
return setmetatable(t, behavior)
|
|
end
|
|
|
|
function behavior:endCast()
|
|
self.state = "idle"
|
|
self.cast = nil
|
|
Tree.level.selector:unlock()
|
|
end
|
|
|
|
function behavior:update(dt)
|
|
if self.cast and self.state == "casting" then self.cast:update(self.owner, dt) end
|
|
end
|
|
|
|
function behavior:draw()
|
|
if self.cast and self.state == "casting" then self.cast:draw() end
|
|
end
|
|
|
|
return behavior
|