improvement: get battle stats from the fighter

It'll allow us later to add battle bonus and malus
This commit is contained in:
Kazhnuz 2021-07-03 11:17:57 +02:00
parent 32bb1b5425
commit d4698ab101
5 changed files with 21 additions and 16 deletions

View file

@ -2,22 +2,24 @@ local BattleUtils = {}
local CONSTS = require "datas.consts.battle" local CONSTS = require "datas.consts.battle"
local protectypes = require "datas.gamedata.battles.protectypes" 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 local damages = base / CONSTS.DAMAGE.DIVISOR
if (isSpecial) then if (isSpecial) then
damages = damages * stats:get(stats.POWER) damages = damages * fighter:getStat(STATS.POWER)
else else
damages = damages * stats:get(stats.ATTACK) damages = damages * fighter:getStat(STATS.ATTACK)
end end
return damages return damages
end end
function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending) function BattleUtils.computeReceivingDamages(base, fighter, isSpecial, isDefending)
local damages = base local damages = base
if (isSpecial) then if (isSpecial) then
damages = damages / stats:get(stats.MIND) damages = damages / fighter:getStat(STATS.MIND)
else else
damages = damages / stats:get(stats.DEFENSE) damages = damages / fighter:getStat(STATS.DEFENSE)
end end
if (isDefending) then if (isDefending) then

View file

@ -2,6 +2,7 @@ local FighterControllerParent = require "scenes.battlesystem.controllers.parent"
local EnnemyController = FighterControllerParent:extend() local EnnemyController = FighterControllerParent:extend()
local Villain = require "scenes.battlesystem.controllers.fighters.villain" local Villain = require "scenes.battlesystem.controllers.fighters.villain"
local STATS = require "datas.consts.stats"
function EnnemyController:new(owner, battleData) function EnnemyController:new(owner, battleData)
self.super.new(self, owner) self.super.new(self, owner)
@ -30,8 +31,7 @@ end
function EnnemyController:getHighestSpeed() function EnnemyController:getHighestSpeed()
local highestSpeed = 0 local highestSpeed = 0
for i, villain in ipairs(self.list) do for i, villain in ipairs(self.list) do
local stats = villain.abstract.stats local currentSpeed = villain:getStat(STATS.SPEED)
local currentSpeed = stats:get(stats.SPEED)
if (currentSpeed > highestSpeed) then if (currentSpeed > highestSpeed) then
highestSpeed = currentSpeed highestSpeed = currentSpeed
end end

View file

@ -75,14 +75,14 @@ function FighterParent:haveProtecType(type)
end end
function FighterParent:sendDamage(target, value, type, element, isSpecial) 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) core.debug:print("cbs/battler", "Sending " .. damage .." damage at " .. target.name)
return target:receiveDamage(damage, type, element, isSpecial, self) return target:receiveDamage(damage, type, element, isSpecial, self)
end end
function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho) 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.applyProtectTypes(damages, type, self.abstract:getProtecTypes())
damages = battleutils.applyResistences(damages, element, self.abstract:getResistences()) damages = battleutils.applyResistences(damages, element, self.abstract:getResistences())
damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses()) damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses())
@ -143,6 +143,10 @@ function FighterParent:getNbrActionPerTurn()
return self.abstract.turns return self.abstract.turns
end end
function FighterParent:getStat(statname)
return self.abstract.stats:get(statname)
end
function FighterParent:getStats() function FighterParent:getStats()
return self.abstract:getStats() return self.abstract:getStats()
end end

View file

@ -1,5 +1,6 @@
local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent" local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent"
local FleeAction = ActionParent:extend() local FleeAction = ActionParent:extend()
local STATS = require "datas.consts.stats"
function FleeAction:new(fighter) function FleeAction:new(fighter)
FleeAction.super.new(self, fighter) FleeAction.super.new(self, fighter)
@ -19,7 +20,7 @@ function FleeAction:startAction()
return return
end 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 if (math.random(100) < chanceToFlee) then
self.fighter.turnSystem.hud:showMessage("You flee the battle") self.fighter.turnSystem.hud:showMessage("You flee the battle")
self.fighter.turnSystem:fleeBattle() self.fighter.turnSystem:fleeBattle()

View file

@ -1,4 +1,5 @@
local maputils = {} local maputils = {}
local STATS = require "datas.consts.stats"
maputils.CONST = {} maputils.CONST = {}
@ -6,11 +7,8 @@ maputils.CONST.STARTX = -8
maputils.CONST.STARTY = 90 maputils.CONST.STARTY = 90
function maputils.sortBattlers(a, b) function maputils.sortBattlers(a, b)
local astats = a.fighter:getStats() local aspeed = a.fighter:getStat(STATS.SPEED) / (3 ^ (a.number-1))
local bstats = b.fighter:getStats() local bspeed = b.fighter:getStat(STATS.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 if (aspeed == bspeed) then
if (a.fighter.isHero == b.fighter.isHero) then if (a.fighter.isHero == b.fighter.isHero) then