improvement: get battle stats from the fighter
It'll allow us later to add battle bonus and malus
This commit is contained in:
parent
32bb1b5425
commit
d4698ab101
5 changed files with 21 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue