From 5a023ccd1c4e9bd086e473e93e8dccf01c51c7ae Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Tue, 23 Sep 2025 18:35:23 +0000 Subject: [PATCH] =?UTF-8?q?refactor(fight/effect):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=8A=80=E8=83=BD=E4=BC=A4=E5=AE=B3=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=B0=86=E4=BC=A4=E5=AE=B3=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=A7=BB=E8=87=B3Effect0.OnSkill=E6=96=B9=E6=B3=95=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=88=E6=9E=9C=E8=B0=83=E7=94=A8=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/effect/effect_damage.go | 22 +++++++++++++++++++++ logic/service/fight/fightc.go | 22 +++++---------------- logic/service/fight/input/input.go | 7 +++---- logic/service/fight/input/nodemanger.go | 18 +++++------------ logic/service/fight/node/attack.go | 6 ------ logic/service/fight/node/skill.go | 20 +++++++++++++++++++ 6 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 logic/service/fight/node/skill.go diff --git a/logic/service/fight/effect/effect_damage.go b/logic/service/fight/effect/effect_damage.go index cc16681f3..bbb9c9ac5 100644 --- a/logic/service/fight/effect/effect_damage.go +++ b/logic/service/fight/effect/effect_damage.go @@ -22,6 +22,28 @@ func (this *Effect0) UseSkill(opp *input.Input) bool { return true } +// 使用技能时 +func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) { + + spower := skill.CalculatePower(opp.CurrentPet) + damage := e.Input.GetDamageEffect(0) + damage.Stack(int(spower.IntPart())) + e.Input.Exec(func(t input.Effect) bool { //计算暴击率加成 + + t.IsCrit(opp, skill) + e.Input.AttackValue.IsCritical = skill.Crit + return e.Input.AttackValue.IsCritical == 0 + }) + if e.Input.AttackValue.IsCritical == 1 { + damage.Stack(int(spower.IntPart() * 2)) //暴击翻倍 + + } + if uint32(damage.Stack()) > opp.CurrentPet.Info.Hp { + opp.CurrentPet.Info.Hp = 0 + } else { + opp.CurrentPet.Info.Hp = opp.CurrentPet.Info.Hp - uint32(damage.Stack()) + } +} func (this *Effect0) IsCrit(opp *input.Input, skill *info.SkillEntity) { skill.Crit = 0 CritRate := utils.Max(skill.CritRate, 1) diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index fe0271070..0c3c6f8a8 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -372,7 +372,7 @@ func (f *FightC) parseskill(attacker, defender *input.Input, id *SelectSkillActi temparg := id.Skill.SideEffectArgS for _, v := range id.Skill.SideEffectS { - t, ok := attacker.GetSkillEffect(v) + t, ok := input.Geteffect(v + 1000000) if ok { //获取成功 @@ -435,24 +435,12 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *SelectSk attacker.AttackValue.AttackTime = a.Skill.AttackTime if attacker.AttackValue.AttackTime > 0 { //如果命中 f.parseskill(attacker, defender, a) //命中后解析effect - spower := a.Skill.CalculatePower(defender.CurrentPet) - damage := attacker.GetDamageEffect(0) - damage.Stack(int(spower.IntPart())) - attacker.Exec(func(t input.Effect) bool { //计算暴击率加成 + attacker.Exec(func(t input.Effect) bool { - t.IsCrit(defender, a.Skill) - attacker.AttackValue.IsCritical = a.Skill.Crit - return attacker.AttackValue.IsCritical == 0 + t.OnSkill(defender, a.Skill) //调用伤害计算 + + return true }) - if attacker.AttackValue.IsCritical == 1 { - damage.Stack(int(spower.IntPart() * 2)) //暴击翻倍 - - } - if uint32(damage.Stack()) > defender.CurrentPet.Info.Hp { - defender.CurrentPet.Info.Hp = 0 - } else { - defender.CurrentPet.Info.Hp = defender.CurrentPet.Info.Hp - uint32(damage.Stack()) - } // 扣减防御方血量 } //todo 处理未命中效果 diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index 4f0779555..d3bdc226c 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -8,7 +8,6 @@ import ( "github.com/gogf/gf/v2/util/gconv" "github.com/jinzhu/copier" - "github.com/mohae/deepcopy" ) type Input struct { @@ -27,9 +26,9 @@ type Input struct { func NewInput(c common.FightI, p common.PlayerI) *Input { ret := &Input{FightC: c, Player: p} - t := ret.GetDamageEffect(0) - ret.AddEffect(deepcopy.Copy(t).(Effect)) //添加默认基类,实现继承 - p.SetFightC(c) //给玩家设置战斗容器 + t, _ := Geteffect(4000000) + ret.AddEffect(t) //添加默认基类,实现继承 + p.SetFightC(c) //给玩家设置战斗容器 return ret } diff --git a/logic/service/fight/input/nodemanger.go b/logic/service/fight/input/nodemanger.go index 8c38a8bf9..25f171396 100644 --- a/logic/service/fight/input/nodemanger.go +++ b/logic/service/fight/input/nodemanger.go @@ -35,7 +35,7 @@ type Effect interface { IsHit(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断 TakeHit(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断 //() bool // 暴击伤害结算后触发 - + OnSkill(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断 // OnHit() bool // 技能命中时触发 // OnMiss() bool // 技能未命中时触发 // AfterAttacked() bool // 被攻击后触发(受击判定) @@ -88,7 +88,7 @@ func InitSkillEffect(id int, t Effect) { NodeM[id+1000000] = t } -func (c *Input) geteffect(id int) (Effect, bool) { +func Geteffect(id int) (Effect, bool) { //todo 获取前GetEffect ret, ok := NodeM[id] @@ -99,16 +99,7 @@ func (c *Input) geteffect(id int) (Effect, bool) { return nil, false //todo 获取后GetEffect } -func (c *Input) GetSkillEffect(id int) (Effect, bool) { - ret, ok := c.geteffect(id) - if ok { - //todo 获取前GetEffect - return ret, ok - //todo 获取后GetEffect - } - return nil, false -} func InitPropEffect(id int, t Effect) { NodeM[id+2000000] = t @@ -142,7 +133,8 @@ func InitDamageEffect(id int, t Effect) { // 1为红伤 func (c *Input) GetDamageEffect(id int) Effect { - ret, ok := c.geteffect(id + 1000000) + + ret, ok := Geteffect(id + 1000000) if ok { //todo 获取前GetEffect return ret @@ -157,7 +149,7 @@ func InitStatusEffect(id int, t Effect) { } func (c *Input) GetStatusEffect(id int) (Effect, bool) { - ret, ok := c.geteffect(id + 3000000) + ret, ok := Geteffect(id + 3000000) if ok { //todo 获取前GetEffect return ret, true diff --git a/logic/service/fight/node/attack.go b/logic/service/fight/node/attack.go index d6ee165e4..4015c36a2 100644 --- a/logic/service/fight/node/attack.go +++ b/logic/service/fight/node/attack.go @@ -15,13 +15,7 @@ func (this *EffectNode) TakeHit(opp *input.Input, skill *info.SkillEntity) { } -func (this *EffectNode) UseSkill(opp *input.Input) bool { - return this.Input.CurrentPet.HP != 0 -} -func (this *EffectNode) OnSkillPP() bool { - panic("not implemented") // TODO: Implement -} func (this *EffectNode) SkillUseEnd() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/node/skill.go b/logic/service/fight/node/skill.go new file mode 100644 index 000000000..2bc51adf8 --- /dev/null +++ b/logic/service/fight/node/skill.go @@ -0,0 +1,20 @@ +package node + +import ( + "blazing/logic/service/fight/info" + "blazing/logic/service/fight/input" +) + +// 使用技能前 +func (e *EffectNode) UseSkill(opp *input.Input) bool { + + return e.Input.CurrentPet.HP != 0 +} + +// 使用技能时 +func (e *EffectNode) OnSkill(opp *input.Input, skill *info.SkillEntity) { + +} +func (e *EffectNode) OnSkillPP() bool { + panic("not implemented") // TODO: Implement +}