--- @class 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): nil Вызывается в момент каста, изменяет мир local spell = {} spell.__index = spell function spell:update(caster, dt) end function spell:draw() end function spell:cast(caster, target) end local walk = setmetatable({ --- @type Deque path = nil }, spell) function walk:cast(caster, target) local path = self.path if path:is_empty() then return end path:pop_front() print("Following path: ") for p in path:values() do print(p) end caster:has(Tree.behaviors.map):followPath(path) -- TODO: списать деньги за каст (антиутопия какая-то) -- TODO: привязка тинькоффа 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