feat: add a stat manager object
This commit is contained in:
parent
b1e1ef614f
commit
c7b9d97c96
4 changed files with 44 additions and 8 deletions
|
@ -22,14 +22,14 @@ function CharacterEquip:setEquip(category, name)
|
|||
end
|
||||
self.equip[category] = name
|
||||
game.loot:removeItem(category, name, 1)
|
||||
self.stats = self:createStats()
|
||||
self.stats:setStats(self:createStats())
|
||||
end
|
||||
|
||||
function CharacterEquip:removeEquip(category)
|
||||
if (not utils.string.isEmpty(self.equip[category])) then
|
||||
game.loot:addItem(category, self.equip[category], 1)
|
||||
self.equip[category] = ""
|
||||
self.stats = self:createStats()
|
||||
self.stats:setStats(self:createStats())
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ function CharacterLevel:setLevel(newlevel)
|
|||
self.exp = math.max(math.min(exp, exp_max - 1), exp_min)
|
||||
self.exp_next = exp_max
|
||||
|
||||
self.stats = self:createStats()
|
||||
self.stats:setStats(self:createStats())
|
||||
end
|
||||
|
||||
function CharacterLevel:levelUp()
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
local Serializable = require "birb.classes.serializable"
|
||||
local AbstractMobParent = Serializable:extend()
|
||||
local StatManager = require "game.abstractmobs.statmanager"
|
||||
|
||||
function AbstractMobParent:new(serializeFields, listSerializable)
|
||||
function AbstractMobParent:new(serializeFields, listSerializable, statManager)
|
||||
local statManager = statManager or StatManager
|
||||
self:initBasicElements()
|
||||
self.stats = self:createStats()
|
||||
|
||||
self.stats = statManager()
|
||||
self.stats:setStats(self:createStats())
|
||||
self.skills = self:createSkills()
|
||||
self.statuts = {}
|
||||
self:initLife()
|
||||
|
@ -47,8 +51,8 @@ end
|
|||
-- Handle HP and stuff like that
|
||||
|
||||
function AbstractMobParent:initLife()
|
||||
self.hp = self.stats.hpmax
|
||||
self.pp = self.stats.ppmax
|
||||
self.hp = self.stats:get(self.stats.HPMAX)
|
||||
self.pp = self.stats:get(self.stats.PPMAX)
|
||||
self.status = 0
|
||||
end
|
||||
|
||||
|
@ -118,7 +122,7 @@ end
|
|||
|
||||
function AbstractMobParent:setBonus(pvFactor, statFactor)
|
||||
self.stats.hpmax = self.stats.hpmax * pvFactor
|
||||
self.hp = self.stats.hpmax
|
||||
self.hp = self.stats:get(self.stats.HPMAX)
|
||||
|
||||
self.stats.attack = self.stats.attack * statFactor
|
||||
self.stats.power = self.stats.power * statFactor
|
||||
|
|
32
sonic-radiance.love/game/abstractmobs/statmanager.lua
Normal file
32
sonic-radiance.love/game/abstractmobs/statmanager.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
local StatManager = Object:extend()
|
||||
local CONST = require "datas.consts.stats"
|
||||
StatManager.CONST = CONST
|
||||
|
||||
StatManager.HPMAX = CONST.HPMAX
|
||||
StatManager.PPMAX = CONST.PPMAX
|
||||
StatManager.ATTACK = CONST.ATTACK
|
||||
StatManager.POWER = CONST.POWER
|
||||
StatManager.DEFENSE = CONST.DEFENSE
|
||||
StatManager.MIND = CONST.MIND
|
||||
StatManager.TECHNIC = CONST.TECHNIC
|
||||
StatManager.SPEED = CONST.SPEED
|
||||
|
||||
function StatManager:new(owner)
|
||||
self.owner = owner
|
||||
end
|
||||
|
||||
function StatManager:setStats(stats)
|
||||
for key, value in pairs(stats) do
|
||||
self[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
function StatManager:get(statname)
|
||||
return self:computeStat(statname)
|
||||
end
|
||||
|
||||
function StatManager:computeStat(statname)
|
||||
return self[statname]
|
||||
end
|
||||
|
||||
return StatManager
|
Loading…
Reference in a new issue