From 3fa2cd2f3a58a25d708382b511c356aa9e92e6a3 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Tue, 26 Aug 2025 22:26:21 +0000 Subject: [PATCH] =?UTF-8?q?refactor(fight):=20=E9=87=8D=E6=9E=84=E6=95=88?= =?UTF-8?q?=E6=9E=9C=E8=8A=82=E7=82=B9=E7=BB=A7=E6=89=BF=E4=BD=93=E7=B3=BB?= =?UTF-8?q?=E5=B9=B6=E5=AE=8C=E5=96=84Effect1=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/battle/effect/effect_1.go | 15 +++++++-- logic/service/fight/battle/node/Active.go | 4 +-- logic/service/fight/battle/node/Battle.go | 8 ++--- logic/service/fight/battle/node/Heal.go | 4 +-- logic/service/fight/battle/node/PetSwitch.go | 8 ++--- logic/service/fight/battle/node/Sort.go | 4 +-- logic/service/fight/battle/node/Stack.go | 8 ++--- logic/service/fight/battle/node/Turn.go | 10 +++--- logic/service/fight/battle/node/attack.go | 32 +++++++++---------- logic/service/fight/battle/node/mark.go | 12 +++---- logic/service/fight/battle/node/node.go | 28 +++++++++------- logic/service/fight/info/BattleSkillEntity.go | 7 ++++ 12 files changed, 82 insertions(+), 58 deletions(-) diff --git a/logic/service/fight/battle/effect/effect_1.go b/logic/service/fight/battle/effect/effect_1.go index c6bcf7f4..855a891f 100644 --- a/logic/service/fight/battle/effect/effect_1.go +++ b/logic/service/fight/battle/effect/effect_1.go @@ -2,8 +2,11 @@ package effect import "blazing/logic/service/fight/battle/node" +/** + * 给予对象损伤一半,会回复自己的体力 + */ type Effect1 struct { - node.Node + node.EffectNode } func init() { @@ -13,6 +16,14 @@ func init() { // 重写EFFectID func (this *Effect1) ID() int { - this.Node.ParamSize(0) //设置参数个数 + this.EffectNode.ParamSize(0) //设置参数个数 + return 1 } + +// 重写EFFectID +func (this *Effect1) PostDamage() bool { + this.EffectNode.ParamSize(0) //设置参数个数 + + return true +} diff --git a/logic/service/fight/battle/node/Active.go b/logic/service/fight/battle/node/Active.go index 5bc8e6a4..1c87827b 100644 --- a/logic/service/fight/battle/node/Active.go +++ b/logic/service/fight/battle/node/Active.go @@ -1,11 +1,11 @@ package node // 技能效果前 -func (this *Node) PreActive() bool { +func (this *EffectNode) PreActive() bool { return true } -func (f *Node) OnActive() bool { +func (f *EffectNode) OnActive() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/Battle.go b/logic/service/fight/battle/node/Battle.go index 7992854e..e99df3d2 100644 --- a/logic/service/fight/battle/node/Battle.go +++ b/logic/service/fight/battle/node/Battle.go @@ -2,7 +2,7 @@ package node // 返回false阻止继续运行 // 回合开始 -func (this *Node) PreBattleStart() bool { +func (this *EffectNode) PreBattleStart() bool { return true @@ -10,7 +10,7 @@ func (this *Node) PreBattleStart() bool { // 返回false阻止继续运行 // 回合开始 -func (this *Node) OnBattleStart() bool { +func (this *EffectNode) OnBattleStart() bool { return true @@ -18,14 +18,14 @@ func (this *Node) OnBattleStart() bool { //回合结束前 -func (this *Node) PreBattleEnd() bool { +func (this *EffectNode) PreBattleEnd() bool { return true } //回合结束 -func (this *Node) OnBattleEnd() bool { +func (this *EffectNode) OnBattleEnd() bool { return true } diff --git a/logic/service/fight/battle/node/Heal.go b/logic/service/fight/battle/node/Heal.go index 93743c96..439c85e4 100644 --- a/logic/service/fight/battle/node/Heal.go +++ b/logic/service/fight/battle/node/Heal.go @@ -1,10 +1,10 @@ package node // 治疗相关触发 -func (this *Node) OnBeforeHeal() bool { +func (this *EffectNode) OnBeforeHeal() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnHeal() bool { +func (this *EffectNode) OnHeal() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/PetSwitch.go b/logic/service/fight/battle/node/PetSwitch.go index 8444c144..fe0e62c4 100644 --- a/logic/service/fight/battle/node/PetSwitch.go +++ b/logic/service/fight/battle/node/PetSwitch.go @@ -1,18 +1,18 @@ package node // 精灵切换相关触发 -func (this *Node) OnSwitchIn() bool { +func (this *EffectNode) OnSwitchIn() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnSwitchOut() bool { +func (this *EffectNode) OnSwitchOut() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnOwnerSwitchIn() bool { +func (this *EffectNode) OnOwnerSwitchIn() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnOwnerSwitchOut() bool { +func (this *EffectNode) OnOwnerSwitchOut() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/Sort.go b/logic/service/fight/battle/node/Sort.go index 8c0782b8..75d4a7c0 100644 --- a/logic/service/fight/battle/node/Sort.go +++ b/logic/service/fight/battle/node/Sort.go @@ -1,12 +1,12 @@ package node // 先手选择前 -func (this *Node) BeforeSort() bool { +func (this *EffectNode) BeforeSort() bool { return true } -func (this *Node) OnSort() bool { +func (this *EffectNode) OnSort() bool { //todo 这里待实现对action先手的判断 diff --git a/logic/service/fight/battle/node/Stack.go b/logic/service/fight/battle/node/Stack.go index 495575b5..2829fc18 100644 --- a/logic/service/fight/battle/node/Stack.go +++ b/logic/service/fight/battle/node/Stack.go @@ -1,18 +1,18 @@ package node // 堆叠(Stack)相关触发 -func (this *Node) OnStackBefore() bool { +func (this *EffectNode) OnStackBefore() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnStack() bool { +func (this *EffectNode) OnStack() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnBeforeConsumeStack() bool { +func (this *EffectNode) OnBeforeConsumeStack() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnConsumeStack() bool { +func (this *EffectNode) OnConsumeStack() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/Turn.go b/logic/service/fight/battle/node/Turn.go index 7b010920..97f5530a 100644 --- a/logic/service/fight/battle/node/Turn.go +++ b/logic/service/fight/battle/node/Turn.go @@ -1,20 +1,22 @@ package node // 回合开始前 -func (this *Node) PreTurnStart() bool { +func (this *EffectNode) PreTurnStart() bool { return true } // 回合开始 -func (this *Node) OnTurnStart() bool { +func (this *EffectNode) OnTurnStart() bool { return true } -func (this *Node) PreTurnEnd() bool { +func (this *EffectNode) PreTurnEnd() bool { panic("not implemented") // TODO: Implement } -func (this *Node) TurnEnd() bool { +// 回合结束一次性effect清楚掉 +func (this *EffectNode) TurnEnd() bool { + panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/attack.go b/logic/service/fight/battle/node/attack.go index f9ad592d..12c69f32 100644 --- a/logic/service/fight/battle/node/attack.go +++ b/logic/service/fight/battle/node/attack.go @@ -1,65 +1,65 @@ package node -func (this *Node) BeforeUseSkillCheck() bool { +func (this *EffectNode) BeforeUseSkillCheck() bool { panic("not implemented") // TODO: Implement } -func (this *Node) AfterUseSkillCheck() bool { +func (this *EffectNode) AfterUseSkillCheck() bool { panic("not implemented") // TODO: Implement } -func (this *Node) SkillUseEnd() bool { +func (this *EffectNode) SkillUseEnd() bool { panic("not implemented") // TODO: Implement } -func (this *Node) BeforeMultiHit() bool { +func (this *EffectNode) BeforeMultiHit() bool { panic("not implemented") // TODO: Implement } -func (this *Node) BeforeHit() bool { +func (this *EffectNode) BeforeHit() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnCritPreDamage() bool { +func (this *EffectNode) OnCritPreDamage() bool { panic("not implemented") // TODO: Implement } -func (this *Node) PreDamage() bool { +func (this *EffectNode) PreDamage() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnBeforeCalculateDamage() bool { +func (this *EffectNode) OnBeforeCalculateDamage() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnDamage() bool { +func (this *EffectNode) OnDamage() bool { panic("not implemented") // TODO: Implement } -func (this *Node) Shield() bool { +func (this *EffectNode) Shield() bool { panic("not implemented") // TODO: Implement } -func (this *Node) PostDamage() bool { +func (this *EffectNode) PostDamage() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnCritPostDamage() bool { +func (this *EffectNode) OnCritPostDamage() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnHit() bool { +func (this *EffectNode) OnHit() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnMiss() bool { +func (this *EffectNode) OnMiss() bool { panic("not implemented") // TODO: Implement } -func (this *Node) AfterAttacked() bool { +func (this *EffectNode) AfterAttacked() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnDefeat() bool { +func (this *EffectNode) OnDefeat() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/mark.go b/logic/service/fight/battle/node/mark.go index ab7585c7..3ba851ea 100644 --- a/logic/service/fight/battle/node/mark.go +++ b/logic/service/fight/battle/node/mark.go @@ -1,26 +1,26 @@ package node // 印记(Mark)相关触发 状态类 -func (this *Node) OnBeforeAddMark() bool { +func (this *EffectNode) OnBeforeAddMark() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnAnyMarkAdded() bool { +func (this *EffectNode) OnAnyMarkAdded() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnMarkCreated() bool { +func (this *EffectNode) OnMarkCreated() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnMarkDurationEnd() bool { +func (this *EffectNode) OnMarkDurationEnd() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnRemoveMark() bool { +func (this *EffectNode) OnRemoveMark() bool { panic("not implemented") // TODO: Implement } -func (this *Node) OnMarkDestroy() bool { +func (this *EffectNode) OnMarkDestroy() bool { panic("not implemented") // TODO: Implement } diff --git a/logic/service/fight/battle/node/node.go b/logic/service/fight/battle/node/node.go index 768838c0..988e56ed 100644 --- a/logic/service/fight/battle/node/node.go +++ b/logic/service/fight/battle/node/node.go @@ -2,12 +2,9 @@ package node import ( "context" + "blazing/logic/service/fight/info" ) - - - - type Effect interface { PreBattleStart() bool //战斗开始前 OnBattleStart() bool //战斗开始 @@ -88,15 +85,16 @@ type Effect interface { // 检查,激活,延后 // /基础节点 -type Node struct { +type EffectNode struct { //Turn int // 当前回合数 ,回合数其实从战斗的上下文中获取 //本质上ctx还要传入战斗双方数据来判断是否是本精灵切换 ctx context.Context //节点上下文 - duration int // 持续回合/次(0 = 即时生效,>0 = 回合数 ,负数是永久) + duration int // 默认为1 持续回合/次(0 = 即时生效,>0 = 回合数 ,负数是永久) stacks int // 当前层数 paramSize int maxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果 SideEffectArgs []int // 附加效果参数 + //LifeType EnumLifeType //回合效果 是否可持续 继承到下一直精灵 ,这个用重写事件来实现 // Parent string // 上下文来源(比如 "Skill"、"Buff"、"Passive") @@ -108,12 +106,12 @@ type Node struct { // Done bool // 是否中止后续执行 } -func (this *Node) ID() int { +func (this *EffectNode) ID() int { return 0 } -func (this *Node) Stack(t int) int { +func (this *EffectNode) Stack(t int) int { if t != 0 { this.stacks = t } @@ -121,22 +119,22 @@ func (this *Node) Stack(t int) int { return this.stacks } -func (this *Node) MaxStack() int { +func (this *EffectNode) MaxStack() int { return this.maxStack } -func (this *Node) Duration(t int) int { +func (this *EffectNode) Duration(t int) int { return this.duration } -func (this *Node) SetArgs(args []int) { +func (this *EffectNode) SetArgs(args []int) { this.SideEffectArgs = args } -func (this *Node) ParamSize(t int) int { +func (this *EffectNode) ParamSize(t int) int { if t != 0 { this.paramSize = t } @@ -144,3 +142,9 @@ func (this *Node) ParamSize(t int) int { return this.paramSize } +func (this *EffectNode) GetSkill(t int) *info.BattleSkillEntity { + pet, _ := this.ctx.Value(info.BattleSkillEntityCtx).(*info.BattleSkillEntity) + + return pet + +} diff --git a/logic/service/fight/info/BattleSkillEntity.go b/logic/service/fight/info/BattleSkillEntity.go index 0eeef1f3..beadc8a2 100644 --- a/logic/service/fight/info/BattleSkillEntity.go +++ b/logic/service/fight/info/BattleSkillEntity.go @@ -128,7 +128,14 @@ func (u *BattleSkillEntity) NewBattleAction(ctx context.Context) { ret.ctx = ctx } +// // 技能产生effect +// func (u *BattleSkillEntity) NewEffect(ctx context.Context)*node.EffectNode { +// ret := node.EffectNode{} +// ctx = context.WithValue(ctx, BattleSkillEntityCtx, &ret) //添加用户到上下文 +// ret.ctx = ctx + +// } // 解析副作用参数字符串为整数列表 func parseSideEffectArgs(argsStr string) []int { if argsStr == "" {