slightly tweak the types in AIBehavior

This commit is contained in:
PeaAshMeter 2026-04-17 00:29:53 +03:00
parent d1597d8ffa
commit d7228cc322

View File

@ -2,6 +2,8 @@ local easing = require "lib.utils.easing"
local pf = require "lib.pathfinder"
local utils = require "lib.utils.utils"
--- @alias AIAction fun(self: AIBehavior): Task<nil>
--- @return Character
local function closestCharacter(char)
local caster = Vec3 {}
@ -106,9 +108,9 @@ local function pathToClosestCharacter(owner, radius)
return target
end
---@type {[Class]: fun(self: AIBehavior): Task<nil>} возможно где-то здесь на объявлении типа сломается типизация
--- @type table<Class, AIAction>
local aiNature = {
["dev_warrior"] = function(self)
dev_warrior = function(self)
return function(callback) -- почему так, описано в Task
self.owner:try(Tree.behaviors.spellcaster, function(spellB)
self.target = pathToClosestCharacter(self.owner, 1)
@ -138,7 +140,7 @@ local aiNature = {
end)
end
end,
["dev_mage"] = function(self)
dev_mage = function(self)
return function(callback)
print("etoh... bleh")
callback()
@ -146,12 +148,45 @@ local aiNature = {
end
}
--- @class AIBehavior : Behavior
--- @field target Vec3?
local behavior = {}
behavior.__index = behavior
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
function behavior.new(class)
return setmetatable({