2021-05-08 12:54:07 +02:00
|
|
|
local Serializable = require "birb.classes.serializable"
|
|
|
|
local AbstractMobParent = Serializable:extend()
|
2021-07-03 09:49:11 +02:00
|
|
|
local StatManager = require "game.abstractmobs.statmanager"
|
2020-07-19 13:13:54 +02:00
|
|
|
|
2021-07-03 09:49:11 +02:00
|
|
|
function AbstractMobParent:new(serializeFields, listSerializable, statManager)
|
|
|
|
local statManager = statManager or StatManager
|
2020-07-19 13:13:54 +02:00
|
|
|
self:initBasicElements()
|
2021-07-03 09:49:11 +02:00
|
|
|
|
2021-07-03 10:12:56 +02:00
|
|
|
self.stats = statManager(self)
|
2020-07-19 13:13:54 +02:00
|
|
|
self.skills = self:createSkills()
|
2021-03-12 18:51:35 +01:00
|
|
|
self.statuts = {}
|
2020-07-19 13:13:54 +02:00
|
|
|
self:initLife()
|
2021-05-08 12:54:07 +02:00
|
|
|
AbstractMobParent.super.new(self, serializeFields, listSerializable)
|
2020-07-19 13:13:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function AbstractMobParent:initBasicElements()
|
|
|
|
self.name = "PlaceHolder"
|
|
|
|
self.fullname = "PlaceHolder"
|
|
|
|
self.turns = 2
|
|
|
|
end
|
|
|
|
|
2021-05-15 14:50:12 +02:00
|
|
|
function AbstractMobParent:haveProtecType()
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function AbstractMobParent:getProtecTypes()
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2020-07-19 13:13:54 +02:00
|
|
|
function AbstractMobParent:createSkills()
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2020-07-24 19:49:24 +02:00
|
|
|
-- LIFE FUNCTIONS
|
|
|
|
-- Handle HP and stuff like that
|
|
|
|
|
2020-07-19 13:13:54 +02:00
|
|
|
function AbstractMobParent:initLife()
|
2021-07-03 09:49:11 +02:00
|
|
|
self.hp = self.stats:get(self.stats.HPMAX)
|
|
|
|
self.pp = self.stats:get(self.stats.PPMAX)
|
2020-07-19 13:13:54 +02:00
|
|
|
self.status = 0
|
|
|
|
end
|
|
|
|
|
2020-07-24 19:49:24 +02:00
|
|
|
function AbstractMobParent:setHP(newHP, relative)
|
|
|
|
if (relative) then
|
|
|
|
self.hp = self.hp + newHP
|
|
|
|
else
|
|
|
|
self.hp = newHP
|
|
|
|
end
|
2020-08-07 07:32:16 +02:00
|
|
|
self.hp = math.floor(math.max(0, self.hp))
|
2021-03-12 18:51:35 +01:00
|
|
|
if (self.hp == 0) then
|
|
|
|
self:die()
|
|
|
|
end
|
2021-07-03 13:18:16 +02:00
|
|
|
self.hp = math.min(self.hp, self.stats:get(self.stats.HPMAX))
|
2020-07-24 19:49:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function AbstractMobParent:setPP(newPP, relative)
|
|
|
|
if (relative) then
|
|
|
|
self.pp = self.pp + newPP
|
|
|
|
else
|
|
|
|
self.pp = newPP
|
|
|
|
end
|
2020-08-07 07:32:16 +02:00
|
|
|
self.pp = math.floor(math.max(0, self.pp))
|
2021-07-03 13:18:16 +02:00
|
|
|
self.pp = math.min(self.pp, self.stats:get(self.stats.PPMAX))
|
2020-07-24 19:49:24 +02:00
|
|
|
end
|
|
|
|
|
2021-03-12 18:51:35 +01:00
|
|
|
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
|
|
|
|
|
2020-07-24 19:49:24 +02:00
|
|
|
function AbstractMobParent:isAlive()
|
2021-03-12 18:51:35 +01:00
|
|
|
return (not self:haveStatuts("ko"))
|
2020-07-24 19:49:24 +02:00
|
|
|
end
|
|
|
|
|
2021-03-12 18:51:35 +01:00
|
|
|
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
|
2020-07-19 13:13:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return AbstractMobParent
|