101 lines
2.6 KiB
Lua
101 lines
2.6 KiB
Lua
local TurnController = Object:extend()
|
|
|
|
local Player = require "scenes.battlesystem.controllers.player"
|
|
local Ennemy = require "scenes.battlesystem.controllers.player"
|
|
|
|
local maputils = require "scenes.battlesystem.utils"
|
|
|
|
function TurnController:new(scene)
|
|
self.scene = scene
|
|
self.world = scene.world
|
|
|
|
self.player = Player(self)
|
|
--self.ennemies = Ennemy(self)
|
|
|
|
self.isActive = false
|
|
|
|
self.currentlyPlaying = ""
|
|
|
|
self.turns = {}
|
|
self.turns.current = 1
|
|
self.turns.number = 0
|
|
self.turns.isFinished = true
|
|
self.turns.changeBattler = true
|
|
self.actionList = {}
|
|
end
|
|
|
|
function TurnController:startBattle()
|
|
self.isActive = true
|
|
end
|
|
|
|
function TurnController:update(dt)
|
|
if (self.isActive) then
|
|
if (self.currentlyPlaying == "heroes") then
|
|
self.player:update(dt)
|
|
elseif (self.currentlyPlaying == "ennemies") then
|
|
--self.ennemies:update(dt)
|
|
else
|
|
self:nextAction()
|
|
end
|
|
end
|
|
end
|
|
|
|
function TurnController:nextAction()
|
|
if (self.turns.isFinished) or (self.turns.current >= #self.actionList) then
|
|
self:startNewTurn()
|
|
else
|
|
self.turns.current = self.turns.current + 1
|
|
core.debug:print("cbs/world", "switching to next action")
|
|
end
|
|
self.scene.hud:moveBattleCursor(self.turns.current)
|
|
|
|
self:startAction()
|
|
end
|
|
|
|
function TurnController:startNewTurn()
|
|
core.debug:print("cbs/world", "New Turn Starting")
|
|
self.turns.current = 1
|
|
self.turns.isFinished = false
|
|
self.turns.number = self.turns.number + 1
|
|
self:calculateTurn()
|
|
end
|
|
|
|
function TurnController:calculateTurn()
|
|
self.actionList = self.world:generateActionList()
|
|
table.sort(self.actionList, maputils.sortBattlers)
|
|
end
|
|
|
|
function TurnController:startAction()
|
|
core.debug:print("cbs/world", "Starting action " .. self.turns.current)
|
|
local nextAction = self.actionList[self.turns.current]
|
|
print(nextAction)
|
|
local nextActor = nextAction.actor
|
|
if (nextActor.isDestroyed == true) then
|
|
-- On skipe le personnage s'il a été detruit
|
|
self:nextAction()
|
|
else
|
|
if (nextActor.side == "heroes") then
|
|
self.player:setActive(nextActor)
|
|
self.currentlyPlaying = "heroes"
|
|
elseif (nextActor.side == "ennemies") then
|
|
--self.ennemies:setActive(nextActor)
|
|
self.currentlyPlaying = "ennemies"
|
|
self.actionList[self.turns.current].actor:setActive()
|
|
end
|
|
end
|
|
end
|
|
|
|
function TurnController:endAction()
|
|
self.currentlyPlaying = ""
|
|
end
|
|
|
|
function TurnController:drawTurnList(x, y)
|
|
|
|
end
|
|
|
|
function TurnController:sendSignalToCurrentBattler(signal, subSignal)
|
|
self.actionList[self.turns.current].actor:receiveSignal(signal, subSignal)
|
|
end
|
|
|
|
|
|
return TurnController
|