142 lines
3.2 KiB
Lua
142 lines
3.2 KiB
Lua
local ActorManager = Object:extend()
|
|
local entities = require "scenes.battlesystem.entities"
|
|
|
|
local POSITIONS = {
|
|
{x = 3, y = 4},
|
|
{x = 2, y = 2},
|
|
{x = 2, y = 6},
|
|
}
|
|
|
|
function ActorManager:new(controller)
|
|
self.controller = controller
|
|
|
|
self.turns = {}
|
|
self.turns.current = 1
|
|
self.turns.number = 1
|
|
self.turns.isFinished = true
|
|
self.turns.changeActor = true
|
|
self.actorlist = {}
|
|
self.actionlist = {}
|
|
|
|
self.cursor = self.turns.current
|
|
|
|
self.controller.assets:addTileset("charicons", "assets/sprites/characters/charicons")
|
|
for i, v in ipairs(game.characters.team) do
|
|
self:addCharacter(POSITIONS[i].x, POSITIONS[i].y, v)
|
|
end
|
|
|
|
self:addEnnemy(10, 3, "motobug")
|
|
self:addEnnemy(10, 5, "motobug")
|
|
|
|
--print("entities")
|
|
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
|
|
|
end
|
|
|
|
function ActorManager:generateActionList()
|
|
self.actionlist = {}
|
|
|
|
for i,v in ipairs(self.actorlist) do
|
|
for i=1, v.actionPerTurn do
|
|
local action = {}
|
|
action.actor = v
|
|
action.number = i
|
|
table.insert(self.actionlist, action)
|
|
end
|
|
end
|
|
end
|
|
|
|
function ActorManager:sendSignalToCurrentEntity()
|
|
self.actionlist[self.turns.current].actor:validateAction()
|
|
end
|
|
|
|
function ActorManager:addCharacter(x, y, id)
|
|
local char = entities.Character(self.controller, x, y, id)
|
|
|
|
table.insert(self.actorlist, char)
|
|
end
|
|
|
|
function ActorManager:addEnnemy(x, y, id)
|
|
local enn = entities.Ennemy(self.controller, x, y, id)
|
|
|
|
table.insert(self.actorlist, enn)
|
|
end
|
|
|
|
function ActorManager:switchActiveActor()
|
|
if (self.turns.isFinished) or (self.turns.current >= #self.actionlist) then
|
|
self.turns.current = 1
|
|
self.turns.isFinished = false
|
|
self.turns.number = self.turns.number + 1
|
|
self:recalculateTurns()
|
|
else
|
|
self.turns.current = self.turns.current + 1
|
|
end
|
|
|
|
self.actionlist[self.turns.current].actor:setActive()
|
|
self.turns.changeActor = false
|
|
end
|
|
|
|
local function sortActors(a, b)
|
|
local astats = a.actor:getStats()
|
|
local bstats = b.actor:getStats()
|
|
local aspeed = astats.speed / 1.5 * a.number
|
|
local bspeed = bstats.speed / 1.5 * b.number
|
|
|
|
|
|
if (aspeed == bspeed) then
|
|
if (a.actor.isHero == b.actor.isHero) then
|
|
return (a.actor.id > b.actor.id)
|
|
else
|
|
return a.actor.isHero
|
|
end
|
|
else
|
|
return (aspeed > bspeed)
|
|
end
|
|
end
|
|
|
|
function ActorManager:recalculateTurns()
|
|
self:generateActionList()
|
|
table.sort(self.actionlist, sortActors)
|
|
end
|
|
|
|
function ActorManager:update(dt)
|
|
|
|
if (self.turns.changeActor) then
|
|
self:switchActiveActor( )
|
|
end
|
|
|
|
local cursorSpeed = 16
|
|
|
|
if (self.turns.current == 1) then
|
|
cursorSpeed = 16 * 4
|
|
end
|
|
|
|
if math.abs(self.cursor - self.turns.current) > (cursorSpeed * dt) then
|
|
self.cursor = self.cursor - utils.math.sign(self.cursor - self.turns.current) * cursorSpeed * dt
|
|
else
|
|
self.cursor = self.turns.current
|
|
end
|
|
|
|
end
|
|
|
|
function ActorManager:countEnnemy()
|
|
local count = 0
|
|
|
|
for i,v in ipairs(self.entities) do
|
|
if (v.isEnnemy) then
|
|
count = count + 1
|
|
end
|
|
end
|
|
|
|
return count
|
|
end
|
|
|
|
function ActorManager:draw()
|
|
for i,v in ipairs(self.actionlist) do
|
|
v.actor:drawIcon(4 + (i-1)*(20), 6)
|
|
end
|
|
|
|
love.graphics.draw(self.cursorTexture, self.cursor * 20 - 6, 26, math.rad(-90), 1, 1, 4, 8)
|
|
end
|
|
|
|
return ActorManager
|