sonic-radiance/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua

151 lines
3.6 KiB
Lua
Raw Normal View History

local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
local HeroFighter = FighterParent:extend()
local StatusBar = require "game.modules.gui.statusbar"
2020-07-19 21:41:14 +02:00
local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection"
local actionList = require "scenes.battlesystem.controllers.fighters.systems.actions"
local POSITIONS = {3, 1, 5}
2020-07-25 17:50:44 +02:00
local HEROES_LINE = 2;
local HUDBASE = 8
local HUDSIZE = 91
function HeroFighter:new(owner, character, id)
self.name = character
self.super.new(self, owner, true, id)
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
self.selection = nil
2020-08-06 19:10:54 +02:00
self.exp = self.abstract.exp
end
function HeroFighter:updateAssets(dt)
self.statusbar:update(dt)
end
function HeroFighter:update(dt)
HeroFighter.super.update(self, dt)
2020-07-19 21:41:14 +02:00
if (self.selection ~= nil) then
self.selection:update(dt)
end
end
function HeroFighter:getAbstract()
return game.characters.list[self.name]
end
function HeroFighter:createActor()
local x, y = HEROES_LINE, ((self.id-1)*(4/(#game.characters.team-1))+1)
return self.world.obj.Hero(self.world, x, y, self)
end
function HeroFighter:startAction()
core.debug:print("cbs/heroFighter", "launching the action menu")
self.action = nil
2020-07-24 19:55:11 +02:00
self:talk("turnstart")
self.turnSystem.scene.menu:set( self )
end
function HeroFighter:endAction()
end
-- Basic actions
function HeroFighter:doNothing()
self:setInactive()
end
function HeroFighter:doBasicAction(action)
self.action = actionList[action](self)
self:verifyTargets()
end
2020-08-22 23:10:22 +02:00
function HeroFighter:useItem(category, item)
self.action = actionList["item"](self, category, item)
2020-07-20 12:24:26 +02:00
self:verifyTargets()
end
function HeroFighter:useSkill(skill)
self.action = actionList["skill"](self, skill)
self:verifyTargets()
end
function HeroFighter:verifyTargets()
local needTarget, targetEnnemies = self.action:needTarget()
if (needTarget) then
if (targetEnnemies) then
self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies, true)
else
self.selection = SelectionSystem(self, self.owner, false)
end
else
self.action:start()
end
end
2020-07-19 21:41:14 +02:00
function HeroFighter:attack()
self:doBasicAction("attack")
2020-07-19 21:41:14 +02:00
end
function HeroFighter:receiveTarget(target)
self.selection = nil
if (self.action ~= nil) then
self.action:setTarget(target)
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
-- 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
-- DRAW FUNCTIONS
function HeroFighter:drawIcon(x, y)
local iconID = self.abstract.data.icon
self.assets.tileset["charicons"]:drawTile(iconID, x, y)
end
function HeroFighter:drawHUD()
local boxSize = 424 / 4
local x = (self.id-0.5)*boxSize
local y = self.turnSystem.hud:getPlayerHUDPosition()
self.statusbar:draw(x - HUDSIZE/2, y)
end
return HeroFighter