Ajout des derniers développement #1
7 changed files with 218 additions and 53 deletions
|
@ -0,0 +1,21 @@
|
|||
local FighterControllerParent = require "scenes.battlesystem.controllers.parent"
|
||||
local EnnemyController = FighterControllerParent:extend()
|
||||
|
||||
local Villain = require "scenes.battlesystem.controllers.fighters.villain"
|
||||
|
||||
function EnnemyController:new(owner)
|
||||
self.super.new(self, owner)
|
||||
self:initVillains()
|
||||
end
|
||||
|
||||
function EnnemyController:initVillains()
|
||||
self:addVillain("motobug")
|
||||
self:addVillain("motobug")
|
||||
self:addVillain("motobug")
|
||||
end
|
||||
|
||||
function EnnemyController:addVillain(name)
|
||||
self:add(Villain(self, name, self:count() + 1))
|
||||
end
|
||||
|
||||
return EnnemyController
|
|
@ -0,0 +1,29 @@
|
|||
local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
|
||||
local HeroFighter = FighterParent:extend()
|
||||
|
||||
local POSITIONS = {3, 1, 5}
|
||||
local HEROES_LINE = 3;
|
||||
|
||||
function HeroFighter:new(owner, character, id)
|
||||
self.name = character
|
||||
self.super.new(self, owner, true, id)
|
||||
end
|
||||
|
||||
function HeroFighter:getAbstract()
|
||||
return game.characters.list[self.name]
|
||||
end
|
||||
|
||||
function HeroFighter:createActor()
|
||||
local x, y = HEROES_LINE, POSITIONS[self.id]
|
||||
return self.world.obj.Hero(self.world, x, y, self)
|
||||
end
|
||||
|
||||
function HeroFighter:startAction()
|
||||
|
||||
end
|
||||
|
||||
function HeroFighter:endAction()
|
||||
|
||||
end
|
||||
|
||||
return HeroFighter
|
|
@ -0,0 +1,76 @@
|
|||
local FighterParent = Object:extend()
|
||||
|
||||
local counter = 0
|
||||
|
||||
function FighterParent:new(owner, isHero, id)
|
||||
self.owner = owner
|
||||
self.turnSystem = owner.turnSystem
|
||||
self.world = owner.world
|
||||
self.isHero = isHero
|
||||
|
||||
-- Note : l'ID est ici relatif à chaque quand, il n'est donc pas unique,
|
||||
-- ce qui est unique étant le combo id + isHero
|
||||
self.id = id
|
||||
|
||||
self.abstract = self:getAbstract()
|
||||
self.actor = self:createActor()
|
||||
|
||||
self.isActive = false
|
||||
end
|
||||
|
||||
function FighterParent:getAbstract()
|
||||
return {}
|
||||
end
|
||||
|
||||
function FighterParent:createActor()
|
||||
return {}
|
||||
end
|
||||
|
||||
function FighterParent:update(dt)
|
||||
counter = counter + dt
|
||||
if (counter > 5) then
|
||||
counter = 0
|
||||
self:setInactive()
|
||||
end
|
||||
end
|
||||
|
||||
function FighterParent:setActive()
|
||||
counter = 0
|
||||
self.isActive = true
|
||||
self:startAction()
|
||||
end
|
||||
|
||||
function FighterParent:setInactive()
|
||||
self.isActive = false
|
||||
self.turnSystem:nextAction()
|
||||
end
|
||||
|
||||
function FighterParent:getNbrActionPerTurn()
|
||||
return self.abstract.turns
|
||||
end
|
||||
|
||||
function FighterParent:getStats()
|
||||
return self.abstract:getStats()
|
||||
end
|
||||
|
||||
function FighterParent:startAction()
|
||||
|
||||
end
|
||||
|
||||
function FighterParent:getUniqueIdentificator()
|
||||
local side = 1
|
||||
if (isHero == false) then
|
||||
side = -1
|
||||
end
|
||||
return self.id * side
|
||||
end
|
||||
|
||||
function FighterParent:getNonUniqueIdentificator()
|
||||
return self.id
|
||||
end
|
||||
|
||||
function FighterParent:canFight()
|
||||
return true
|
||||
end
|
||||
|
||||
return FighterParent
|
|
@ -0,0 +1,29 @@
|
|||
local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
|
||||
local VillainFighter = FighterParent:extend()
|
||||
|
||||
local POSITIONS = {3, 1, 5}
|
||||
local ENNEMY_LINE = 10;
|
||||
|
||||
function VillainFighter:new(owner, ennemy, id)
|
||||
self.name = ennemy
|
||||
self.super.new(self, owner, false, id)
|
||||
end
|
||||
|
||||
function VillainFighter:getAbstract()
|
||||
return game.ennemies:getEnnemyData(self.name)
|
||||
end
|
||||
|
||||
function VillainFighter:createActor()
|
||||
local x, y = ENNEMY_LINE, POSITIONS[self.id]
|
||||
return self.world.obj.Ennemy(self.world, x, y, self)
|
||||
end
|
||||
|
||||
function VillainFighter:startAction()
|
||||
|
||||
end
|
||||
|
||||
function VillainFighter:endAction()
|
||||
|
||||
end
|
||||
|
||||
return VillainFighter
|
|
@ -1,7 +1,7 @@
|
|||
local TurnController = Object:extend()
|
||||
|
||||
local Player = require "scenes.battlesystem.controllers.player"
|
||||
local Ennemy = require "scenes.battlesystem.controllers.player"
|
||||
local Ennemy = require "scenes.battlesystem.controllers.ennemy"
|
||||
|
||||
local maputils = require "scenes.battlesystem.utils"
|
||||
|
||||
|
@ -10,7 +10,7 @@ function TurnController:new(scene)
|
|||
self.world = scene.world
|
||||
|
||||
self.player = Player(self)
|
||||
--self.ennemies = Ennemy(self)
|
||||
self.ennemies = Ennemy(self)
|
||||
|
||||
self.isActive = false
|
||||
|
||||
|
@ -22,6 +22,8 @@ function TurnController:new(scene)
|
|||
self.turns.isFinished = true
|
||||
self.turns.changeBattler = true
|
||||
self.actionList = {}
|
||||
|
||||
self.currentFighter = nil
|
||||
end
|
||||
|
||||
function TurnController:startBattle()
|
||||
|
@ -30,10 +32,8 @@ 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)
|
||||
if (self.currentFighter ~= nil) then
|
||||
self.currentFighter:update(dt)
|
||||
else
|
||||
self:nextAction()
|
||||
end
|
||||
|
@ -45,15 +45,15 @@ function TurnController:nextAction()
|
|||
self:startNewTurn()
|
||||
else
|
||||
self.turns.current = self.turns.current + 1
|
||||
core.debug:print("cbs/world", "switching to next action")
|
||||
core.debug:print("cbs/turns", "switching to next action")
|
||||
end
|
||||
self.scene.hud:moveBattleCursor(self.turns.current)
|
||||
--self.scene.hud:moveBattleCursor(self.turns.current)
|
||||
|
||||
self:startAction()
|
||||
end
|
||||
|
||||
function TurnController:startNewTurn()
|
||||
core.debug:print("cbs/world", "New Turn Starting")
|
||||
core.debug:print("cbs/turns", "New Turn Starting")
|
||||
self.turns.current = 1
|
||||
self.turns.isFinished = false
|
||||
self.turns.number = self.turns.number + 1
|
||||
|
@ -61,27 +61,24 @@ function TurnController:startNewTurn()
|
|||
end
|
||||
|
||||
function TurnController:calculateTurn()
|
||||
self.actionList = self.world:generateActionList()
|
||||
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/world", "Starting action " .. self.turns.current)
|
||||
core.debug:print("cbs/turns", "Starting action " .. self.turns.current)
|
||||
local nextAction = self.actionList[self.turns.current]
|
||||
print(nextAction)
|
||||
local nextActor = nextAction.actor
|
||||
if (nextActor.isDestroyed == true) then
|
||||
local nextFighter = nextAction.fighter
|
||||
if (nextFighter.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
|
||||
self.currentFighter = nextFighter
|
||||
core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name)
|
||||
self.currentFighter:setActive()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,22 +1,46 @@
|
|||
local ControllerParent = Object:extend()
|
||||
local FighterControllerParent = Object:extend()
|
||||
|
||||
function ControllerParent:new(owner)
|
||||
self.owner = owner
|
||||
self.activeActor = nil;
|
||||
self.startData = {}
|
||||
function FighterControllerParent:new(turnSystem)
|
||||
self.turnSystem = turnSystem
|
||||
self.world = turnSystem.world
|
||||
self.list = {}
|
||||
end
|
||||
|
||||
function ControllerParent:setActive(activeActor)
|
||||
function FighterControllerParent:add(fighter)
|
||||
table.insert(self.list, fighter)
|
||||
end
|
||||
|
||||
function FighterControllerParent:count()
|
||||
return #self.list
|
||||
end
|
||||
|
||||
function FighterControllerParent:setActive(activeActor)
|
||||
self.activeActor = activeActor
|
||||
activeActor:setActive()
|
||||
end
|
||||
|
||||
function ControllerParent:update(dt)
|
||||
function FighterControllerParent:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function ControllerParent:endAction()
|
||||
function FighterControllerParent:endAction()
|
||||
self.owner:nextAction()
|
||||
end
|
||||
|
||||
return PlayerController
|
||||
function FighterControllerParent:putActions(actionList)
|
||||
for i, fighter in ipairs(self.list) do
|
||||
|
||||
if fighter:canFight() then
|
||||
for i=1, fighter:getNbrActionPerTurn() do
|
||||
local action = {}
|
||||
action.fighter = fighter
|
||||
action.number = i
|
||||
table.insert(actionList, action)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return FighterControllerParent
|
||||
|
|
|
@ -1,28 +1,17 @@
|
|||
local PlayerController = Object:extend()
|
||||
local FighterControllerParent = require "scenes.battlesystem.controllers.parent"
|
||||
local HeroFighterController = FighterControllerParent:extend()
|
||||
|
||||
function PlayerController:new(owner)
|
||||
self.owner = owner
|
||||
self.activeActor = nil;
|
||||
self.startData = {}
|
||||
local Character = require "scenes.battlesystem.controllers.fighters.character"
|
||||
|
||||
function HeroFighterController:new(owner)
|
||||
self.super.new(self, owner)
|
||||
self:initHeroes()
|
||||
end
|
||||
|
||||
function PlayerController:setActive(activeActor)
|
||||
self.activeActor = activeActor
|
||||
activeActor:setActive()
|
||||
function HeroFighterController:initHeroes()
|
||||
for i, hero in ipairs(game.characters.team) do
|
||||
self:add(Character(self, hero, i))
|
||||
end
|
||||
end
|
||||
|
||||
function PlayerController:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function PlayerController:setStartData(x, y, direction)
|
||||
self.startData.x = x
|
||||
self.startData.y = y
|
||||
self.startData.direction = direction
|
||||
end
|
||||
|
||||
function PlayerController:getStartData()
|
||||
return self.startData.x, self.startData.y, self.startData.direction
|
||||
end
|
||||
|
||||
return PlayerController
|
||||
return HeroFighterController
|
||||
|
|
Loading…
Reference in a new issue