141 lines
3.8 KiB
Go
141 lines
3.8 KiB
Go
package node
|
|
|
|
import "fmt"
|
|
|
|
// 基础上下文
|
|
type EffectContext struct {
|
|
Turn int // 当前回合数
|
|
Actor string // 当前行动者(谁在出手)
|
|
Target string // 当前目标(技能攻击对象)
|
|
Skill string // 使用的技能
|
|
Extra map[string]interface{} // 临时附加信息(状态、标记、计算中间值等)
|
|
}
|
|
|
|
// 节点类型
|
|
type NodeFunc func(ctx *EffectContext, next func())
|
|
|
|
type EffectNode struct {
|
|
Name string
|
|
Exec NodeFunc
|
|
}
|
|
|
|
// 节点管理器
|
|
type NodeRunner struct {
|
|
nodes []*EffectNode
|
|
index int
|
|
ctx *EffectContext
|
|
}
|
|
|
|
func NewNodeRunner(ctx *EffectContext, nodes []*EffectNode) *NodeRunner {
|
|
return &NodeRunner{
|
|
nodes: nodes,
|
|
index: 0,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// 执行下一个节点
|
|
func (r *NodeRunner) Run() {
|
|
if r.index >= len(r.nodes) {
|
|
return
|
|
}
|
|
current := r.nodes[r.index]
|
|
r.index++
|
|
current.Exec(r.ctx, r.Run)
|
|
}
|
|
|
|
// 跳过当前节点
|
|
func (r *NodeRunner) Skip() {
|
|
r.index++
|
|
r.Run()
|
|
}
|
|
|
|
// ------------------------
|
|
// 定义战斗流程节点
|
|
// ------------------------
|
|
func BuildBattleNodes() []*EffectNode {
|
|
return []*EffectNode{
|
|
{Name: "战斗开始", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("OnBattleStart")
|
|
next()
|
|
}},
|
|
{Name: "登场/切换", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("OnSwitchIn / OnSwitchOut / OnTransform")
|
|
next()
|
|
}},
|
|
{Name: "回合开始", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("TurnStart")
|
|
next()
|
|
}},
|
|
{Name: "操作阶段", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("选择技能 / 使用道具 / 切换")
|
|
next()
|
|
}},
|
|
{Name: "先手判定", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("先手权判定")
|
|
next()
|
|
}},
|
|
{Name: "先手出手-前置", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("BeforeUseSkillCheck / BeforeHit / OnMiss")
|
|
next()
|
|
}},
|
|
{Name: "先手出手-技能命中", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("技能命中判定 / 初始伤害公式 / 红伤数值计算")
|
|
next()
|
|
}},
|
|
{Name: "先手出手-技能效果结算", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("技能效果结算 / 魂印 / 套装 / 回合类效果")
|
|
next()
|
|
}},
|
|
{Name: "先手出手-伤害结算", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("最终伤害生效 / 体力扣除")
|
|
next()
|
|
}},
|
|
{Name: "先手出手-行动结束", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("行动后效果 / 额外行动 / 机盖弹伤 / 出手结束效果")
|
|
next()
|
|
}},
|
|
{Name: "后手出手", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("后手节点同先手节点")
|
|
next()
|
|
}},
|
|
{Name: "回合结束后①", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("回合结束后通用时点① / 桃园回血 / 回合扣减①")
|
|
next()
|
|
}},
|
|
{Name: "回合结束后②", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("回合结束后通用时点② / 战争猎魔 / 16年魂印续航")
|
|
next()
|
|
}},
|
|
{Name: "死亡判定", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("死亡结算 / 保护机制")
|
|
next()
|
|
}},
|
|
{Name: "击败/未击败判定", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("击败触发效果 / 未击败触发效果")
|
|
next()
|
|
}},
|
|
{Name: "进入下回合", Exec: func(ctx *EffectContext, next func()) {
|
|
fmt.Println("进入下回合,流程重新开始")
|
|
next()
|
|
}},
|
|
}
|
|
}
|
|
|
|
// ------------------------
|
|
// 测试运行
|
|
// ------------------------
|
|
func TestBattleFlow() {
|
|
ctx := &EffectContext{
|
|
Turn: 1,
|
|
Actor: "PlayerA",
|
|
Target: "PlayerB",
|
|
Skill: "火球",
|
|
Extra: map[string]interface{}{},
|
|
}
|
|
|
|
nodes := BuildBattleNodes()
|
|
runner := NewNodeRunner(ctx, nodes)
|
|
runner.Run()
|
|
}
|