From b8ce414f112514fd168b780c6b1054d394d2a49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Tue, 10 Mar 2026 00:06:02 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E7=B3=BB=E7=BB=9F=E6=8A=80=E8=83=BD=E6=94=BB?= =?UTF-8?q?=E5=87=BB=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整技能攻击时间判断顺序,提前计算总伤害 - 替换随机数生成函数,使用grand包提供更安全的随机数 - 修复暴击计算中的概率判断逻辑,统一使用Meet函数 - 修正技能伤害计算中防御属性获取错误,应使用目标方属性而非攻击方 - 优化基础伤害公式计算顺序,提升性能 - 添加技能伤害调试输出便于问题排查 ``` --- logic/service/fight/fightc.go | 3 ++- logic/service/fight/info/BattleSkillEntity.go | 5 ++--- logic/service/fight/input/fight.go | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index f2172ba83..cf7cf479e 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -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) } //还原属性 diff --git a/logic/service/fight/info/BattleSkillEntity.go b/logic/service/fight/info/BattleSkillEntity.go index b4640c287..db42a9296 100644 --- a/logic/service/fight/info/BattleSkillEntity.go +++ b/logic/service/fight/info/BattleSkillEntity.go @@ -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 } diff --git a/logic/service/fight/input/fight.go b/logic/service/fight/input/fight.go index 77a647b43..533d6148b 100644 --- a/logic/service/fight/input/fight.go +++ b/logic/service/fight/input/fight.go @@ -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 }