diff --git a/sonic-radiance.love/game/abstractmobs/character/equip.lua b/sonic-radiance.love/game/abstractmobs/character/equip.lua index f5eff45..323e2bc 100644 --- a/sonic-radiance.love/game/abstractmobs/character/equip.lua +++ b/sonic-radiance.love/game/abstractmobs/character/equip.lua @@ -22,21 +22,19 @@ function CharacterEquip:setEquip(category, name) end self.equip[category] = name game.loot:removeItem(category, name, 1) - self.stats:setStats(self:createStats()) + self.stats:setStats(self:createStats(self)) 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.stats:setStats(self:createStats(self)) end end function CharacterEquip:predictStat(statName, category, name) - local data = core.datas:get("items", name) - local boost = data.statsBoost[statName] or 0 - return self:getStat(statName, category) + boost + return self.stats:predictStat(statName, category, name) end function CharacterEquip:getEquipStats(stat, ignore) diff --git a/sonic-radiance.love/game/abstractmobs/character/init.lua b/sonic-radiance.love/game/abstractmobs/character/init.lua index 75e6e48..02570b3 100644 --- a/sonic-radiance.love/game/abstractmobs/character/init.lua +++ b/sonic-radiance.love/game/abstractmobs/character/init.lua @@ -10,9 +10,11 @@ AbstractCharacter:implement(CharacterLevels) AbstractCharacter:implement(CharacterDatas) AbstractCharacter:implement(CharacterEquip) +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"}) + AbstractCharacter.super.new(self, {"simplename", "level", "exp", "exp_next", "hp", "pp", "statuts", "equip"}, nil, CharacterStatManager) end function AbstractCharacter:initBasicElements() diff --git a/sonic-radiance.love/game/abstractmobs/character/levels.lua b/sonic-radiance.love/game/abstractmobs/character/levels.lua index 1e67f5f..f4801b3 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.stats:setStats(self:createStats(self)) end function CharacterLevel:levelUp() @@ -29,7 +29,7 @@ function CharacterLevel:levelUp() self:setLevel(self.level + 1) end -function CharacterLevel:getComputedStat(statname) +function CharacterLevel:getLevelStat(statname) local baseStat = self.data.stats[statname] if (baseStat == nil) then error("Stat " .. statname .. " doesn't exist") @@ -48,6 +48,11 @@ function CharacterLevel:getComputedStat(statname) end end +function CharacterLevel:getComputedStat(statname) + core.debug:warning("CharacterLevel", "Function getComputedStat is deprecated") + return self:getLevelStat(statname) +end + function CharacterLevel:getStatList() return STATS.LIST end diff --git a/sonic-radiance.love/game/abstractmobs/character/statmanager.lua b/sonic-radiance.love/game/abstractmobs/character/statmanager.lua new file mode 100644 index 0000000..f3d6b0c --- /dev/null +++ b/sonic-radiance.love/game/abstractmobs/character/statmanager.lua @@ -0,0 +1,19 @@ +local StatManager = require "game.abstractmobs.statmanager" +local CharacterStatManager = StatManager:extend() + +function CharacterStatManager:new(owner) + CharacterStatManager.super.new(self, owner) +end + +function CharacterStatManager:computeStat(statname, ignoreEquip) + local stat = self.owner:getLevelStat(statname) + self.owner:getEquipStats(statname, ignoreEquip) + return stat +end + +function CharacterStatManager:predictStat(statname, category, name) + local data = core.datas:get("items", name) + local boost = data.statsBoost[statname] or 0 + return self:computeStat(statname, category) + boost +end + +return CharacterStatManager \ No newline at end of file