chore: extract hp management from actor
This commit is contained in:
parent
2e38b31dea
commit
bf23dd2056
7 changed files with 65 additions and 49 deletions
|
@ -32,12 +32,35 @@ function AbstractMobParent:createSkills()
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- LIFE FUNCTIONS
|
||||||
|
-- Handle HP and stuff like that
|
||||||
|
|
||||||
function AbstractMobParent:initLife()
|
function AbstractMobParent:initLife()
|
||||||
self.hp = self.stats.hpmax
|
self.hp = self.stats.hpmax
|
||||||
self.pp = self.stats.ppmax
|
self.pp = self.stats.ppmax
|
||||||
self.status = 0
|
self.status = 0
|
||||||
end
|
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()
|
function AbstractMobParent:getStats()
|
||||||
return self.stats
|
return self.stats
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,12 +9,6 @@ function Ennemy:new(world, x, y, owner)
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
|
|
||||||
self.actionPerTurn = 2
|
self.actionPerTurn = 2
|
||||||
|
|
||||||
self:receiveDatas()
|
|
||||||
self.hp = self.data.stats.hpmax
|
|
||||||
self.pp = self.data.stats.ppmax
|
|
||||||
|
|
||||||
self.shownHP = self.hp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Ennemy:draw()
|
function Ennemy:draw()
|
||||||
|
@ -24,29 +18,13 @@ function Ennemy:draw()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
|
||||||
self.owner:drawHUD(x - 14, y - 38)
|
self.owner:drawHUD(x - 14, y - 38)
|
||||||
|
|
||||||
if (self.isSelected) then
|
if (self.isSelected) then
|
||||||
local height = 32
|
local height = 32
|
||||||
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
|
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
|
||||||
end
|
end
|
||||||
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()
|
function Ennemy:getStats()
|
||||||
return self.data.stats
|
return self.data.stats
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,29 +37,6 @@ function Hero:initCharacter(charid)
|
||||||
self.turnAction = nil
|
self.turnAction = nil
|
||||||
end
|
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
|
-- ACTIVITY FUNCTION
|
||||||
-- Function to set or unset activity to the character
|
-- Function to set or unset activity to the character
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,17 @@ function HeroFighter:finishAction()
|
||||||
self:setInactive()
|
self:setInactive()
|
||||||
end
|
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
|
-- DRAW FUNCTIONS
|
||||||
function HeroFighter:drawIcon(x, y)
|
function HeroFighter:drawIcon(x, y)
|
||||||
local iconID = 1
|
local iconID = 1
|
||||||
|
|
|
@ -17,6 +17,27 @@ function FighterParent:new(owner, isHero, id)
|
||||||
self.actor = self:createActor()
|
self.actor = self:createActor()
|
||||||
|
|
||||||
self.isActive = false
|
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
|
end
|
||||||
|
|
||||||
function FighterParent:getAbstract()
|
function FighterParent:getAbstract()
|
||||||
|
@ -75,7 +96,7 @@ function FighterParent:getNonUniqueIdentificator()
|
||||||
end
|
end
|
||||||
|
|
||||||
function FighterParent:canFight()
|
function FighterParent:canFight()
|
||||||
return true
|
return self.isAlive
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
|
|
|
@ -35,6 +35,12 @@ function VillainFighter:endAction()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- LIFE FUNCTIONS
|
||||||
|
function VillainFighter:setHP(value, relative)
|
||||||
|
VillainFighter.super.setHP(self, value, relative)
|
||||||
|
self.hpbar:setHP(self.abstract.hp)
|
||||||
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
function VillainFighter:drawIcon(x, y)
|
function VillainFighter:drawIcon(x, y)
|
||||||
love.graphics.setColor(1, 0, 0, 1)
|
love.graphics.setColor(1, 0, 0, 1)
|
||||||
|
|
|
@ -26,11 +26,11 @@ function StatusBar:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatusBar:updateHP()
|
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
|
end
|
||||||
|
|
||||||
function StatusBar:updatePP()
|
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
|
end
|
||||||
|
|
||||||
function StatusBar:drawEmblem(x, y)
|
function StatusBar:drawEmblem(x, y)
|
||||||
|
|
Loading…
Reference in a new issue