From 611b284ade62c7090ea507f6905df5cc5aba5d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Sun, 8 Mar 2026 23:43:20 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E6=95=88=E6=9E=9C=E4=B8=AD=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过引入HasPropADD()和HasPropSub()方法来替代循环遍历, 简化了多处战斗效果代码,提高了可读性和性能。 - effect/200.go: 使用HasPropADD()替代循环检测 - effect/418.go: 使用HasPropADD()替代循环检测 - effect/437.go: 使用HasPropADD()替代循环检测 - effect/449.go: 使用HasPropSub()替代循环检测 - effect --- logic/service/fight/effect/200.go | 19 +++++------ logic/service/fight/effect/418.go | 7 ++-- logic/service/fight/effect/434.go | 32 +++++++++++++++++++ logic/service/fight/effect/437.go | 8 ++--- logic/service/fight/effect/449.go | 20 +++++------- logic/service/fight/effect/460.go | 12 +------ logic/service/fight/effect/489.go | 11 +++---- .../fight/effect/{back.go1 => back.go} | 22 ------------- logic/service/fight/effect/effect_419.go | 16 ++++------ .../fight/effect/effect_power_doblue.go | 8 +---- logic/service/fight/input/prop.go | 20 ++++++++++++ 11 files changed, 85 insertions(+), 90 deletions(-) create mode 100644 logic/service/fight/effect/434.go rename logic/service/fight/effect/{back.go1 => back.go} (97%) diff --git a/logic/service/fight/effect/200.go b/logic/service/fight/effect/200.go index 71e1259cf..dbe16128e 100644 --- a/logic/service/fight/effect/200.go +++ b/logic/service/fight/effect/200.go @@ -11,18 +11,15 @@ type Effect200 struct { } func (e *Effect200) OnSkill() bool { + if e.Ctx().Opp.HasPropADD() { + chance := e.Args()[0].IntPart() + success, _, _ := e.Input.Player.Roll(int(chance), 100) + if success { + effectType := int(e.Args()[1].IntPart()) // XX类型 - for _, v := range e.Ctx().Opp.Prop[:] { - if v > 0 { - chance := e.Args()[0].IntPart() - success, _, _ := e.Input.Player.Roll(int(chance), 100) - if success { - effectType := int(e.Args()[1].IntPart()) // XX类型 - - statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) - if statusEffect != nil { - e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) - } + statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) + if statusEffect != nil { + e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) } } diff --git a/logic/service/fight/effect/418.go b/logic/service/fight/effect/418.go index 38bac22b0..6c3d26c7e 100644 --- a/logic/service/fight/effect/418.go +++ b/logic/service/fight/effect/418.go @@ -11,11 +11,8 @@ type Effect418 struct { } func (e *Effect418) OnSkill() bool { - for _, v := range e.Ctx().Opp.Prop[:] { - if v > 0 { - e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1])) - return true - } + if e.Ctx().Opp.HasPropADD() { + e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1])) } diff --git a/logic/service/fight/effect/434.go b/logic/service/fight/effect/434.go new file mode 100644 index 000000000..d26e362a6 --- /dev/null +++ b/logic/service/fight/effect/434.go @@ -0,0 +1,32 @@ +package effect + +import ( + "blazing/logic/service/fight/input" + "blazing/logic/service/fight/node" +) + +// 434 - 若自身处于能力强化状态,则n%几率令对手XX +type Effect434 struct { + node.EffectNode +} + +func (e *Effect434) OnSkill() bool { + if e.Ctx().Our.CurrentPet.HasPositiveBuff() { // 自身处于能力强化状态 + chance := e.Args()[0].IntPart() + success, _, _ := e.Input.Player.Roll(int(chance), 100) + if success { + effectType := int(e.Args()[1].IntPart()) // XX类型,比如麻痹 + + statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) + if statusEffect != nil { + e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) + } + } + } + + return true +} +func init() { + input.InitEffect(input.EffectType.Skill, 434, &Effect434{}) + +} diff --git a/logic/service/fight/effect/437.go b/logic/service/fight/effect/437.go index c4845a880..cdced0fda 100644 --- a/logic/service/fight/effect/437.go +++ b/logic/service/fight/effect/437.go @@ -12,12 +12,8 @@ type Effect437 struct { func (e *Effect437) OnSkill() bool { - for _, v := range e.Ctx().Opp.Prop[:] { - if v > 0 { - - e.Ctx().Opp.SetProp(e.Ctx().Opp, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1])) - return true - } + if e.Ctx().Opp.HasPropADD() { + e.Ctx().Opp.SetProp(e.Ctx().Opp, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[1])) } diff --git a/logic/service/fight/effect/449.go b/logic/service/fight/effect/449.go index 55468d18a..8603d65aa 100644 --- a/logic/service/fight/effect/449.go +++ b/logic/service/fight/effect/449.go @@ -11,20 +11,16 @@ type Effect449 struct { } func (e *Effect449) OnSkill() bool { + if e.Ctx().Opp.HasPropSub() { + chance := e.Args()[0].IntPart() // N% + success, _, _ := e.Input.Player.Roll(int(chance), 100) + if success { + effectType := int(e.Args()[1].IntPart()) // XX类型 - for _, v := range e.Ctx().Opp.Prop[:] { - if v < 0 { - chance := e.Args()[0].IntPart() // N% - success, _, _ := e.Input.Player.Roll(int(chance), 100) - if success { - effectType := int(e.Args()[1].IntPart()) // XX类型 - - statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) - if statusEffect != nil { - e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) - } + statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) + if statusEffect != nil { + e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) } - return true } } diff --git a/logic/service/fight/effect/460.go b/logic/service/fight/effect/460.go index e9d7de153..6c3f498da 100644 --- a/logic/service/fight/effect/460.go +++ b/logic/service/fight/effect/460.go @@ -14,18 +14,8 @@ type Effect460 struct { func (e *Effect460) OnSkill() bool { baseChance := e.Args()[0].IntPart() // m% - // 检查对手是否处于能力强化状态 - extraChance := false - - for _, v := range e.Ctx().Opp.Prop[:] { - if v > 0 { - extraChance = true - } - - } - totalChance := baseChance - if extraChance { + if e.Ctx().Opp.HasPropADD() { totalChance += e.Args()[1].IntPart() } success, _, _ := e.Input.Player.Roll(int(totalChance), 100) diff --git a/logic/service/fight/effect/489.go b/logic/service/fight/effect/489.go index 228881661..3e0696af5 100644 --- a/logic/service/fight/effect/489.go +++ b/logic/service/fight/effect/489.go @@ -12,13 +12,10 @@ type Effect489 struct { } func (e *Effect489) SkillHit_ex() bool { - for _, v := range e.Ctx().Our.Prop[:] { - if v > 0 { - maxHp := e.Ctx().Our.CurrentPet.GetMaxHP() - healAmount := maxHp.Div(e.Args()[0]) // 1/m - e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount) - return true - } + if e.Ctx().Our.HasPropADD() { + maxHp := e.Ctx().Our.CurrentPet.GetMaxHP() + healAmount := maxHp.Div(e.Args()[0]) // 1/m + e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, healAmount) } diff --git a/logic/service/fight/effect/back.go1 b/logic/service/fight/effect/back.go similarity index 97% rename from logic/service/fight/effect/back.go1 rename to logic/service/fight/effect/back.go index f1842084d..d09fa7cf5 100644 --- a/logic/service/fight/effect/back.go1 +++ b/logic/service/fight/effect/back.go @@ -461,28 +461,6 @@ func (e *Effect516) OnSkill() bool { return true } -// 434 - 若自身处于能力强化状态,则n%几率令对手XX -type Effect434 struct { - node.EffectNode -} - -func (e *Effect434) OnSkill() bool { - if e.Ctx().Our.CurrentPet.HasPositiveBuff() { // 自身处于能力强化状态 - chance := e.Args()[0].IntPart() - success, _, _ := e.Input.Player.Roll(int(chance), 100) - if success { - effectType := int(e.Args()[1].IntPart()) // XX类型,比如麻痹 - - statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType) - if statusEffect != nil { - e.Ctx().Opp.AddEffect(e.Ctx().Our, statusEffect) - } - } - } - - return true -} - // 495 - 若对手处于XX状态,则30%几率秒杀对手 type Effect495 struct { node.EffectNode diff --git a/logic/service/fight/effect/effect_419.go b/logic/service/fight/effect/effect_419.go index 6aa8ec1cf..1e9ef3a72 100644 --- a/logic/service/fight/effect/effect_419.go +++ b/logic/service/fight/effect/effect_419.go @@ -14,17 +14,15 @@ type Effect419 struct { } func (e *Effect419) Skill_Use() bool { - for _, V := range e.Ctx().Opp.Prop[:] { - if V > 0 { - fixedDamage := alpacadecimal.NewFromInt(int64(e.Args()[1].IntPart())) // k点固定伤害 + if e.Ctx().Opp.HasPropADD() { + fixedDamage := alpacadecimal.NewFromInt(int64(e.Args()[1].IntPart())) // k点固定伤害 - damageZone := &info.DamageZone{ - Type: info.DamageType.Fixed, - Damage: fixedDamage, - } - e.Ctx().Opp.Damage(e.Ctx().Our, damageZone) - return true + damageZone := &info.DamageZone{ + Type: info.DamageType.Fixed, + Damage: fixedDamage, } + e.Ctx().Opp.Damage(e.Ctx().Our, damageZone) + return true } diff --git a/logic/service/fight/effect/effect_power_doblue.go b/logic/service/fight/effect/effect_power_doblue.go index 780fbe671..702017d45 100644 --- a/logic/service/fight/effect/effect_power_doblue.go +++ b/logic/service/fight/effect/effect_power_doblue.go @@ -83,13 +83,7 @@ func init() { }) registerStatusFunc(431, func(i, o *input.Input) bool { - for _, v := range o.Prop[:] { - - if v < 0 { - return true - } - } - return false + return o.HasPropSub() }) initskill(609, &Effect609{}) } diff --git a/logic/service/fight/input/prop.go b/logic/service/fight/input/prop.go index 71b777ca8..2c6989340 100644 --- a/logic/service/fight/input/prop.go +++ b/logic/service/fight/input/prop.go @@ -1,5 +1,25 @@ package input +func (our *Input) HasPropADD() bool { + for _, v := range our.Prop[:] { + if v > 0 { + + return true + } + + } + return false +} +func (our *Input) HasPropSub() bool { + for _, v := range our.Prop[:] { + if v < 0 { + + return true + } + + } + return false +} func (target *Input) SetProp(source *Input, index, level int8) bool { // 前置状态结算:判断是否允许执行属性操作 canExecute := target.Exec(func(effect Effect) bool {