From d4698ab101b463a041c686e24acab2547d28cfdb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 3 Jul 2021 11:17:57 +0200 Subject: [PATCH] improvement: get battle stats from the fighter It'll allow us later to add battle bonus and malus --- sonic-radiance.love/game/utils/battle/init.lua | 14 ++++++++------ .../scenes/battlesystem/controllers/ennemy.lua | 4 ++-- .../battlesystem/controllers/fighters/parent.lua | 8 ++++++-- .../controllers/fighters/systems/actions/flee.lua | 3 ++- sonic-radiance.love/scenes/battlesystem/utils.lua | 8 +++----- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/sonic-radiance.love/game/utils/battle/init.lua b/sonic-radiance.love/game/utils/battle/init.lua index 43dbb33..025973f 100644 --- a/sonic-radiance.love/game/utils/battle/init.lua +++ b/sonic-radiance.love/game/utils/battle/init.lua @@ -2,22 +2,24 @@ local BattleUtils = {} local CONSTS = require "datas.consts.battle" local protectypes = require "datas.gamedata.battles.protectypes" -function BattleUtils.computeLaunchingDamages(base, stats, isSpecial) +local STATS = require "datas.consts.stats" + +function BattleUtils.computeLaunchingDamages(base, fighter, isSpecial) local damages = base / CONSTS.DAMAGE.DIVISOR if (isSpecial) then - damages = damages * stats:get(stats.POWER) + damages = damages * fighter:getStat(STATS.POWER) else - damages = damages * stats:get(stats.ATTACK) + damages = damages * fighter:getStat(STATS.ATTACK) end return damages end -function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending) +function BattleUtils.computeReceivingDamages(base, fighter, isSpecial, isDefending) local damages = base if (isSpecial) then - damages = damages / stats:get(stats.MIND) + damages = damages / fighter:getStat(STATS.MIND) else - damages = damages / stats:get(stats.DEFENSE) + damages = damages / fighter:getStat(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 6689b56..41530e0 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua @@ -2,6 +2,7 @@ local FighterControllerParent = require "scenes.battlesystem.controllers.parent" local EnnemyController = FighterControllerParent:extend() local Villain = require "scenes.battlesystem.controllers.fighters.villain" +local STATS = require "datas.consts.stats" function EnnemyController:new(owner, battleData) self.super.new(self, owner) @@ -30,8 +31,7 @@ end function EnnemyController:getHighestSpeed() local highestSpeed = 0 for i, villain in ipairs(self.list) do - local stats = villain.abstract.stats - local currentSpeed = stats:get(stats.SPEED) + local currentSpeed = villain:getStat(STATS.SPEED) if (currentSpeed > highestSpeed) then highestSpeed = currentSpeed end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index ed7e734..cf484ed 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -75,14 +75,14 @@ function FighterParent:haveProtecType(type) end function FighterParent:sendDamage(target, value, type, element, isSpecial) - local damage = battleutils.computeLaunchingDamages(value, self:getStats(), isSpecial) + local damage = battleutils.computeLaunchingDamages(value, self, isSpecial) core.debug:print("cbs/battler", "Sending " .. damage .." damage at " .. target.name) return target:receiveDamage(damage, type, element, isSpecial, self) end function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho) - local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending) + local damages = battleutils.computeReceivingDamages(value, self, isSpecial, self.isDefending) damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes()) damages = battleutils.applyResistences(damages, element, self.abstract:getResistences()) damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses()) @@ -143,6 +143,10 @@ function FighterParent:getNbrActionPerTurn() return self.abstract.turns end +function FighterParent:getStat(statname) + return self.abstract.stats:get(statname) +end + function FighterParent:getStats() return self.abstract:getStats() end 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 035ae9c..6360d18 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 @@ -1,5 +1,6 @@ local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent" local FleeAction = ActionParent:extend() +local STATS = require "datas.consts.stats" function FleeAction:new(fighter) FleeAction.super.new(self, fighter) @@ -19,7 +20,7 @@ function FleeAction:startAction() return end - local chanceToFlee = self.fighter.turnSystem:getChanceTooFlee(stats:get(stats.SPEED)) + local chanceToFlee = self.fighter.turnSystem:getChanceTooFlee(self.fighter:getStat(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 148bbe7..dd1eeb8 100644 --- a/sonic-radiance.love/scenes/battlesystem/utils.lua +++ b/sonic-radiance.love/scenes/battlesystem/utils.lua @@ -1,4 +1,5 @@ local maputils = {} +local STATS = require "datas.consts.stats" maputils.CONST = {} @@ -6,11 +7,8 @@ maputils.CONST.STARTX = -8 maputils.CONST.STARTY = 90 function maputils.sortBattlers(a, b) - local astats = a.fighter:getStats() - local bstats = b.fighter:getStats() - local aspeed = astats:get(astats.SPEED) / (3 ^ (a.number-1)) - local bspeed = bstats:get(astats.SPEED) / (3 ^ (b.number-1)) - + local aspeed = a.fighter:getStat(STATS.SPEED) / (3 ^ (a.number-1)) + local bspeed = b.fighter:getStat(STATS.SPEED) / (3 ^ (b.number-1)) if (aspeed == bspeed) then if (a.fighter.isHero == b.fighter.isHero) then