From 2265d7dac9cc569667ff18b7fdb5ca135aba2b49 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 3 Jul 2021 10:41:16 +0200 Subject: [PATCH] improvement: do not recompute all stats --- .../game/abstractmobs/character/equip.lua | 4 ++-- .../game/abstractmobs/character/init.lua | 22 +++++++++---------- .../game/abstractmobs/character/levels.lua | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sonic-radiance.love/game/abstractmobs/character/equip.lua b/sonic-radiance.love/game/abstractmobs/character/equip.lua index 323e2bc..038ca23 100644 --- a/sonic-radiance.love/game/abstractmobs/character/equip.lua +++ b/sonic-radiance.love/game/abstractmobs/character/equip.lua @@ -22,14 +22,14 @@ function CharacterEquip:setEquip(category, name) end self.equip[category] = name game.loot:removeItem(category, name, 1) - self.stats:setStats(self:createStats(self)) + self:updateHPPP() 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:setStats(self:createStats(self)) + self:updateHPPP() end end diff --git a/sonic-radiance.love/game/abstractmobs/character/init.lua b/sonic-radiance.love/game/abstractmobs/character/init.lua index 02570b3..843be24 100644 --- a/sonic-radiance.love/game/abstractmobs/character/init.lua +++ b/sonic-radiance.love/game/abstractmobs/character/init.lua @@ -15,6 +15,7 @@ local CharacterStatManager = require "game.abstractmobs.character.statmanager" function AbstractCharacter:new(name) self.simplename = name AbstractCharacter.super.new(self, {"simplename", "level", "exp", "exp_next", "hp", "pp", "statuts", "equip"}, nil, CharacterStatManager) + self:updateHPPP() end function AbstractCharacter:initBasicElements() @@ -26,22 +27,21 @@ end function AbstractCharacter:createStats() local statNames = self:getStatList() local stats = {} - for _, name in ipairs(statNames) do - stats[name] = self:getStat(name) - end - if (self.hp ~= nil) then - self.hp = math.min(self.hp, stats.hpmax) - end - if (self.pp ~= nil) then - self.pp = math.min(self.pp, stats.ppmax) - end return stats end +function AbstractCharacter:updateHPPP() + if (self.hp ~= nil) then + self.hp = math.min(self.hp, self.stats:get(self.stats.HPMAX)) + end + if (self.pp ~= nil) then + self.pp = math.min(self.pp, self.stats:get(self.stats.PPMAX)) + end +end + function AbstractCharacter:getStat(statName, ignoreEquip) - local stat = self:getComputedStat(statName) + self:getEquipStats(statName, ignoreEquip) - return stat + return self.stats:get(statName, ignoreEquip) end function AbstractCharacter:createSkills() diff --git a/sonic-radiance.love/game/abstractmobs/character/levels.lua b/sonic-radiance.love/game/abstractmobs/character/levels.lua index f4801b3..60584f4 100644 --- a/sonic-radiance.love/game/abstractmobs/character/levels.lua +++ b/sonic-radiance.love/game/abstractmobs/character/levels.lua @@ -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:setStats(self:createStats(self)) + self:updateHPPP() end function CharacterLevel:levelUp()