heroes-of-nerevelon/lib/spellbook.lua
2025-10-12 03:03:02 +03:00

65 lines
2.4 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--- @class Spell Здесь будет много бойлерплейта, поэтому тоже понадобится спеллмейкерский фреймворк, который просто вернет готовый Spell
--- @field update fun(self: Spell, caster: Character, dt: number): nil Изменяет состояние спелла
--- @field draw fun(self: Spell): nil Рисует превью каста, ничего не должна изменять в идеальном мире
--- @field cast fun(self: Spell, caster: Character, target: Vec3): boolean Вызывается в момент каста, изменяет мир. Возвращает bool в зависимости от того, получилось ли скастовать
local spell = {}
spell.__index = spell
function spell:update(caster, dt) end
function spell:draw() end
function spell:cast(caster, target) return true end
local walk = setmetatable({
--- @type Deque
path = nil
}, spell)
function walk:cast(caster, target)
local path = self.path
if path:is_empty() then return false end
path:pop_front()
for p in path:values() do print(p) end
caster:has(Tree.behaviors.map):followPath(path, function()
caster:has(Tree.behaviors.spellcaster):endCast()
end)
-- TODO: списать деньги за каст (антиутопия какая-то)
-- TODO: привязка тинькоффа
return true
end
function walk:update(caster, dt)
local charPos = caster:has(Tree.behaviors.map).position:floor()
--- @type Vec3
local mpos = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
self.path = require "lib.pathfinder" (charPos, mpos)
end
function walk:draw()
if not self.path then return end
--- Это отрисовка пути персонажа к мышке
love.graphics.setColor(0.6, 0.75, 0.5)
for p in self.path:values() do
love.graphics.circle("fill", p.x + 0.45, p.y + 0.45, 0.1)
end
love.graphics.setColor(1, 1, 1)
end
----------------------------------------
local spellbook = {
walk = walk
}
--- Создает новый спеллбук с уникальными спеллами (а не ссылками на шаблоны)
--- @param list Spell[]
function spellbook.of(list)
local spb = {}
for i, sp in ipairs(list) do
spb[i] = setmetatable({}, { __index = sp })
end
return spb
end
return spellbook