sonic-radiance/sonic-radiance.love/scenes/battlesystem/controllers/init.lua

98 lines
2.4 KiB
Lua

local TurnController = Object:extend()
local Player = require "scenes.battlesystem.controllers.player"
local Ennemy = require "scenes.battlesystem.controllers.ennemy"
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 = {}
self.currentFighter = nil
end
function TurnController:startBattle()
self.isActive = true
end
function TurnController:update(dt)
if (self.isActive) then
if (self.currentFighter ~= nil) then
self.currentFighter: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/turns", "switching to next action")
end
--self.scene.hud:moveBattleCursor(self.turns.current)
self:startAction()
end
function TurnController:startNewTurn()
core.debug:print("cbs/turns", "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.player:putActions(self.actionList)
self.ennemies:putActions(self.actionList)
table.sort(self.actionList, maputils.sortBattlers)
end
function TurnController:startAction()
core.debug:print("cbs/turns", "Starting action " .. self.turns.current)
local nextAction = self.actionList[self.turns.current]
print(nextAction)
local nextFighter = nextAction.fighter
if (nextFighter.isDestroyed == true) then
-- On skipe le personnage s'il a été detruit
self:nextAction()
else
self.currentFighter = nextFighter
core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name)
self.currentFighter:setActive()
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