37 lines
1.1 KiB
Lua
37 lines
1.1 KiB
Lua
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
|
local BattleConst = require "app/module/battle/battle_const"
|
|
|
|
local BattleFormula = {}
|
|
|
|
local DEFAULT_FACTOR = 10000
|
|
local HURT_STATE_CRIT = BattleConst.HURT_STATE_CRIT
|
|
|
|
function BattleFormula:getDamageOrCureResult(unitComp, buff, targetUnitComp)
|
|
local func = self.calculateFormula[buff:getFormula()]
|
|
if func then
|
|
return func(unitComp, buff, targetUnitComp)
|
|
end
|
|
return 0
|
|
end
|
|
|
|
BattleFormula.calculateFormula = {
|
|
-- 攻击力乘以系数
|
|
[1] = function(unitComp, buff, targetUnit)
|
|
local result = unitComp.unitEntity:getAtk() * buff:getEffectNum() // DEFAULT_FACTOR
|
|
local hurtState = 0
|
|
local crit = unitComp.unitEntity:getCrit()
|
|
if crit > 0 then
|
|
if BattleHelper:random(1, DEFAULT_FACTOR) <= crit then -- 暴击了
|
|
hurtState = HURT_STATE_CRIT
|
|
end
|
|
end
|
|
return result, hurtState
|
|
end,
|
|
-- 目标生命上限的百分比伤害
|
|
[2] = function(unitComp, buff, targetUnit)
|
|
local result = targetUnit.unitEntity:getMaxHp() * buff:getEffectNum() // DEFAULT_FACTOR
|
|
return result, 0
|
|
end
|
|
}
|
|
|
|
return BattleFormula |