2021-04-10 17:14:41 +02:00
|
|
|
local Team = Object:extend()
|
|
|
|
|
|
|
|
local Emblem = require "game.modules.gui.emblem"
|
|
|
|
|
|
|
|
function Team:initTeam()
|
|
|
|
self.active = game.characters:getActiveCharacterData()
|
|
|
|
|
|
|
|
self.emblems = {}
|
|
|
|
for i, name in ipairs(game.characters.team) do
|
|
|
|
game.characters:loadSprite(self.assets, name)
|
|
|
|
self.emblems[i] = Emblem(game.characters.list[name], self.scene)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.activeVisible = game.characters.active
|
|
|
|
self.canChangeActive = true
|
|
|
|
end
|
|
|
|
|
2021-04-18 19:59:03 +02:00
|
|
|
function Team:updateActiveCharacter()
|
2021-04-19 18:04:29 +02:00
|
|
|
local everybodyIsKo = true
|
|
|
|
for id, name in ipairs(game.characters.team) do
|
|
|
|
if (game.characters.list[name].hp > 0) then
|
|
|
|
everybodyIsKo = false
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (everybodyIsKo) then
|
|
|
|
self.scene:gameover()
|
|
|
|
else
|
|
|
|
if ((self.active.hp == 0) and not game.difficulty:get("playerKoChar")) then
|
|
|
|
self:switchActiveCharacter()
|
|
|
|
end
|
2021-04-18 19:59:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-10 17:59:01 +02:00
|
|
|
function Team:getCurrentCharType()
|
|
|
|
return self.active.data.class
|
|
|
|
end
|
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
function Team:switchActiveCharacter()
|
|
|
|
if (self.canChangeActive) then
|
2021-04-18 19:59:03 +02:00
|
|
|
local count = game.characters:setActiveCharacter()
|
2021-04-10 17:43:10 +02:00
|
|
|
self.active = game.characters:getActiveCharacterData()
|
2021-04-10 17:14:41 +02:00
|
|
|
self.canChangeActive = false
|
|
|
|
self.tweens:newTimer(0.3, "changeCharacter")
|
2021-04-18 19:59:03 +02:00
|
|
|
self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + count}, "inQuad")
|
2021-04-10 17:14:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Team:endCharacterSwitchAnimation()
|
|
|
|
self.canChangeActive = true
|
|
|
|
self.activeVisible = game.characters.active
|
|
|
|
self:updateCurrentCharset()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Team:drawEmblems(x, y)
|
|
|
|
for i,emblem in ipairs(self.emblems) do
|
|
|
|
local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90
|
|
|
|
local rad = math.rad(angle)
|
|
|
|
local emblemX, emblemY = utils.math.lengthdir(18, rad)
|
|
|
|
emblem:draw(x + emblemX, y + emblemY)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return Team
|