sonic-radiance/sonic-radiance.love/game/abstractmobs/parent.lua
2021-03-12 18:51:35 +01:00

121 lines
2.5 KiB
Lua

local AbstractMobParent = Object:extend()
function AbstractMobParent:new()
self:initBasicElements()
self.stats = self:createStats()
self.skills = self:createSkills()
self.statuts = {}
self:initLife()
end
function AbstractMobParent:initBasicElements()
self.name = "PlaceHolder"
self.fullname = "PlaceHolder"
self.turns = 2
end
function AbstractMobParent:createStats()
local stats = {}
stats.hpmax = 0
stats.ppmax = 0
stats.attack = 0
stats.power = 0
stats.defense = 0
stats.technic = 0
stats.mind = 0
stats.speed = 0
return stats
end
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
self.hp = math.floor(math.max(0, self.hp))
if (self.hp == 0) then
self:die()
end
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))
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)
self.stats.hpmax = self.stats.hpmax * pvFactor
self.hp = self.stats.hpmax
self.stats.attack = self.stats.attack * statFactor
self.stats.power = self.stats.power * statFactor
self.stats.defense = self.stats.defense * statFactor
self.stats.mind = self.stats.mind * statFactor
self.stats.technic = self.stats.technic * statFactor
self.stats.speed = self.stats.speed * statFactor
end
return AbstractMobParent