slightly tweak the types in AIBehavior

This commit is contained in:
PeaAshMeter 2026-04-17 00:29:53 +03:00 committed by neckrat
parent 09fb7e80ae
commit 3d6124d2ed

View File

@ -2,6 +2,8 @@ local easing = require "lib.utils.easing"
local pf = require "lib.pathfinder" local pf = require "lib.pathfinder"
local utils = require "lib.utils.utils" local utils = require "lib.utils.utils"
--- @alias AIAction fun(self: AIBehavior): Task<nil>
--- @return Character --- @return Character
local function closestCharacter(char) local function closestCharacter(char)
local caster = Vec3 {} local caster = Vec3 {}
@ -106,9 +108,9 @@ local function pathToClosestCharacter(owner, radius)
return target return target
end end
---@type {[Class]: fun(self: AIBehavior): Task<nil>} возможно где-то здесь на объявлении типа сломается типизация --- @type table<Class, AIAction>
local aiNature = { local aiNature = {
["dev_warrior"] = function(self) dev_warrior = function(self)
return function(callback) -- почему так, описано в Task return function(callback) -- почему так, описано в Task
self.owner:try(Tree.behaviors.spellcaster, function(spellB) self.owner:try(Tree.behaviors.spellcaster, function(spellB)
self.target = pathToClosestCharacter(self.owner, 1) self.target = pathToClosestCharacter(self.owner, 1)
@ -138,7 +140,7 @@ local aiNature = {
end) end)
end end
end, end,
["dev_mage"] = function(self) dev_mage = function(self)
return function(callback) return function(callback)
print("etoh... bleh") print("etoh... bleh")
callback() callback()
@ -146,12 +148,45 @@ local aiNature = {
end end
} }
--- @class AIBehavior : Behavior --- @class AIBehavior : Behavior
--- @field target Vec3? --- @field target Vec3?
local behavior = {} local behavior = {}
behavior.__index = behavior behavior.__index = behavior
behavior.id = "ai" behavior.id = "ai"
function behavior:dev_warrior()
return function(callback) -- почему так, описано в Task
self.owner:try(Tree.behaviors.spellcaster, function(spellB)
self.target = pathToClosestCharacter(self.owner, 1)
local attackTarget = closestCharacter(self.owner):has(Tree.behaviors.positioned)
if not attackTarget then return end
local task1 = spellB.spellbook[1]:cast(self.owner, self.target)
if task1 then
task1(
function()
-- здесь мы оказываемся после того, как сходили в первый раз
print('[AI]: я походил')
local task2 = spellB.spellbook[3]:cast(self.owner, attackTarget.position)
if task2 then
-- дергаем функцию после завершения хода
print('[AI]: и ударил')
task2(callback)
else
print('[AI]: чёт не бьётся')
callback()
end
end
)
else
print('рот этого казино')
callback()
end
end)
end
end
--- @param class Class --- @param class Class
function behavior.new(class) function behavior.new(class)
return setmetatable({ return setmetatable({