From d360a8596313a2f71d4c8dc5e3d7266e0e13ee45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Mon, 9 Mar 2026 20:55:04 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E7=B3=BB=E7=BB=9F=E4=B8=AD=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E8=AE=A1=E7=AE=97=E5=92=8C=E9=80=BB=E8=BE=91=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将GetProp方法返回类型从int改为alpacadecimal.Decimal, 避免精度丢失问题 - 修改战斗中速度比较逻辑,使用Decimal的Cmp方法进行比较 - 修正BattlePetEntity中属性计算公式,将乘法改为除法 - 调整伤害累加逻辑,修复SumDamage叠加问题 - 更新攻击力和防御力计算,直接使用Decimal数值 - 移除Effect178、Effect501等未使用的技能效果 - 重构回合处理逻辑,调整死亡判断时机和流程 - 添加TrueFirst字段用于正确跟踪实际先手方 ``` --- logic/service/fight/effect/178.go | 35 +++++++++++++ logic/service/fight/effect/501.go | 29 +++++++++++ logic/service/fight/effect/back.go1 | 45 ----------------- logic/service/fight/effect/effect_115.go | 2 +- logic/service/fight/fightc.go | 49 ++++++++----------- logic/service/fight/info/BattlePetEntity.go | 5 +- logic/service/fight/info/BattleSkillEntity.go | 2 +- logic/service/fight/input/effect.go | 4 +- logic/service/fight/input/fight.go | 12 ++--- logic/service/fight/input/input.go | 2 +- 10 files changed, 98 insertions(+), 87 deletions(-) create mode 100644 logic/service/fight/effect/178.go create mode 100644 logic/service/fight/effect/501.go diff --git a/logic/service/fight/effect/178.go b/logic/service/fight/effect/178.go new file mode 100644 index 000000000..025080ec9 --- /dev/null +++ b/logic/service/fight/effect/178.go @@ -0,0 +1,35 @@ +package effect + +import ( + "blazing/logic/service/fight/action" + "blazing/logic/service/fight/input" + "blazing/logic/service/fight/node" + + "github.com/alpacahq/alpacadecimal" +) + +// 178 - 造成伤害的1/n回复自身体力,若属性相同则造成伤害的1/m回复自身体力 +type Effect178 struct { + node.EffectNode +} + +func (e *Effect178) Skill_Use_ex() bool { + damageDone := e.Ctx().Our.SumDamage + var healAmount alpacadecimal.Decimal + + if e.Ctx().Our.CurrentPet.Type == e.Ctx().Opp.CurrentPet.Type { + // 属性相同,1/m + healAmount = damageDone.Div(e.Args()[1]) + } else { + // 属性不同,1/n + healAmount = damageDone.Div(e.Args()[0]) + } + + e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount) + + return true +} +func init() { + input.InitEffect(input.EffectType.Skill, 178, &Effect178{}) + +} diff --git a/logic/service/fight/effect/501.go b/logic/service/fight/effect/501.go new file mode 100644 index 000000000..4be9908b6 --- /dev/null +++ b/logic/service/fight/effect/501.go @@ -0,0 +1,29 @@ +package effect + +import ( + "blazing/logic/service/fight/input" + "blazing/logic/service/fight/node" +) + +// 501 - 若造成的伤害不足m,则对手XX等级-n +type Effect501 struct { + node.EffectNode +} + +func (e *Effect501) Skill_Use_ex() bool { + damageThreshold := int(e.Args()[0].IntPart()) + damageDone := e.Ctx().Our.SumDamage + + if damageDone.IntPart() < int64(damageThreshold) { + effectType := int8(e.Args()[1].IntPart()) // XX类型 + effectValue := int8(e.Args()[2].IntPart()) // 等级-n + e.Ctx().Opp.SetProp(e.Ctx().Our, effectType, effectValue) + + } + + return true +} +func init() { + input.InitEffect(input.EffectType.Skill, 501, &Effect501{}) + +} diff --git a/logic/service/fight/effect/back.go1 b/logic/service/fight/effect/back.go1 index 0c53455e6..165b2bf61 100644 --- a/logic/service/fight/effect/back.go1 +++ b/logic/service/fight/effect/back.go1 @@ -206,28 +206,6 @@ func (e *Effect177) SetArgs(t *input.Input, a ...int) { e.EffectNode.Duration(a[0]) // 持续n回合 } -// 178 - 造成伤害的1/n回复自身体力,若属性相同则造成伤害的1/m回复自身体力 -type Effect178 struct { - node.EffectNode -} - -func (e *Effect178) SkillHit_ex() bool { - damageDone := e.Ctx().Our.SumDamage - var healAmount alpacadecimal.Decimal - - if e.Ctx().Our.CurrentPet.Type == e.Ctx().Opp.CurrentPet.Type { - // 属性相同,1/m - healAmount = damageDone.Div(e.Args()[1]) - } else { - // 属性不同,1/n - healAmount = damageDone.Div(e.Args()[0]) - } - - e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount) - - return true -} - // 475 - 若造成的伤害不足m,则下n回合的攻击必定致命一击 type Effect475 struct { node.EffectNode @@ -253,29 +231,6 @@ func (e *Effect475) SkillHit_ex() bool { return true } -// 501 - 若造成的伤害不足m,则对手XX等级-n -type Effect501 struct { - node.EffectNode -} - -func (e *Effect501) SkillHit_ex() bool { - damageThreshold := int(e.Args()[0].IntPart()) - damageDone := e.Ctx().Our.SumDamage - - if damageDone.IntPart() < int64(damageThreshold) { - effectType := int(e.Args()[1].IntPart()) // XX类型 - effectValue := int(e.Args()[2].IntPart()) // 等级-n - - statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) - if statusEffect != nil { - statusEffect.SetArgs(e.Ctx().Our, -effectValue) // 负值表示降低 - e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) - } - } - - return true -} - // 440 - n回合内对手使用技能消耗的PP值变为m倍 type Effect440 struct { node.EffectNode diff --git a/logic/service/fight/effect/effect_115.go b/logic/service/fight/effect/effect_115.go index 8335abc24..185c456af 100644 --- a/logic/service/fight/effect/effect_115.go +++ b/logic/service/fight/effect/effect_115.go @@ -30,7 +30,7 @@ func (e *Effect115) Skill_Use() bool { if !ok { return true } - rr := alpacadecimal.NewFromInt(int64(e.Ctx().Our.GetProp(4))).Div(alpacadecimal.NewFromInt(int64(e.SideEffectArgs[1]))) + rr := e.Ctx().Our.GetProp(4).Div(alpacadecimal.NewFromInt(int64(e.SideEffectArgs[1]))) e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{ Type: info.DamageType.Fixed, diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 6245bed93..132be52fa 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -170,11 +170,11 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) firstAttack, secondAttack = secondAttack, firstAttack //互换先手权 f.First, f.Second = f.Second, f.First case firstAttack.SkillEntity.XML.Priority == secondAttack.SkillEntity.XML.Priority: - if f.Second.GetProp(4) > f.First.GetProp(4) { + if f.Second.GetProp(4).Cmp(f.First.GetProp(4)) > 0 { firstAttack, secondAttack = secondAttack, firstAttack //互换先手权 f.First, f.Second = f.Second, f.First } - if f.Second.GetProp(4) == f.First.GetProp(4) { + if f.Second.GetProp(4).Cmp(f.First.GetProp(4)) == 0 { if grand.Meet(1, 2) { //随机出手 firstAttack, secondAttack = secondAttack, firstAttack //互换先手权 f.First, f.Second = f.Second, f.First @@ -188,7 +188,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) f.First, f.Second = f.Second, f.First } var attacker, defender *input.Input - + f.TrueFirst = f.First //开始回合操作 for i := 0; i < 2; i++ { var originalSkill *info.SkillEntity //原始技能 @@ -229,17 +229,6 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) } //先手权不一定出手 - // if i == 0 { - // //不能使用,所以这时候取消后手 - // defender.ReactvieEffect() - // firstAttack, secondAttack = secondAttack, firstAttack //互换先手权 - // f.First, f.Second = f.Second, f.First - // //反转先后手 - // originalSkill = f.copySkill(firstAttack) - - // currentSkill = originalSkill - // attacker, defender = defender, attacker - // } } else { @@ -256,16 +245,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) skill.PP-- } } - - if defender.CurrentPet.Info.Hp <= 0 && attacker.CurrentPet.Info.Hp <= 0 { //先手方死亡,触发反同归于尽 - attacker.CurrentPet.Info.Hp = 1 - } - if defender.CurrentPet.Info.Hp <= 0 { - - f.TURNOVER(defender) - - break - } else { + if defender.CurrentPet.Info.Hp > 0 { //技能使用后 defender.Exec(func(effect input.Effect) bool { //技能使用后的我方效果 effect.Ctx().SkillEntity = currentSkill @@ -273,18 +253,14 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) return true }) } - if attacker.CurrentPet.Info.Hp <= 0 { - f.TURNOVER(attacker) - break - } else { + if attacker.CurrentPet.Info.Hp > 0 { //技能使用后 attacker.Exec(func(effect input.Effect) bool { //技能使用后的我方效果 effect.Ctx().SkillEntity = currentSkill effect.Skill_Use() return true }) - } //技能使用后 @@ -299,6 +275,21 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) effect.Action_end_ex() return true }) + if defender.CurrentPet.Info.Hp <= 0 && attacker.CurrentPet.Info.Hp <= 0 { //先手方死亡,触发反同归于尽 + attacker.CurrentPet.Info.Hp = 1 + } + if defender.CurrentPet.Info.Hp <= 0 { + + f.TURNOVER(defender) + + break + } + if attacker.CurrentPet.Info.Hp <= 0 { + f.TURNOVER(attacker) + + break + } + } f.Broadcast(func(ff *input.Input) { diff --git a/logic/service/fight/info/BattlePetEntity.go b/logic/service/fight/info/BattlePetEntity.go index 79769c5fb..16893f6c8 100644 --- a/logic/service/fight/info/BattlePetEntity.go +++ b/logic/service/fight/info/BattlePetEntity.go @@ -61,8 +61,9 @@ func CalculateRealValue(value alpacadecimal.Decimal, stat1 int8) alpacadecimal.D two := alpacadecimal.NewFromInt(2) stat := alpacadecimal.NewFromInt(int64(stat1)) if stat.IsPositive() { - value.Mul(stat.Add(two).Mul(two)) - r := value.Mul(stat.Add(two).Mul(two)) + + r := value.Mul(stat.Add(two).Div(two)) + // println(value.IntPart(), r.IntPart(), "强化后数值") return r } else { diff --git a/logic/service/fight/info/BattleSkillEntity.go b/logic/service/fight/info/BattleSkillEntity.go index 223538295..b4640c287 100644 --- a/logic/service/fight/info/BattleSkillEntity.go +++ b/logic/service/fight/info/BattleSkillEntity.go @@ -77,7 +77,7 @@ func CreateSkill(skill *model.SkillInfo, rand *rand.Rand, pet *BattlePetEntity) ret.XML = move } ret.Accuracy = alpacadecimal.NewFromInt(int64(move.Accuracy)) - println(ret.Accuracy.IntPart()) + // println(ret.Accuracy.IntPart()) ret.Info = skill return &ret diff --git a/logic/service/fight/input/effect.go b/logic/service/fight/input/effect.go index 9cdb75e76..0a19413ba 100644 --- a/logic/service/fight/input/effect.go +++ b/logic/service/fight/input/effect.go @@ -92,7 +92,7 @@ func (our *Input) InitEffect(etype EnumEffectType, id int, a ...int) Effect { // * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5) // 是否需要真实提升 -func (our *Input) GetProp(id int) int { +func (our *Input) GetProp(id int) alpacadecimal.Decimal { // 计算实际值(这里可以插入后续优化的函数调用) realValue := info.CalculateRealValue(alpacadecimal.NewFromInt(int64(our.CurrentPet.Info.Prop[id])), our.AttackValue.Prop[id]) @@ -100,7 +100,7 @@ func (our *Input) GetProp(id int) int { // todo: 插入获取后处理函数,例如: // realValue = postProcessValue(realValue, id, c) - return int(realValue.IntPart()) + return realValue } diff --git a/logic/service/fight/input/fight.go b/logic/service/fight/input/fight.go index 3baf565e2..c6fc86275 100644 --- a/logic/service/fight/input/fight.go +++ b/logic/service/fight/input/fight.go @@ -154,8 +154,8 @@ func (our *Input) Damage(in *Input, sub *info.DamageZone) { } if sub.Type == info.DamageType.Red { //红才会产生造成伤害 - our.Opp.SumDamage = sub.Damage // 叠加总伤害 这里相当于记录红伤 - our.Opp.AttackValue.LostHp = uint32(our.Opp.SumDamage.IntPart()) //红伤落实 + our.Opp.SumDamage = sub.Damage.Add(our.Opp.SumDamage) // 叠加总伤害 这里相当于记录红伤 + } if uint32(sub.Damage.IntPart()) > our.CurrentPet.Info.Hp { @@ -184,13 +184,13 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca switch skill.Category() { //判断技能类型 case info.Category.PHYSICAL: - attackDec = alpacadecimal.NewFromInt(int64(our.GetProp(0))) - defenseDec = alpacadecimal.NewFromInt(int64(deftype.GetProp(1))) + attackDec = our.GetProp(0) + defenseDec = our.GetProp(1) case info.Category.SPECIAL: - attackDec = alpacadecimal.NewFromInt(int64(our.GetProp(2))) - defenseDec = alpacadecimal.NewFromInt(int64(deftype.GetProp(3))) + attackDec = our.GetProp(2) + defenseDec = our.GetProp(3) default: return alpacadecimal.Zero diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index c909d3975..db27f63de 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -165,7 +165,7 @@ func (our *Input) GenInfo() { our.RemainHp = int32(our.CurrentPet.Info.Hp) our.SkillList = our.CurrentPet.Info.SkillList - + our.AttackValue.LostHp = uint32(our.SumDamage.IntPart()) //红伤落实 // f.Second.SkillList = f.Second.CurrentPet.Info.SkillList // f.Second.RemainHp = int32(f.Second.CurrentPet.Info.Hp) // ret.FAttack = *f.First.AttackValue