From 69d296b2f73ce0bff268b3afb04b0b4ba1ef92cb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 12 Mar 2021 18:51:35 +0100 Subject: [PATCH] feat: initial statuse system --- .../game/abstractmobs/parent.lua | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/game/abstractmobs/parent.lua b/sonic-radiance.love/game/abstractmobs/parent.lua index 489a242..e641128 100644 --- a/sonic-radiance.love/game/abstractmobs/parent.lua +++ b/sonic-radiance.love/game/abstractmobs/parent.lua @@ -4,6 +4,7 @@ function AbstractMobParent:new() self:initBasicElements() self.stats = self:createStats() self.skills = self:createSkills() + self.statuts = {} self:initLife() end @@ -48,6 +49,9 @@ function AbstractMobParent:setHP(newHP, relative) self.hp = newHP end self.hp = math.floor(math.max(0, self.hp)) + if (self.hp == 0) then + self:die() + end end function AbstractMobParent:setPP(newPP, relative) @@ -59,14 +63,47 @@ function AbstractMobParent:setPP(newPP, relative) self.pp = math.floor(math.max(0, self.pp)) end -function AbstractMobParent:isAlive() - return (self.hp > 0) -end - function AbstractMobParent:getStats() return self.stats end +-- STATUT HANDLING + +function AbstractMobParent:addStatut(name, duration) + local duration = duration or -1 + self.statuts[name] = duration +end + +function AbstractMobParent:haveStatuts(statutName) + return (self.statuts[statutName] ~= nil) +end + +function AbstractMobParent:removeStatut(statutName) + self.statuts[statutName] = nil +end + +function AbstractMobParent:resetStatut() + self.statuts = {} +end + +function AbstractMobParent:die() + self:addStatut("ko") +end + +function AbstractMobParent:isAlive() + return (not self:haveStatuts("ko")) +end + +function AbstractMobParent:removeOneTurnToStatut() + for name, duration in pairs(self.statuts) do + if (duration == 1) then + self.statuts[name] = nil + else + self.statuts[name] = (duration - 1) + end + end +end + -- Bonus stuff function AbstractMobParent:setBonus(pvFactor, statFactor)