local Serializable = require "birb.classes.serializable" local AbstractMobParent = Serializable:extend() local StatManager = require "game.abstractmobs.statmanager" local statutStatList = require "datas.gamedata.statuses" function AbstractMobParent:new(serializeFields, listSerializable, statManager) local statManager = statManager or StatManager self:initBasicElements() self.stats = statManager(self) self.skills = self:createSkills() self.statuts = {} self:initLife() AbstractMobParent.super.new(self, serializeFields, listSerializable) end function AbstractMobParent:initBasicElements() self.name = "PlaceHolder" self.fullname = "PlaceHolder" self.turns = 2 end function AbstractMobParent:haveProtecType() return false end function AbstractMobParent:getProtecTypes() return {} end function AbstractMobParent:createSkills() return {} end -- LIFE FUNCTIONS -- Handle HP and stuff like that function AbstractMobParent:initLife() self.hp = self.stats:get(self.stats.HPMAX) self.pp = self.stats:get(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 self.hp = math.floor(math.max(0, self.hp)) if (self.hp == 0) then self:die() end self.hp = math.min(self.hp, self.stats:get(self.stats.HPMAX)) end function AbstractMobParent:setPP(newPP, relative) if (relative) then self.pp = self.pp + newPP else self.pp = newPP end self.pp = math.floor(math.max(0, self.pp)) self.pp = math.min(self.pp, self.stats:get(self.stats.PPMAX)) end function AbstractMobParent:getStats() return self.stats end function AbstractMobParent:getStatutsStat(statName) local stat = 0 for statut, _ in pairs(self.statuts) do for _, statutStat in ipairs(statutStatList[statut]) do if (statutStat[1] == statName) then stat = stat + statutStat[2] end end end return stat 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 return AbstractMobParent