local AnimationNode = require "lib.animation_node" --- @class AIBehavior : Behavior --- @field animationNode AnimationNode? local behavior = {} behavior.__index = behavior behavior.id = "ai" function behavior.new() return setmetatable({}, behavior) end function behavior:update(dt) self.owner:try(Tree.behaviors.spellcaster, function(b) if b.state == "casting" then b.cast:update(self.owner, dt) end end) if self.animationNode and self.animationNode.state == "running" then self.animationNode:update(dt) -- print(self.animationNode.t) end end function behavior:draw() self.owner:try(Tree.behaviors.spellcaster, function(b) if b.state == "casting" then b.cast:draw() end end) 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 = { AnimationNode { function(node) local caster = Vec3 {} self.owner:try(Tree.behaviors.positioned, function(b) caster = b.position end) local target = Vec3 {} local charTarget local minDist = 88005553535 -- spooky magic number for k, v in pairs(Tree.level.characters) do v:try(Tree.behaviors.positioned, function(b) local dist = ((caster.x - b.position.x) ^ 2 + (caster.y - b.position.y) ^ 2) ^ 0.5 if dist < minDist and dist ~= 0 then minDist = dist target = b.position charTarget = v end -- print(k, b.position) end) break end -- print(target) charTarget:try(Tree.behaviors.positioned, function(b) target = Vec3 { target.x, target.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти end) spellB.spellbook[1]:cast(self.owner, target) -- print(minDist, target) end } } } self.animationNode:run() end) end return behavior