refactor(fight): 重构战斗节点触发机制并完善效果接口

This commit is contained in:
1
2025-08-26 20:01:20 +00:00
parent e3184646e4
commit a14481a2dd
12 changed files with 273 additions and 62 deletions

View File

@@ -6,12 +6,13 @@ type Effect1 struct {
node.Node
}
// 重写EFFect方法
func (this *Effect1) ID() int {
return 1
}
func init() {
node.NodeM.AddEffect(&Effect1{})
}
// 重写EFFectID
func (this *Effect1) ID() int {
this.Node.ParamSize(0) //设置参数个数
return 1
}

View File

@@ -1,14 +1,11 @@
package node
// 技能效果前
func (this *Node) PreActive() func() {
func (this *Node) PreActive() bool {
return this.OnActive() //默认返回,继续执行代码
return true
}
// 执行技能效果
func (this *Node) OnActive() func() {
return nil //返回空,说明这个节点后续没有追加节点
func (f *Node) OnActive() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -2,30 +2,30 @@ package node
// 返回false阻止继续运行
// 回合开始
func (this *Node) PreBattleStart() func() {
func (this *Node) PreBattleStart() bool {
return this.OnBattleStart()
return true
}
// 返回false阻止继续运行
// 回合开始
func (this *Node) OnBattleStart() func() {
func (this *Node) OnBattleStart() bool {
return nil
return true
}
//回合结束前
func (this *Node) PreBattleEnd() func() {
return this.OnBattleEnd()
func (this *Node) PreBattleEnd() bool {
return true
}
//回合结束
func (this *Node) OnBattleEnd() func() {
return nil
func (this *Node) OnBattleEnd() bool {
return true
}

View File

@@ -0,0 +1,10 @@
package node
// 治疗相关触发
func (this *Node) OnBeforeHeal() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnHeal() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -1,19 +1,18 @@
package node
// 精灵切换
func (this *Node) PreSwitch() func() {
return this.OnSwitch()
// 精灵切换相关触发
func (this *Node) OnSwitchIn() bool {
panic("not implemented") // TODO: Implement
}
// 精灵切换时
func (this *Node) OnSwitch() func() {
return this.AfterSwitch()
func (this *Node) OnSwitchOut() bool {
panic("not implemented") // TODO: Implement
}
// 精灵切换后
func (this *Node) AfterSwitch() func() {
return nil
func (this *Node) OnOwnerSwitchIn() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnOwnerSwitchOut() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -1,15 +1,15 @@
package node
// 先手选择前
func (this *Node) BeforeSort() func() {
return this.OnSort()
func (this *Node) BeforeSort() bool {
return true
}
func (this *Node) OnSort() func() {
func (this *Node) OnSort() bool {
//todo 这里待实现对action先手的判断
return nil
return true
}

View File

@@ -0,0 +1,18 @@
package node
// 堆叠Stack相关触发
func (this *Node) OnStackBefore() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnStack() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnBeforeConsumeStack() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnConsumeStack() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -1,13 +1,20 @@
package node
// 回合开始前
func (this *Node) PreTurnStart() func() {
return this.OnTurnStart()
func (this *Node) PreTurnStart() bool {
return true
}
// 回合开始
func (this *Node) OnTurnStart() func() {
return nil
func (this *Node) OnTurnStart() bool {
return true
}
func (this *Node) PreTurnEnd() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) TurnEnd() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -0,0 +1,65 @@
package node
func (this *Node) BeforeUseSkillCheck() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) AfterUseSkillCheck() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) SkillUseEnd() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) BeforeMultiHit() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) BeforeHit() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnCritPreDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) PreDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnBeforeCalculateDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) Shield() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) PostDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnCritPostDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnHit() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnMiss() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) AfterAttacked() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnDefeat() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -33,19 +33,22 @@ func (c *NodeManager) AddEffect(e Effect) {
// 触发执行
func (c *NodeManager) Trigger() {
c.Exec(func(e Effect) bool {
return e.OnTurnStart()
PreBattleStart := c.Exec(func(e Effect) bool {
return e.PreBattleStart()
}) //回合开始
if PreBattleStart { //说明上一步骤没有阻止执行
}
//假如说这里需要能力提升
c.Exec(func(e Effect) bool {
return e.OnBeforeAddMark()
})
// c.Exec(func(e Effect) func() {
// return e.OnBeforeAddMark()
// })
//添加印记前的效果如果有任何一个false,说明组织了添加效果
//这里能力提升
c.Exec(func(e Effect) bool {
return e.OnAnyMarkAdded()
})
// c.Exec(func(e Effect) bool {
// return e.OnAnyMarkAdded()
// })
// var candidates []*Effect
// for _, eff := range c.Effects {
@@ -103,11 +106,14 @@ func (c *NodeManager) removeEffect(e Effect) {
// ForEachEffectBool 遍历所有 Effect执行“无参数、返回 bool”的方法
// 参数 fn接收单个 Effect返回 bool如 func(e Effect) bool { return e.OnBattleStart() }
// 返回值:所有 Effect 的方法返回值列表
func (c *NodeManager) Exec(fn func(Effect) bool) []bool {
func (c *NodeManager) Exec(fn func(Effect) bool) bool {
results := make([]bool, 0, len(c.Effects))
var results bool
for _, effect := range c.Effects {
results = append(results, fn(effect))
result := fn(effect)
if !result {
results = result //如果是false,说明存在阻止向下执行的effect比如免疫能力提升效果
}
}
return results
}

View File

@@ -0,0 +1,26 @@
package node
// 印记Mark相关触发 状态类
func (this *Node) OnBeforeAddMark() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnAnyMarkAdded() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnMarkCreated() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnMarkDurationEnd() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnRemoveMark() bool {
panic("not implemented") // TODO: Implement
}
func (this *Node) OnMarkDestroy() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -4,12 +4,80 @@ import (
"context"
)
type Effect interface {
OnBattleStart() func()
OnBattleEnd() func()
OnActive() func()
OnSwitch() func()
OnTurnStart() func()
PreBattleStart() bool //战斗开始前
OnBattleStart() bool //战斗开始
PreTurnStart() bool //回合开始前
OnTurnStart() bool //回合开始
PreActive() bool //效果生效前
OnActive() bool //效果生效
BeforeUseSkillCheck() bool //使用技能前
AfterUseSkillCheck() bool //使用技能后
SkillUseEnd() bool //技能使用结束
BeforeMultiHit() bool //多段攻击前
BeforeHit() bool //命中前
OnCritPreDamage() bool //暴击判定成功且伤害计算前触发
PreDamage() bool // 技能伤害计算前触发(增伤 / 减伤等)
OnBeforeCalculateDamage() bool // 最终伤害计算前触发
OnDamage() bool // 造成伤害时触发
Shield() bool // 护盾值变化时触发
PostDamage() bool // 伤害结算后触发(血量扣除后)
OnCritPostDamage() bool // 暴击伤害结算后触发
OnHit() bool // 技能命中时触发
OnMiss() bool // 技能未命中时触发
AfterAttacked() bool // 被攻击后触发(受击判定)
OnDefeat() bool // 精灵被击败时触发
// BeforeTransform EnumEffectTrigger enum:"19" // 变形 / 进化前触发
// OnTransform EnumEffectTrigger enum:"20" // 精灵变形 / 进化时触发
// AfterTransform EnumEffectTrigger enum:"21" // 变形 / 进化后触发
// OnTransformEnd EnumEffectTrigger enum:"22" // 变形 / 进化结束时触发
PreTurnEnd() bool // 回合结束前
TurnEnd() bool // 回合结束
// 印记Mark相关触发
OnBeforeAddMark() bool // 添加印记前触发
OnAnyMarkAdded() bool // 任何印记添加时触发
OnMarkCreated() bool // 印记创建时触发
OnMarkDurationEnd() bool // 印记持续回合结束时触发
OnRemoveMark() bool // 移除印记时触发
OnMarkDestroy() bool // 印记销毁时触发
// 堆叠Stack相关触发
OnStackBefore() bool // 堆叠效果前触发
OnStack() bool // 堆叠效果触发
OnBeforeConsumeStack() bool // 消耗堆叠前触发
OnConsumeStack() bool // 消耗堆叠时触发
// 治疗相关触发
OnBeforeHeal() bool // 治疗前触发
OnHeal() bool // 治疗生效时触发
// // 怒气Rage相关触发
// BeforeRageGain EnumEffectTrigger enum:"37" // 增怒前触发
// OnRageGain EnumEffectTrigger enum:"38" // 增怒时触发
// BeforeRageLoss EnumEffectTrigger enum:"39" // 减怒前触发
// OnRageLoss EnumEffectTrigger enum:"40" // 减怒时触发
// 精灵切换相关触发
OnSwitchIn() bool // 精灵出战 / 上场时触发
OnSwitchOut() bool // 精灵下场时触发
OnOwnerSwitchIn() bool // 所属玩家精灵出战时触发
OnOwnerSwitchOut() bool // 所属玩家精灵下场时触发
PreBattleEnd() bool //战斗结束前
OnBattleEnd() bool //战斗结束
Duration(int) int
ID() int
@@ -23,11 +91,12 @@ type Effect interface {
type Node struct {
//Turn int // 当前回合数 ,回合数其实从战斗的上下文中获取
//本质上ctx还要传入战斗双方数据来判断是否是本精灵切换
ctx context.Context //节点上下文
duration int // 持续回合/次0 = 即时生效,>0 = 回合数 ,负数是永久)
stacks int // 当前层数
maxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果
ctx context.Context //节点上下文
duration int // 持续回合/次0 = 即时生效,>0 = 回合数 ,负数是永久)
stacks int // 当前层数
paramSize int
maxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果
SideEffectArgs []int // 附加效果参数
//LifeType EnumLifeType //回合效果 是否可持续 继承到下一直精灵 ,这个用重写事件来实现
// Parent string // 上下文来源(比如 "Skill"、"Buff"、"Passive"
@@ -62,3 +131,16 @@ func (this *Node) Duration(t int) int {
return this.duration
}
func (this *Node) SetArgs(args []int) {
this.SideEffectArgs = args
}
func (this *Node) ParamSize(t int) int {
if t != 0 {
this.paramSize = t
}
return this.paramSize
}