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 TurnController = Object:extend()
|
||||||
|
|
||||||
local Player = require "scenes.battlesystem.controllers.player"
|
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"
|
local maputils = require "scenes.battlesystem.utils"
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ function TurnController:new(scene)
|
||||||
self.world = scene.world
|
self.world = scene.world
|
||||||
|
|
||||||
self.player = Player(self)
|
self.player = Player(self)
|
||||||
--self.ennemies = Ennemy(self)
|
self.ennemies = Ennemy(self)
|
||||||
|
|
||||||
self.isActive = false
|
self.isActive = false
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ function TurnController:new(scene)
|
||||||
self.turns.isFinished = true
|
self.turns.isFinished = true
|
||||||
self.turns.changeBattler = true
|
self.turns.changeBattler = true
|
||||||
self.actionList = {}
|
self.actionList = {}
|
||||||
|
|
||||||
|
self.currentFighter = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:startBattle()
|
function TurnController:startBattle()
|
||||||
|
@ -30,10 +32,8 @@ end
|
||||||
|
|
||||||
function TurnController:update(dt)
|
function TurnController:update(dt)
|
||||||
if (self.isActive) then
|
if (self.isActive) then
|
||||||
if (self.currentlyPlaying == "heroes") then
|
if (self.currentFighter ~= nil) then
|
||||||
self.player:update(dt)
|
self.currentFighter:update(dt)
|
||||||
elseif (self.currentlyPlaying == "ennemies") then
|
|
||||||
--self.ennemies:update(dt)
|
|
||||||
else
|
else
|
||||||
self:nextAction()
|
self:nextAction()
|
||||||
end
|
end
|
||||||
|
@ -45,15 +45,15 @@ function TurnController:nextAction()
|
||||||
self:startNewTurn()
|
self:startNewTurn()
|
||||||
else
|
else
|
||||||
self.turns.current = self.turns.current + 1
|
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
|
end
|
||||||
self.scene.hud:moveBattleCursor(self.turns.current)
|
--self.scene.hud:moveBattleCursor(self.turns.current)
|
||||||
|
|
||||||
self:startAction()
|
self:startAction()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:startNewTurn()
|
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.current = 1
|
||||||
self.turns.isFinished = false
|
self.turns.isFinished = false
|
||||||
self.turns.number = self.turns.number + 1
|
self.turns.number = self.turns.number + 1
|
||||||
|
@ -61,27 +61,24 @@ function TurnController:startNewTurn()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:calculateTurn()
|
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)
|
table.sort(self.actionList, maputils.sortBattlers)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:startAction()
|
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]
|
local nextAction = self.actionList[self.turns.current]
|
||||||
print(nextAction)
|
print(nextAction)
|
||||||
local nextActor = nextAction.actor
|
local nextFighter = nextAction.fighter
|
||||||
if (nextActor.isDestroyed == true) then
|
if (nextFighter.isDestroyed == true) then
|
||||||
-- On skipe le personnage s'il a été detruit
|
-- On skipe le personnage s'il a été detruit
|
||||||
self:nextAction()
|
self:nextAction()
|
||||||
else
|
else
|
||||||
if (nextActor.side == "heroes") then
|
self.currentFighter = nextFighter
|
||||||
self.player:setActive(nextActor)
|
core.debug:print("cbs/turns", "Activating " .. self.currentFighter.name)
|
||||||
self.currentlyPlaying = "heroes"
|
self.currentFighter:setActive()
|
||||||
elseif (nextActor.side == "ennemies") then
|
|
||||||
--self.ennemies:setActive(nextActor)
|
|
||||||
self.currentlyPlaying = "ennemies"
|
|
||||||
self.actionList[self.turns.current].actor:setActive()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,46 @@
|
||||||
local ControllerParent = Object:extend()
|
local FighterControllerParent = Object:extend()
|
||||||
|
|
||||||
function ControllerParent:new(owner)
|
function FighterControllerParent:new(turnSystem)
|
||||||
self.owner = owner
|
self.turnSystem = turnSystem
|
||||||
self.activeActor = nil;
|
self.world = turnSystem.world
|
||||||
self.startData = {}
|
self.list = {}
|
||||||
end
|
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
|
self.activeActor = activeActor
|
||||||
activeActor:setActive()
|
activeActor:setActive()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ControllerParent:update(dt)
|
function FighterControllerParent:update(dt)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ControllerParent:endAction()
|
function FighterControllerParent:endAction()
|
||||||
self.owner:nextAction()
|
self.owner:nextAction()
|
||||||
end
|
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)
|
local Character = require "scenes.battlesystem.controllers.fighters.character"
|
||||||
self.owner = owner
|
|
||||||
self.activeActor = nil;
|
function HeroFighterController:new(owner)
|
||||||
self.startData = {}
|
self.super.new(self, owner)
|
||||||
|
self:initHeroes()
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlayerController:setActive(activeActor)
|
function HeroFighterController:initHeroes()
|
||||||
self.activeActor = activeActor
|
for i, hero in ipairs(game.characters.team) do
|
||||||
activeActor:setActive()
|
self:add(Character(self, hero, i))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlayerController:update(dt)
|
return HeroFighterController
|
||||||
|
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in a new issue