feat: add ennemy stat manager

This commit is contained in:
Kazhnuz 2021-07-03 10:12:56 +02:00
parent de0a1a886a
commit c0b4fd41f8
3 changed files with 34 additions and 16 deletions

View file

@ -2,11 +2,12 @@ local AbstractMobParent = require "game.abstractmobs.parent"
local AbstractEnnemy = AbstractMobParent:extend() local AbstractEnnemy = AbstractMobParent:extend()
local elements = require "datas.gamedata.battles.elements" local elements = require "datas.gamedata.battles.elements"
local EnnemyStatManager = require "game.abstractmobs.ennemy.statmanager"
function AbstractEnnemy:new(directory, name) function AbstractEnnemy:new(directory, name)
self.simplename = name self.simplename = name
self.directory = directory self.directory = directory
self.super.new(self) AbstractEnnemy.super.new(self, nil, nil, EnnemyStatManager)
end end
function AbstractEnnemy:getWeaknesses() function AbstractEnnemy:getWeaknesses()
@ -42,4 +43,9 @@ function AbstractEnnemy:createSkills()
return self.data.skills return self.data.skills
end end
function AbstractEnnemy:setBonus(pvFactor, statFactor)
self.stats:setBonus(pvFactor, statFactor)
self.hp = self.stats:get(self.stats.HPMAX)
end
return AbstractEnnemy return AbstractEnnemy

View file

@ -0,0 +1,25 @@
local StatManager = require "game.abstractmobs.statmanager"
local EnnemyStatManager = StatManager:extend()
function EnnemyStatManager:new(owner)
EnnemyStatManager.super.new(self, owner)
self.pvFactor = 1
self.statFactor = 1
end
function EnnemyStatManager:setBonus(pvFactor, statFactor)
self.pvFactor = pvFactor or 1
self.statFactor = statFactor or 1
end
function EnnemyStatManager:computeStat(statname)
local stat = self.owner.data.stats[statname]
if statname == EnnemyStatManager.HPMAX then
return stat * self.pvFactor
elseif (statname ~= EnnemyStatManager.PPMAX) then
return stat * self.statFactor
end
end
return EnnemyStatManager

View file

@ -3,10 +3,11 @@ local AbstractMobParent = Serializable:extend()
local StatManager = require "game.abstractmobs.statmanager" local StatManager = require "game.abstractmobs.statmanager"
function AbstractMobParent:new(serializeFields, listSerializable, statManager) function AbstractMobParent:new(serializeFields, listSerializable, statManager)
print(statManager)
local statManager = statManager or StatManager local statManager = statManager or StatManager
self:initBasicElements() self:initBasicElements()
self.stats = statManager() self.stats = statManager(self)
self.stats:setStats(self:createStats()) self.stats:setStats(self:createStats())
self.skills = self:createSkills() self.skills = self:createSkills()
self.statuts = {} self.statuts = {}
@ -118,18 +119,4 @@ function AbstractMobParent:removeOneTurnToStatut()
end end
end end
-- Bonus stuff
function AbstractMobParent:setBonus(pvFactor, statFactor)
self.stats.hpmax = self.stats.hpmax * pvFactor
self.hp = self.stats:get(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 return AbstractMobParent