feature/task #29

Merged
PeaAshMeter merged 10 commits from feature/task into main 2026-02-02 02:36:31 +03:00
5 changed files with 59 additions and 26 deletions
Showing only changes of commit 3f694ccec9 - Show all commits

View File

@ -22,6 +22,7 @@ end
--- @class AIBehavior : Behavior
--- @field animationNode AnimationNode?
--- @field target Vec3?
local behavior = {}
behavior.__index = behavior
behavior.id = "ai"
@ -52,26 +53,53 @@ end
function behavior:makeMove()
self.owner:try(Tree.behaviors.spellcaster, function(spellB)
-- print('какещке')
self.animationNode = AnimationNode {
function(node) end,
onEnd = function()
-- print('kakeshke')
end,
children = {
local charTarget = closestCharacter(self.owner)
charTarget:try(Tree.behaviors.positioned, function(b)
self.target = Vec3 { b.position.x, b.position.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
end)
spellB.spellbook[1]:cast(self.owner, self.target):chain {
spellB.spellbook[1]:cast(self.owner, Vec3 { 10, 10 }):chain {
AnimationNode {
function(node)
local charTarget = closestCharacter(self.owner)
local target
charTarget:try(Tree.behaviors.positioned, function(b)
target = Vec3 { b.position.x, b.position.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
end)
spellB.spellbook[1]:cast(self.owner, target)
onEnd = function()
Tree.level.turnOrder:next()
end
}
}
}
self.animationNode:run()
}:run()
-- -- print('какещке')
-- self.animationNode = AnimationNode { -- кринж
-- function(node) end,
-- onEnd = function()
-- -- print('kakeshke')
-- end,
-- children = {
-- AnimationNode {
-- function(node) --тяжело
-- local charTarget = closestCharacter(self.owner)
-- charTarget:try(Tree.behaviors.positioned, function(b)
-- self.target = Vec3 { b.position.x, b.position.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
-- end)
-- spellB.spellbook[1]:cast(self.owner, self.target)
-- end,
-- onEnd = function() --база
-- end,
-- children = {
-- AnimationNode {
-- function(node)
-- -- if not self.target then return end
-- print("пупупупупупупупупупуупупуууууу")
-- print(spellB.spellbook[3]:cast(self.owner, self.target))
-- end
-- }
-- }
-- }
-- }
-- }
-- self.animationNode:run()
end)
end

View File

@ -37,7 +37,9 @@ function selector:update(dt)
if not selectedId then self:select(nil) end
return
end
if b.cast:cast(char, mousePosition) then
local task = b.cast:cast(char, mousePosition)
if task then
task:run()
self:lock()
b.state = "running"
end

View File

@ -34,6 +34,11 @@ function turnOrder:next()
local next = self.pendingQueue:peek()
if not next then return self:endRound() end
self.current = self.pendingQueue:pop()
local char = Tree.level.characters[self.current]
char:try(Tree.behaviors.ai, function(ai)
ai:makeMove()
end)
end
--- Меняем местами очередь сходивших и не сходивших (пустую)

View File

@ -14,7 +14,7 @@ local easing = require "lib.utils.easing"
--- @field tag string
--- @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 в зависимости от того, получилось ли скастовать
--- @field cast fun(self: Spell, caster: Character, target: Vec3): AnimationNode | nil Вызывается в момент каста, изменяет мир.
local spell = {}
spell.__index = spell
spell.tag = "base"
@ -35,12 +35,12 @@ function walk:cast(caster, target)
if not caster:try(Tree.behaviors.stats, function(stats)
return stats.mana >= 2
end) then
return false
return
end
local path = require "lib.pathfinder" (caster:has(Tree.behaviors.positioned).position:floor(), target)
path:pop_front()
if path:is_empty() then return false end
if path:is_empty() then return end
for p in path:values() do print(p) end
@ -50,15 +50,13 @@ function walk:cast(caster, target)
end)
local sprite = caster:has(Tree.behaviors.sprite)
if not sprite then return true end
AnimationNode {
if not sprite then return end
return AnimationNode {
function(node)
caster:has(Tree.behaviors.tiled):followPath(path, node)
end,
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end,
}:run()
return true
}
end
function walk:update(caster, dt)

View File

@ -36,7 +36,7 @@ function love.load()
character.spawn("Foodor")
:addBehavior {
Tree.behaviors.residentsleeper.new(),
Tree.behaviors.stats.new(nil, nil, 1),
Tree.behaviors.stats.new(nil, nil, 3),
Tree.behaviors.positioned.new(Vec3 { 5, 3 }),
Tree.behaviors.tiled.new(),
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),