45 lines
2.0 KiB
Lua
45 lines
2.0 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+(攻击者元素伤害增加+所有伤害增加)(攻击者)+(受到元素伤害增加+受到所有伤害增加(受击)-受到元素伤害降低-受到所有伤害降低(受击)*暴击伤害
|
|
[1] = function(unitComp, buff, targetUnit)
|
|
local matchType = unitComp.unitEntity:getMatchType()
|
|
local result = unitComp.unitEntity:getAtk() * buff:getEffectNum() // DEFAULT_FACTOR *
|
|
(DEFAULT_FACTOR + unitComp.unitEntity:getDmgAddition() + targetUnit.unitEntity:getWeakness(matchType) - targetUnit.unitEntity:getDmgDec(matchType)) // DEFAULT_FACTOR
|
|
local hurtState = 0
|
|
local crit = unitComp.unitEntity:getCrit()
|
|
if crit > 0 then
|
|
if BattleHelper:random(1, DEFAULT_FACTOR) <= crit then -- 暴击了
|
|
result = result * (BattleHelper:getDefaultCrittime() + unitComp.unitEntity:getCrittime()) // DEFAULT_FACTOR
|
|
hurtState = HURT_STATE_CRIT
|
|
end
|
|
end
|
|
return result, hurtState
|
|
end,
|
|
-- 生命值*回合开始时的回血系数*(1 + 治疗效果增加)
|
|
[2] = function(unitComp, buff, targetUnit)
|
|
local result = targetUnit.unitEntity:getMaxHp() * buff:getEffectNum() // DEFAULT_FACTOR * (unitComp.unitEntity:getCureAddition() + DEFAULT_FACTOR) // DEFAULT_FACTOR
|
|
return result, 0
|
|
end,
|
|
-- 角色攻击力*技能倍率*(1+治疗效果增加)
|
|
[3] = function(unitComp, buff, targetUnit)
|
|
local result = unitComp.unitEntity:getAtk() * buff:getEffectNum() // DEFAULT_FACTOR * (unitComp.unitEntity:getCureAddition() + DEFAULT_FACTOR) // DEFAULT_FACTOR
|
|
return result, 0
|
|
end
|
|
}
|
|
|
|
return BattleFormula |