feat(fight): 优化战斗系统技能攻击计算逻辑 - 调整技能攻击时间判断顺序,提前计算总伤害 - 替换随机数生成函数,使用grand包提供更安全的随机数 - 修复暴击计算中的概率判断逻辑,统一使用Meet函数 - 修正技能伤害计算中防御属性获取错误,应使用目标方属性而非攻击方 - 优化基础伤害公式计算顺序,提升性能 - 添加技能伤害调试输出便于问题排查 ```
This commit is contained in:
@@ -48,9 +48,10 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *info
|
||||
attacker.SkillID = uint32(skill.XML.ID) //获取技能ID
|
||||
var SumDamage alpacadecimal.Decimal
|
||||
if skill.AttackTime != 0 { //如果命中
|
||||
|
||||
SumDamage = attacker.CalculatePower(defender, skill)
|
||||
attacker.CalculateCrit(defender, skill) //暴击计算
|
||||
attacker.IsCritical = skill.Crit
|
||||
SumDamage = attacker.CalculatePower(defender, skill)
|
||||
}
|
||||
|
||||
//还原属性
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/alpacahq/alpacadecimal"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
@@ -223,9 +224,7 @@ func (s *SkillEntity) CriticalsameTypeBonus() alpacadecimal.Decimal {
|
||||
|
||||
func (s *SkillEntity) Criticalrandom() alpacadecimal.Decimal {
|
||||
|
||||
randomnum := s.Rand.Int31n(39) + 217
|
||||
// 10. 随机倍率,随机值除以255
|
||||
randomFactor := alpacadecimal.NewFromInt(int64(randomnum)).Div(alpacadecimal.NewFromInt(255))
|
||||
randomFactor := alpacadecimal.NewFromInt(int64(grand.N(217, 255))).Div(alpacadecimal.NewFromInt(255))
|
||||
return randomFactor
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/alpacahq/alpacadecimal"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
// 计算暴击
|
||||
@@ -38,7 +39,7 @@ func (our *Input) CalculateCrit(opp *Input, skill *info.SkillEntity) {
|
||||
}
|
||||
|
||||
//todo 暴击伤害
|
||||
if t, _, _ := our.Player.Roll(625*CritRate, 10000); t {
|
||||
if t := grand.Meet(CritRate, 16); t {
|
||||
skill.Crit = 1
|
||||
}
|
||||
|
||||
@@ -185,12 +186,12 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca
|
||||
switch skill.Category() { //判断技能类型
|
||||
case info.Category.PHYSICAL:
|
||||
attackDec = our.GetProp(0)
|
||||
defenseDec = our.GetProp(1)
|
||||
defenseDec = deftype.GetProp(1)
|
||||
|
||||
case info.Category.SPECIAL:
|
||||
|
||||
attackDec = our.GetProp(2)
|
||||
defenseDec = our.GetProp(3)
|
||||
defenseDec = deftype.GetProp(3)
|
||||
|
||||
default:
|
||||
return alpacadecimal.Zero
|
||||
@@ -228,10 +229,9 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca
|
||||
}
|
||||
// 5. 基础伤害公式:等级因子 * 威力因子 * 攻击 / 防御 / 50 + 2
|
||||
baseDamage := levelFactor.
|
||||
Mul(alpacadecimal.NewFromInt(int64(skill.XML.Power))).
|
||||
Mul(attackDec).
|
||||
Div(defenseDec).
|
||||
Div(alpacadecimal.NewFromInt(50)).
|
||||
Mul(alpacadecimal.NewFromInt(int64(skill.XML.Power))).
|
||||
Mul(attackDec.Div(defenseDec)).
|
||||
Add(alpacadecimal.NewFromInt(2))
|
||||
|
||||
var typeRate alpacadecimal.Decimal
|
||||
@@ -246,7 +246,7 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca
|
||||
Mul(typeRate). // 克制系数
|
||||
|
||||
Mul(skill.Criticalrandom()) //随机波动
|
||||
|
||||
println(baseDamage.IntPart(), damage.IntPart(), attackDec.IntPart(), defenseDec.IntPart(), "技能伤害")
|
||||
return damage
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user