From 7db0ad1b28996e9e779a1fc0413e1d066603011c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 3 Jul 2021 09:51:19 +0200 Subject: [PATCH] chore: use getter to get stat --- sonic-radiance.love/game/characters.lua | 2 +- .../game/loot/effects/heal.lua | 5 ++-- .../game/modules/gui/statusbar.lua | 4 ++-- .../game/utils/battle/init.lua | 8 +++---- .../battlesystem/controllers/ennemy.lua | 6 +++-- .../fighters/systems/actions/flee.lua | 4 +++- .../scenes/battlesystem/utils.lua | 4 ++-- .../scenes/debug/menu/infopanel/character.lua | 23 ++++++++++++------- .../scenes/overworld/actors/player/health.lua | 2 +- .../screens/mainmenu/character/basicpage.lua | 5 ++-- .../screens/mainmenu/character/statpage.lua | 2 +- .../screens/mainmenu/common/charwidget.lua | 5 ++-- .../overworld/screens/mainmenu/equip.lua | 2 +- 13 files changed, 43 insertions(+), 29 deletions(-) diff --git a/sonic-radiance.love/game/characters.lua b/sonic-radiance.love/game/characters.lua index 175fd3a..927e14e 100644 --- a/sonic-radiance.love/game/characters.lua +++ b/sonic-radiance.love/game/characters.lua @@ -164,7 +164,7 @@ end function CharacterManager:sendDamageFromMap(name, damageRatio) local character = self.list[name] if (character.hp > 0) then - local newHP = math.floor(character.hp - (character.stats.hpmax * damageRatio)) + local newHP = math.floor(character.hp - (character.stats:get(character.stats.HPMAX) * damageRatio)) if (not game.difficulty:get("hazardMakesKo")) then newHP = math.max(1, newHP) end diff --git a/sonic-radiance.love/game/loot/effects/heal.lua b/sonic-radiance.love/game/loot/effects/heal.lua index 7eaef60..ed1aca4 100644 --- a/sonic-radiance.love/game/loot/effects/heal.lua +++ b/sonic-radiance.love/game/loot/effects/heal.lua @@ -35,10 +35,11 @@ function HealEffect:getCurrentValue() end function HealEffect:getMaxValue() + local stats = self.character.stats if (self.effect.healType == "hp") then - return self.character.stats.hpmax + return stats:get(stats.HPMAX) elseif (self.effect.healType == "mp") then - return self.character.stats.ppmax + return stats:get(stats.PPMAX) end end diff --git a/sonic-radiance.love/game/modules/gui/statusbar.lua b/sonic-radiance.love/game/modules/gui/statusbar.lua index 13be04c..947d717 100644 --- a/sonic-radiance.love/game/modules/gui/statusbar.lua +++ b/sonic-radiance.love/game/modules/gui/statusbar.lua @@ -47,8 +47,8 @@ end function StatusBar:drawStatusArea(x, y) self.assets.images["statusbar"]:draw(x, y) -local hpmax = self.stats.hpmax -local ppmax = self.stats.ppmax +local hpmax = self.stats:get(self.stats.HPMAX) +local ppmax = self.stats:get(self.stats.PPMAX) self.assets.fonts["hudnbrs_small"]:set() self.hpbar:drawWithLabels(x + 6, y + 9, self.hp, hpmax) diff --git a/sonic-radiance.love/game/utils/battle/init.lua b/sonic-radiance.love/game/utils/battle/init.lua index a6bde26..43dbb33 100644 --- a/sonic-radiance.love/game/utils/battle/init.lua +++ b/sonic-radiance.love/game/utils/battle/init.lua @@ -5,9 +5,9 @@ local protectypes = require "datas.gamedata.battles.protectypes" function BattleUtils.computeLaunchingDamages(base, stats, isSpecial) local damages = base / CONSTS.DAMAGE.DIVISOR if (isSpecial) then - damages = damages * stats.power + damages = damages * stats:get(stats.POWER) else - damages = damages * stats.attack + damages = damages * stats:get(stats.ATTACK) end return damages end @@ -15,9 +15,9 @@ end function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending) local damages = base if (isSpecial) then - damages = damages / stats.mind + damages = damages / stats:get(stats.MIND) else - damages = damages / stats.defense + damages = damages / stats:get(stats.DEFENSE) end if (isDefending) then diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua index c5f89ae..6689b56 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua @@ -30,8 +30,10 @@ end function EnnemyController:getHighestSpeed() local highestSpeed = 0 for i, villain in ipairs(self.list) do - if (villain.abstract.stats.speed > highestSpeed) then - highestSpeed = villain.abstract.stats.speed + local stats = villain.abstract.stats + local currentSpeed = stats:get(stats.SPEED) + if (currentSpeed > highestSpeed) then + highestSpeed = currentSpeed end end return highestSpeed diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua index 0e0a949..035ae9c 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua @@ -11,13 +11,15 @@ end function FleeAction:startAction() core.debug:print("cbs/action", "Starting flee action") + local stats = self.fighter.abstract.stats + if (self.fighter.abstract.name == "shadow") then self.fighter.turns.hud:showMessage("You won't flee the battle") self:finishAction() return end - local chanceToFlee = self.fighter.turnSystem:getChanceTooFlee(self.fighter.abstract.stats.speed) + local chanceToFlee = self.fighter.turnSystem:getChanceTooFlee(stats:get(stats.SPEED)) if (math.random(100) < chanceToFlee) then self.fighter.turnSystem.hud:showMessage("You flee the battle") self.fighter.turnSystem:fleeBattle() diff --git a/sonic-radiance.love/scenes/battlesystem/utils.lua b/sonic-radiance.love/scenes/battlesystem/utils.lua index a21284c..148bbe7 100644 --- a/sonic-radiance.love/scenes/battlesystem/utils.lua +++ b/sonic-radiance.love/scenes/battlesystem/utils.lua @@ -8,8 +8,8 @@ maputils.CONST.STARTY = 90 function maputils.sortBattlers(a, b) local astats = a.fighter:getStats() local bstats = b.fighter:getStats() - local aspeed = astats.speed / (3 ^ (a.number-1)) - local bspeed = bstats.speed / (3 ^ (b.number-1)) + local aspeed = astats:get(astats.SPEED) / (3 ^ (a.number-1)) + local bspeed = bstats:get(astats.SPEED) / (3 ^ (b.number-1)) if (aspeed == bspeed) then diff --git a/sonic-radiance.love/scenes/debug/menu/infopanel/character.lua b/sonic-radiance.love/scenes/debug/menu/infopanel/character.lua index 7caacad..16a0261 100644 --- a/sonic-radiance.love/scenes/debug/menu/infopanel/character.lua +++ b/sonic-radiance.love/scenes/debug/menu/infopanel/character.lua @@ -7,18 +7,25 @@ function CharacterPanel:new(character) end function CharacterPanel:drawContent(x, y) + local stats = self.character.stats + local debugString = "# DEBUG - " .. self.character.name .. "(" .. "Lvl " .. self.character.level .. ")" .. "\n" local debugString = debugString .. "EXP: " .. self.character.exp .. " / " .. self.character.exp_next .. "\n" - local debugString = debugString .. "HP: " .. self.character.hp .. " / " .. self.character.stats.hpmax .. "\n" - local debugString = debugString .. "PP: " .. self.character.pp .. " / " .. self.character.stats.ppmax .. "\n" - local debugString = debugString .. "ATK: " .. self.character.stats.attack - local debugString = debugString .. " DEF: " .. self.character.stats.defense - local debugString = debugString .. " SPD: " .. self.character.stats.speed .. "\n" - local debugString = debugString .. "POW: " .. self.character.stats.power - local debugString = debugString .. " MND: " .. self.character.stats.mind - local debugString = debugString .. " TEK: " .. self.character.stats.technic .. "\n" + local debugString = debugString .. "HP: " .. self.character.hp .. " / " .. stats:get(stats.HPMAX) .. "\n" + local debugString = debugString .. "PP: " .. self.character.pp .. " / " .. stats:get(stats.PPMAX) .. "\n" + local debugString = debugString .. self:addToDebugString(stats, stats.ATTACK) + local debugString = debugString .. " " .. self:addToDebugString(stats, stats.DEFENSE) + local debugString = debugString .. " " .. self:addToDebugString(stats, stats.SPEED) .. "\n" + local debugString = debugString .. self:addToDebugString(stats, stats.POWER) + local debugString = debugString .. " " .. self:addToDebugString(stats, stats.MIND) + local debugString = debugString .. " " .. self:addToDebugString(stats, stats.TECHNIC) .. "\n" love.graphics.print(debugString, x, y) end +function CharacterPanel:addToDebugString(stats, statname) + local stats = stats + return stats.CONST.SIMPLENAME[statname] .. ": " .. stats:get(statname) +end + return CharacterPanel diff --git a/sonic-radiance.love/scenes/overworld/actors/player/health.lua b/sonic-radiance.love/scenes/overworld/actors/player/health.lua index 5e07775..96bb584 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/health.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/health.lua @@ -17,7 +17,7 @@ function PlayerHealth:drawHealth(x, y) local yy = y + (i * 17) local character = game.characters.list[name] self.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(x + 18, yy, character.hp, character.stats.hpmax) + self.hpbar:drawWithLabels(x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX)) self.assets.tileset["charicons"]:drawTile(character.data.icon, x, yy - 3) end end diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua index e1a6f2a..e639de3 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua @@ -42,10 +42,11 @@ function BasicPage:drawIdentity(x, y) end function BasicPage:drawHPPP(x, y) + local stats = self.character.stats self.view.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(x, y - 4, self.character.hp, self.character.stats.hpmax) + self.hpbar:drawWithLabels(x, y - 4, self.character.hp, stats:get(stats.HPMAX)) local xx = x + const.CHARPAGESIZE - HPBAR_SIZE - 7 - self.ppbar:drawWithLabels(xx, y - 4, self.character.pp, self.character.stats.ppmax) + self.ppbar:drawWithLabels(xx, y - 4, self.character.pp, stats:get(stats.PPMAX)) end function BasicPage:drawLevel(x, y) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua index fa120ac..4401ec3 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua @@ -36,7 +36,7 @@ function StatPage:drawStats(x, y) local xStat = x + (((i - 1) % 2) * (const.CHARPAGESIZE/2)) + 6 local yStat = y + (math.floor((i-1)/2) * 16) + 4 local middle = xStat + 10 + const.CHARPAGESIZE/4 - local stat = char.stats[statName] + local stat = char.stats:get(statName) self.view.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, const.CHARPAGESIZE, "left") self.view.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9) self.view.scene.assets.fonts["small"]:draw(stat, middle, yStat, -1, "center") diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua index 2b739db..c4fddf0 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua @@ -53,8 +53,9 @@ function CharacterWidget:draw(x, y) local xDebut = x + 52 local yDebut = y + 15 self.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, character.stats.hpmax) - self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, character.stats.ppmax) + local stats = character.stats + self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, stats:get(stats.HPMAX)) + self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, stats:get(stats.PPMAX)) end if self.canvas.texture ~= nil then love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua index 28f134b..51bd2cb 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua @@ -52,7 +52,7 @@ function EquipScreen:drawDescription(x, y) local xStat = xx + (((i - 1) % 2) * (ww/2)) local yStat = yy + (math.floor((i-1)/2) * 16) + 24 local middle = xStat + 10 + ww/4 - local stat = char.stats[statName] + local stat = char.stats:get(statName) local newStat = char:predictStat(statName, self.category, self.item.name) self.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, ww, "left") self.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9)