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 initiativeComparator = function(id_a, id_b)
|
||||||
local res = Tree.level.characters[id_a]:try(Tree.behaviors.stats, function(astats)
|
local res = Tree.level.characters[id_a]:try(Tree.behaviors.stats, function(astats)
|
||||||
@ -15,8 +16,8 @@ end
|
|||||||
--- @field pendingQueue PriorityQueue Очередь тех, кто ждет своего хода в текущем раунде
|
--- @field pendingQueue PriorityQueue Очередь тех, кто ждет своего хода в текущем раунде
|
||||||
--- @field current? Id Считаем того, кто сейчас ходит, отдельно, т.к. он ВСЕГДА первый в списке
|
--- @field current? Id Считаем того, кто сейчас ходит, отдельно, т.к. он ВСЕГДА первый в списке
|
||||||
--- @field isTurnsEnabled boolean
|
--- @field isTurnsEnabled boolean
|
||||||
local turnOrder = {}
|
local turnOrder = {}
|
||||||
turnOrder.__index = turnOrder
|
turnOrder.__index = turnOrder
|
||||||
|
|
||||||
local function new()
|
local function new()
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
@ -29,19 +30,30 @@ end
|
|||||||
--- Перемещаем активного персонажа в очередь сходивших
|
--- Перемещаем активного персонажа в очередь сходивших
|
||||||
---
|
---
|
||||||
--- Если в очереди на ход больше никого нет, заканчиваем раунд
|
--- Если в очереди на ход больше никого нет, заканчиваем раунд
|
||||||
|
---
|
||||||
|
--- Анимируем камеру к следующему персонажу. Если это ИИ, то активируем его логику.
|
||||||
function turnOrder:next()
|
function turnOrder:next()
|
||||||
self.actedQueue:insert(self.current)
|
self.actedQueue:insert(self.current)
|
||||||
local next = self.pendingQueue:peek()
|
local next = self.pendingQueue:peek()
|
||||||
if not next then return self:endRound() end
|
if not next then self:endRound() else self.current = self.pendingQueue:pop() end
|
||||||
self.current = self.pendingQueue:pop()
|
|
||||||
|
|
||||||
local char = Tree.level.characters[self.current]
|
local char = Tree.level.characters[self.current]
|
||||||
char:try(Tree.behaviors.ai, function(ai)
|
|
||||||
Tree.level.selector:lock()
|
Tree.level.selector:lock()
|
||||||
ai:makeTurn()(function()
|
char:try(Tree.behaviors.positioned, function(positioned)
|
||||||
Tree.level.selector:unlock()
|
Tree.level.camera:animateTo(positioned.position, 1500, easing.easeInOutCubic)(
|
||||||
self:next()
|
function()
|
||||||
end)
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -46,14 +46,6 @@ end
|
|||||||
|
|
||||||
function endTurnButton:onClick()
|
function endTurnButton:onClick()
|
||||||
Tree.level.turnOrder:next()
|
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
|
end
|
||||||
|
|
||||||
return function(values)
|
return function(values)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user