attempt to save our souls (callback hell my beloved)
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
This commit is contained in:
parent
d48f1af1af
commit
3f694ccec9
@ -22,6 +22,7 @@ end
|
|||||||
|
|
||||||
--- @class AIBehavior : Behavior
|
--- @class AIBehavior : Behavior
|
||||||
--- @field animationNode AnimationNode?
|
--- @field animationNode AnimationNode?
|
||||||
|
--- @field target Vec3?
|
||||||
local behavior = {}
|
local behavior = {}
|
||||||
behavior.__index = behavior
|
behavior.__index = behavior
|
||||||
behavior.id = "ai"
|
behavior.id = "ai"
|
||||||
@ -52,26 +53,53 @@ end
|
|||||||
|
|
||||||
function behavior:makeMove()
|
function behavior:makeMove()
|
||||||
self.owner:try(Tree.behaviors.spellcaster, function(spellB)
|
self.owner:try(Tree.behaviors.spellcaster, function(spellB)
|
||||||
-- print('какещке')
|
|
||||||
self.animationNode = AnimationNode {
|
|
||||||
function(node) end,
|
|
||||||
onEnd = function()
|
|
||||||
-- print('kakeshke')
|
|
||||||
end,
|
|
||||||
children = {
|
|
||||||
AnimationNode {
|
|
||||||
function(node)
|
|
||||||
local charTarget = closestCharacter(self.owner)
|
local charTarget = closestCharacter(self.owner)
|
||||||
local target
|
|
||||||
charTarget:try(Tree.behaviors.positioned, function(b)
|
charTarget:try(Tree.behaviors.positioned, function(b)
|
||||||
target = Vec3 { b.position.x, b.position.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
|
self.target = Vec3 { b.position.x, b.position.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
|
||||||
end)
|
end)
|
||||||
spellB.spellbook[1]:cast(self.owner, target)
|
|
||||||
|
spellB.spellbook[1]:cast(self.owner, self.target):chain {
|
||||||
|
spellB.spellbook[1]:cast(self.owner, Vec3 { 10, 10 }):chain {
|
||||||
|
AnimationNode {
|
||||||
|
onEnd = function()
|
||||||
|
Tree.level.turnOrder:next()
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}:run()
|
||||||
self.animationNode: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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,9 @@ function selector:update(dt)
|
|||||||
if not selectedId then self:select(nil) end
|
if not selectedId then self:select(nil) end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if b.cast:cast(char, mousePosition) then
|
local task = b.cast:cast(char, mousePosition)
|
||||||
|
if task then
|
||||||
|
task:run()
|
||||||
self:lock()
|
self:lock()
|
||||||
b.state = "running"
|
b.state = "running"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -34,6 +34,11 @@ function turnOrder:next()
|
|||||||
local next = self.pendingQueue:peek()
|
local next = self.pendingQueue:peek()
|
||||||
if not next then return self:endRound() end
|
if not next then return self:endRound() end
|
||||||
self.current = self.pendingQueue:pop()
|
self.current = self.pendingQueue:pop()
|
||||||
|
|
||||||
|
local char = Tree.level.characters[self.current]
|
||||||
|
char:try(Tree.behaviors.ai, function(ai)
|
||||||
|
ai:makeMove()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Меняем местами очередь сходивших и не сходивших (пустую)
|
--- Меняем местами очередь сходивших и не сходивших (пустую)
|
||||||
|
|||||||
@ -14,7 +14,7 @@ local easing = require "lib.utils.easing"
|
|||||||
--- @field tag string
|
--- @field tag string
|
||||||
--- @field update fun(self: Spell, caster: Character, dt: number): nil Изменяет состояние спелла
|
--- @field update fun(self: Spell, caster: Character, dt: number): nil Изменяет состояние спелла
|
||||||
--- @field draw fun(self: Spell): 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 = {}
|
local spell = {}
|
||||||
spell.__index = spell
|
spell.__index = spell
|
||||||
spell.tag = "base"
|
spell.tag = "base"
|
||||||
@ -35,12 +35,12 @@ function walk:cast(caster, target)
|
|||||||
if not caster:try(Tree.behaviors.stats, function(stats)
|
if not caster:try(Tree.behaviors.stats, function(stats)
|
||||||
return stats.mana >= 2
|
return stats.mana >= 2
|
||||||
end) then
|
end) then
|
||||||
return false
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local path = require "lib.pathfinder" (caster:has(Tree.behaviors.positioned).position:floor(), target)
|
local path = require "lib.pathfinder" (caster:has(Tree.behaviors.positioned).position:floor(), target)
|
||||||
path:pop_front()
|
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
|
for p in path:values() do print(p) end
|
||||||
|
|
||||||
@ -50,15 +50,13 @@ function walk:cast(caster, target)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local sprite = caster:has(Tree.behaviors.sprite)
|
local sprite = caster:has(Tree.behaviors.sprite)
|
||||||
if not sprite then return true end
|
if not sprite then return end
|
||||||
AnimationNode {
|
return AnimationNode {
|
||||||
function(node)
|
function(node)
|
||||||
caster:has(Tree.behaviors.tiled):followPath(path, node)
|
caster:has(Tree.behaviors.tiled):followPath(path, node)
|
||||||
end,
|
end,
|
||||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end,
|
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end,
|
||||||
}:run()
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function walk:update(caster, dt)
|
function walk:update(caster, dt)
|
||||||
|
|||||||
2
main.lua
2
main.lua
@ -36,7 +36,7 @@ function love.load()
|
|||||||
character.spawn("Foodor")
|
character.spawn("Foodor")
|
||||||
:addBehavior {
|
:addBehavior {
|
||||||
Tree.behaviors.residentsleeper.new(),
|
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.positioned.new(Vec3 { 5, 3 }),
|
||||||
Tree.behaviors.tiled.new(),
|
Tree.behaviors.tiled.new(),
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user