2020-07-19 15:07:35 +02:00
|
|
|
local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
|
|
|
|
local HeroFighter = FighterParent:extend()
|
|
|
|
|
2020-08-03 09:11:31 +02:00
|
|
|
local StatusBar = require "game.modules.gui.statusbar"
|
2020-07-19 21:41:14 +02:00
|
|
|
local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection"
|
2020-07-19 22:38:59 +02:00
|
|
|
local actionList = require "scenes.battlesystem.controllers.fighters.systems.actions"
|
2020-07-19 16:20:57 +02:00
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
local POSITIONS = {3, 1, 5}
|
2020-07-25 17:50:44 +02:00
|
|
|
local HEROES_LINE = 2;
|
2020-07-19 15:07:35 +02:00
|
|
|
|
2020-08-03 09:24:52 +02:00
|
|
|
local HUDBASE = 8
|
2020-08-04 18:50:36 +02:00
|
|
|
local HUDSIZE = 91
|
2020-08-03 09:24:52 +02:00
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
function HeroFighter:new(owner, character, id)
|
|
|
|
self.name = character
|
|
|
|
self.super.new(self, owner, true, id)
|
2020-07-19 16:20:57 +02:00
|
|
|
|
2020-08-03 09:24:52 +02:00
|
|
|
self.statusbar = StatusBar(self.abstract, self.turnSystem.scene)
|
2020-07-24 19:55:11 +02:00
|
|
|
self:initVoices()
|
2020-07-19 21:41:14 +02:00
|
|
|
|
2020-07-19 22:38:59 +02:00
|
|
|
self.action = nil
|
2020-07-19 21:41:14 +02:00
|
|
|
|
|
|
|
self.selection = nil
|
2020-07-19 16:20:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:updateAssets(dt)
|
|
|
|
self.statusbar:update(dt)
|
2020-07-19 22:38:59 +02:00
|
|
|
|
|
|
|
if (self.action ~= nil) then
|
|
|
|
if (self.action.isStarted) then
|
|
|
|
self.action:update(dt)
|
|
|
|
end
|
|
|
|
end
|
2020-07-19 15:07:35 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
function HeroFighter:update(dt)
|
2020-07-19 21:41:14 +02:00
|
|
|
if (self.selection ~= nil) then
|
|
|
|
self.selection:update(dt)
|
|
|
|
end
|
2020-07-19 18:09:53 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
function HeroFighter:getAbstract()
|
|
|
|
return game.characters.list[self.name]
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:createActor()
|
2020-08-04 18:50:36 +02:00
|
|
|
local x, y = HEROES_LINE, ((self.id-1)*(4/(#game.characters.team-1))+1)
|
2020-07-19 15:07:35 +02:00
|
|
|
return self.world.obj.Hero(self.world, x, y, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:startAction()
|
2020-07-19 18:09:53 +02:00
|
|
|
core.debug:print("cbs/heroFighter", "launching the action menu")
|
2020-07-19 22:38:59 +02:00
|
|
|
self.action = nil
|
2020-07-24 19:55:11 +02:00
|
|
|
self:talk("turnstart")
|
2020-07-19 18:09:53 +02:00
|
|
|
self.turnSystem.scene.menu:set( self )
|
2020-07-19 15:07:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:endAction()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
-- Basic actions
|
|
|
|
function HeroFighter:doNothing()
|
|
|
|
self:setInactive()
|
|
|
|
end
|
|
|
|
|
2020-07-19 22:38:59 +02:00
|
|
|
function HeroFighter:doBasicAction(action)
|
|
|
|
self.action = actionList[action](self)
|
|
|
|
self:verifyTargets()
|
|
|
|
end
|
|
|
|
|
2020-07-20 12:24:26 +02:00
|
|
|
function HeroFighter:useItem(item)
|
|
|
|
self.action = actionList["item"](self, item)
|
|
|
|
self:verifyTargets()
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:useSkill(skill)
|
|
|
|
self.action = actionList["skill"](self, skill)
|
|
|
|
self:verifyTargets()
|
|
|
|
end
|
|
|
|
|
2020-07-19 22:38:59 +02:00
|
|
|
function HeroFighter:verifyTargets()
|
|
|
|
local needTarget, targetEnnemies = self.action:needTarget()
|
|
|
|
|
|
|
|
if (needTarget) then
|
|
|
|
if (targetEnnemies) then
|
2020-07-25 12:09:50 +02:00
|
|
|
self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies, true)
|
2020-07-19 22:38:59 +02:00
|
|
|
else
|
2020-07-25 12:09:50 +02:00
|
|
|
self.selection = SelectionSystem(self, self.owner, false)
|
2020-07-19 22:38:59 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
self.action:start()
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-07-19 21:41:14 +02:00
|
|
|
function HeroFighter:attack()
|
2020-07-19 22:38:59 +02:00
|
|
|
self:doBasicAction("attack")
|
2020-07-19 21:41:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:receiveTarget(target)
|
|
|
|
self.selection = nil
|
2020-07-19 22:38:59 +02:00
|
|
|
if (self.action ~= nil) then
|
2020-07-24 21:54:12 +02:00
|
|
|
self.action:setTarget(target)
|
2020-07-19 22:38:59 +02:00
|
|
|
self.action:start()
|
|
|
|
end
|
2020-07-19 21:41:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:goBackToMenu()
|
|
|
|
self.owner.turnSystem.scene.menusystem:activate()
|
|
|
|
self.selection = nil
|
|
|
|
end
|
|
|
|
|
2020-07-19 22:38:59 +02:00
|
|
|
function HeroFighter:finishAction()
|
2020-07-25 11:38:59 +02:00
|
|
|
self.action = nil
|
2020-07-19 22:38:59 +02:00
|
|
|
self:setInactive()
|
|
|
|
end
|
|
|
|
|
2020-07-24 19:49:24 +02:00
|
|
|
-- LIFE functions
|
|
|
|
function HeroFighter:setHP(value, relative)
|
|
|
|
HeroFighter.super.setHP(self, value, relative)
|
|
|
|
self.statusbar:updateHP()
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:setPP(value, relative)
|
|
|
|
HeroFighter.super.setPP(self, value, relative)
|
|
|
|
self.statusbar:updatePP()
|
|
|
|
end
|
|
|
|
|
2020-07-24 19:55:11 +02:00
|
|
|
-- VOICE SYSTEM
|
|
|
|
|
|
|
|
function HeroFighter:initVoices()
|
|
|
|
self:addVoiceEffect("move")
|
|
|
|
self:addVoiceEffect("turnstart")
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:addVoiceEffect(name)
|
|
|
|
local completename = self.name .. "_" .. name
|
|
|
|
local path = "datas/gamedata/characters/" .. self.name .. "/voices/" .. name .. ".wav"
|
|
|
|
self.assets:newSFX(completename, path)
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:talk(name)
|
|
|
|
local completename = self.name .. "_" .. name
|
2020-08-02 21:00:09 +02:00
|
|
|
self.assets.sfx[completename]:play()
|
2020-07-24 19:55:11 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 16:20:57 +02:00
|
|
|
-- DRAW FUNCTIONS
|
|
|
|
function HeroFighter:drawIcon(x, y)
|
2020-08-02 16:43:15 +02:00
|
|
|
local iconID = self.abstract.data.icon
|
2020-07-19 16:20:57 +02:00
|
|
|
self.assets.tileset["charicons"]:drawTile(iconID, x, y)
|
|
|
|
end
|
|
|
|
|
|
|
|
function HeroFighter:drawHUD()
|
2020-08-04 18:50:36 +02:00
|
|
|
local boxSize = 424 / 4
|
|
|
|
local x = (self.id-0.5)*boxSize
|
2020-08-03 09:24:52 +02:00
|
|
|
local y = self.turnSystem.hud:getPlayerHUDPosition()
|
2020-08-04 18:50:36 +02:00
|
|
|
self.statusbar:draw(x - HUDSIZE/2, y)
|
2020-07-19 16:20:57 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
return HeroFighter
|