diff --git a/lib/character/behaviors/ai.lua b/lib/character/behaviors/ai.lua index 9402f8b..725d4a8 100644 --- a/lib/character/behaviors/ai.lua +++ b/lib/character/behaviors/ai.lua @@ -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 + --- @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} возможно где-то здесь на объявлении типа сломается типизация +--- @type table 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({