From 06b0fb76ba3b5d6258e3386196a6495de2f3457c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 13 Aug 2021 20:14:34 +0200 Subject: [PATCH] feat: use the new statuses data --- .../game/abstractmobs/parent.lua | 82 +++++++++++++++---- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/sonic-radiance.love/game/abstractmobs/parent.lua b/sonic-radiance.love/game/abstractmobs/parent.lua index 478d0e3..1fb1d04 100644 --- a/sonic-radiance.love/game/abstractmobs/parent.lua +++ b/sonic-radiance.love/game/abstractmobs/parent.lua @@ -72,17 +72,71 @@ end -- STATUT HANDLING function AbstractMobParent:addStatut(name, duration, source) - local duration = duration or -1 - self.statuts[name] = {} - self.statuts[name].duration = duration + local statut = self:getStatutData(name) + local duration = duration or 1 + + if (statut.remove ~= nil) then + duration = - self:removeStatutTurns(statut.remove, duration) + end + + if (duration > 0) then + if (statut.replaceAll == true) then + self:resetStatut() + else + self:removeStatut(name) + end + self.statuts[name] = {} + self.statuts[name].duration = duration + end +end + +function AbstractMobParent:getStatutKey(statutName) + local statut = self:getStatutData(statutName) + local key = "" + if (self.statuts[statutName] ~= nil) then + key = statutName + end + if (statut.alternative ~= nil) then + for _, alternative in ipairs(statut.alternative) do + if (self.statuts[alternative] ~= nil) then + key = alternative + end + end + end + return key end function AbstractMobParent:haveStatuts(statutName) - return (self.statuts[statutName] ~= nil) + return (self.statuts[self:getStatutKey(statutName)] ~= nil) end function AbstractMobParent:removeStatut(statutName) - self.statuts[statutName] = nil + local key = self:getStatutKey(statutName) + if (key ~= nil) then + self.statuts[key] = nil + return true + end + return false +end + +function AbstractMobParent:removeStatutTurns(statutName, turns) + local statut = self:getStatutData(statutName) + if (statut.temporary == false) then + return 0 + end + if (not self:haveStatuts(statutName)) then + return turns + end + local key = self:getStatutKey(statutName) + local relativeTurns = self.statuts[key].duration - turns + + if (relativeTurns <= 0) then + self:removeStatut(statutName) + else + self.statuts[key].duration = relativeTurns + end + + return relativeTurns end function AbstractMobParent:resetStatut() @@ -98,22 +152,16 @@ function AbstractMobParent:isAlive() end function AbstractMobParent:removeOneTurnToStatut() - for name, statut in pairs(self.statuts) do - if (statut ~= nil) then - if (statut.duration == 1) then - self.statuts[name] = nil - else - self.statuts[name].duration = (statut.duration - 1) - end - end + for name, _ in pairs(self.statuts) do + self:removeStatutTurns(name, 1) end end function AbstractMobParent:getStatutsStat(statName) local stat = 0 for statutName, _ in pairs(self.statuts) do - local statut = statutStatList[statutName] - if (statut ~= nil) then + local statut = self:getStatutData(statutName) + if (statut.stats ~= nil) then for _, statutStat in ipairs(statut.stats) do if (statutStat[1] == statName) then stat = stat + statutStat[2] @@ -124,4 +172,8 @@ function AbstractMobParent:getStatutsStat(statName) return stat end +function AbstractMobParent:getStatutData(statutName) + return statutStatList[statutName] +end + return AbstractMobParent