Animate camera and activate AI on turn change in turnOrder.next()
This commit is contained in:
parent
4277c6c310
commit
52db521107
@ -1,4 +1,5 @@
|
||||
local PriorityQueue = require "lib.utils.priority_queue"
|
||||
local PriorityQueue = require "lib.utils.priority_queue"
|
||||
local easing = require "lib.utils.easing"
|
||||
|
||||
local initiativeComparator = function(id_a, id_b)
|
||||
local res = Tree.level.characters[id_a]:try(Tree.behaviors.stats, function(astats)
|
||||
@ -15,8 +16,8 @@ end
|
||||
--- @field pendingQueue PriorityQueue Очередь тех, кто ждет своего хода в текущем раунде
|
||||
--- @field current? Id Считаем того, кто сейчас ходит, отдельно, т.к. он ВСЕГДА первый в списке
|
||||
--- @field isTurnsEnabled boolean
|
||||
local turnOrder = {}
|
||||
turnOrder.__index = turnOrder
|
||||
local turnOrder = {}
|
||||
turnOrder.__index = turnOrder
|
||||
|
||||
local function new()
|
||||
return setmetatable({
|
||||
@ -29,19 +30,30 @@ end
|
||||
--- Перемещаем активного персонажа в очередь сходивших
|
||||
---
|
||||
--- Если в очереди на ход больше никого нет, заканчиваем раунд
|
||||
---
|
||||
--- Анимируем камеру к следующему персонажу. Если это ИИ, то активируем его логику.
|
||||
function turnOrder:next()
|
||||
self.actedQueue:insert(self.current)
|
||||
local next = self.pendingQueue:peek()
|
||||
if not next then return self:endRound() end
|
||||
self.current = self.pendingQueue:pop()
|
||||
if not next then self:endRound() else self.current = self.pendingQueue:pop() end
|
||||
|
||||
local char = Tree.level.characters[self.current]
|
||||
char:try(Tree.behaviors.ai, function(ai)
|
||||
Tree.level.selector:lock()
|
||||
ai:makeTurn()(function()
|
||||
Tree.level.selector:unlock()
|
||||
self:next()
|
||||
end)
|
||||
|
||||
Tree.level.selector:lock()
|
||||
char:try(Tree.behaviors.positioned, function(positioned)
|
||||
Tree.level.camera:animateTo(positioned.position, 1500, easing.easeInOutCubic)(
|
||||
function()
|
||||
if char:has(Tree.behaviors.ai) then
|
||||
char:has(Tree.behaviors.ai):makeTurn()(
|
||||
function()
|
||||
self:next()
|
||||
end)
|
||||
else
|
||||
Tree.level.selector:unlock()
|
||||
Tree.level.selector:select(self.current)
|
||||
end
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@ -46,14 +46,6 @@ end
|
||||
|
||||
function endTurnButton:onClick()
|
||||
Tree.level.turnOrder:next()
|
||||
Tree.level.selector:select(nil)
|
||||
local cid = Tree.level.turnOrder.current
|
||||
local playing = Tree.level.characters[cid]
|
||||
if not playing:has(Tree.behaviors.positioned) then return end
|
||||
|
||||
Tree.level.camera:animateTo(playing:has(Tree.behaviors.positioned).position, 1500, easing.easeInOutCubic)(
|
||||
function() if not playing:has(Tree.behaviors.ai) then Tree.level.selector:select(cid) end end
|
||||
)
|
||||
end
|
||||
|
||||
return function(values)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user