diff --git a/sonic-radiance.love/game/abstractmobs/parent.lua b/sonic-radiance.love/game/abstractmobs/parent.lua index 4d64fa1..61c2e0a 100644 --- a/sonic-radiance.love/game/abstractmobs/parent.lua +++ b/sonic-radiance.love/game/abstractmobs/parent.lua @@ -32,12 +32,35 @@ function AbstractMobParent:createSkills() return {} end +-- LIFE FUNCTIONS +-- Handle HP and stuff like that + function AbstractMobParent:initLife() self.hp = self.stats.hpmax self.pp = self.stats.ppmax self.status = 0 end +function AbstractMobParent:setHP(newHP, relative) + if (relative) then + self.hp = self.hp + newHP + else + self.hp = newHP + end +end + +function AbstractMobParent:setPP(newPP, relative) + if (relative) then + self.pp = self.pp + newPP + else + self.pp = newPP + end +end + +function AbstractMobParent:isAlive() + return (self.hp > 0) +end + function AbstractMobParent:getStats() return self.stats end diff --git a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua index 742767a..cd30f60 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua @@ -9,12 +9,6 @@ function Ennemy:new(world, x, y, owner) self.owner = owner self.actionPerTurn = 2 - - self:receiveDatas() - self.hp = self.data.stats.hpmax - self.pp = self.data.stats.ppmax - - self.shownHP = self.hp end function Ennemy:draw() @@ -24,29 +18,13 @@ function Ennemy:draw() love.graphics.setColor(1, 1, 1, 1) self.owner:drawHUD(x - 14, y - 38) - + if (self.isSelected) then local height = 32 self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32) end end -function Ennemy:receiveDatas() - self.data = game.ennemies:getEnnemyData(self.owner.name) -end - -function Ennemy:setHP(value, relative) - if (relative) then - value = self.hp + value - end - - self.hp = value - self.tweens:newTween(0, 0.1, {shownHP = self.hp}, 'inCubic') - if (self.hp <= 0) then - self:destroy() - end -end - function Ennemy:getStats() return self.data.stats end diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 6133202..d81e195 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -37,29 +37,6 @@ function Hero:initCharacter(charid) self.turnAction = nil end -function Hero:getStats() - return game.characters.list[self.owner.name].stats -end - -function Hero:setHP(value, relative) - if relative == true then - value = game.characters.list[self.owner.name].stats.hp + value - end - - game.characters.list[self.owner.name].stats.hp = value - --self.statusbar:updateHP() -end - -function Hero:setPP(value, relative) - if relative == true then - value = game.characters.list[self.owner.name].stats.pp + value - end - - game.characters.list[self.owner.name].stats.pp = value - --self.statusbar:updatePP() -end - - -- ACTIVITY FUNCTION -- Function to set or unset activity to the character diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua index ce7616b..39c5bcc 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua @@ -109,6 +109,17 @@ function HeroFighter:finishAction() self:setInactive() 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 + -- DRAW FUNCTIONS function HeroFighter:drawIcon(x, y) local iconID = 1 diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index 6489a4d..1e7bb52 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -17,6 +17,27 @@ function FighterParent:new(owner, isHero, id) self.actor = self:createActor() self.isActive = false + self.isAlive = true +end + +-- LIFE handling functions + +function FighterParent:setHP(value, relative) + self.abstract:setHP(value, relative) +end + +function FighterParent:setPP(value, relative) + self.abstract:setPP(value, relative) +end + +function FighterParent:applyDeath() + if (self.hp <= 0 and self.isAlive) then + self:die() + end +end + +function FighterParent:die() + self.isAlive = false end function FighterParent:getAbstract() @@ -75,7 +96,7 @@ function FighterParent:getNonUniqueIdentificator() end function FighterParent:canFight() - return true + return self.isAlive end -- DRAW FUNCTIONS diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua index c8a9c6b..3fa98cc 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua @@ -35,6 +35,12 @@ function VillainFighter:endAction() end +-- LIFE FUNCTIONS +function VillainFighter:setHP(value, relative) + VillainFighter.super.setHP(self, value, relative) + self.hpbar:setHP(self.abstract.hp) +end + -- DRAW FUNCTIONS function VillainFighter:drawIcon(x, y) love.graphics.setColor(1, 0, 0, 1) diff --git a/sonic-radiance.love/scenes/battlesystem/gui/statusbar.lua b/sonic-radiance.love/scenes/battlesystem/gui/statusbar.lua index 9dd45ea..c7a3dbf 100644 --- a/sonic-radiance.love/scenes/battlesystem/gui/statusbar.lua +++ b/sonic-radiance.love/scenes/battlesystem/gui/statusbar.lua @@ -26,11 +26,11 @@ function StatusBar:update(dt) end function StatusBar:updateHP() - self.tweens:newTween(0, 0.3, {hp = game.characters.list[self.charid].stats.hp}, 'linear') + self.tweens:newTween(0, 0.3, {hp = self.abstract.hp}, 'linear') end function StatusBar:updatePP() - self.tweens:newTween(0, 0.3, {pp = game.characters.list[self.charid].stats.pp}, 'linear') + self.tweens:newTween(0, 0.3, {pp = self.abstract.pp}, 'linear') end function StatusBar:drawEmblem(x, y)