refactor(fight): 重构战斗节点模块并添加效果管理
This commit is contained in:
17
logic/service/fight/battle/effect/effect_1.go
Normal file
17
logic/service/fight/battle/effect/effect_1.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package effect
|
||||
|
||||
import "blazing/logic/service/fight/battle/node"
|
||||
|
||||
type Effect1 struct {
|
||||
node.Node
|
||||
}
|
||||
|
||||
// 重写EFFect方法
|
||||
func (this *Effect1) ID() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
node.NodeM.AddEffect(&Effect1{})
|
||||
}
|
||||
14
logic/service/fight/battle/node/Active.go
Normal file
14
logic/service/fight/battle/node/Active.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package node
|
||||
|
||||
// 技能效果前
|
||||
func (this *Node) PreActive() func() {
|
||||
|
||||
return this.OnActive() //默认返回,继续执行代码
|
||||
|
||||
}
|
||||
|
||||
// 执行技能效果
|
||||
func (this *Node) OnActive() func() {
|
||||
return nil //返回空,说明这个节点后续没有追加节点
|
||||
|
||||
}
|
||||
31
logic/service/fight/battle/node/Battle.go
Normal file
31
logic/service/fight/battle/node/Battle.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package node
|
||||
|
||||
// 返回false阻止继续运行
|
||||
// 回合开始
|
||||
func (this *Node) PreBattleStart() func() {
|
||||
|
||||
return this.OnBattleStart()
|
||||
|
||||
}
|
||||
|
||||
// 返回false阻止继续运行
|
||||
// 回合开始
|
||||
func (this *Node) OnBattleStart() func() {
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
//回合结束前
|
||||
|
||||
func (this *Node) PreBattleEnd() func() {
|
||||
return this.OnBattleEnd()
|
||||
|
||||
}
|
||||
|
||||
//回合结束
|
||||
|
||||
func (this *Node) OnBattleEnd() func() {
|
||||
return nil
|
||||
|
||||
}
|
||||
19
logic/service/fight/battle/node/PetSwitch.go
Normal file
19
logic/service/fight/battle/node/PetSwitch.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package node
|
||||
|
||||
// 精灵切换前
|
||||
func (this *Node) PreSwitch() func() {
|
||||
return this.OnSwitch()
|
||||
|
||||
}
|
||||
|
||||
// 精灵切换时
|
||||
func (this *Node) OnSwitch() func() {
|
||||
return this.AfterSwitch()
|
||||
|
||||
}
|
||||
|
||||
// 精灵切换后
|
||||
func (this *Node) AfterSwitch() func() {
|
||||
return nil
|
||||
|
||||
}
|
||||
15
logic/service/fight/battle/node/Sort.go
Normal file
15
logic/service/fight/battle/node/Sort.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package node
|
||||
|
||||
// 先手选择前
|
||||
func (this *Node) BeforeSort() func() {
|
||||
return this.OnSort()
|
||||
|
||||
}
|
||||
|
||||
func (this *Node) OnSort() func() {
|
||||
|
||||
//todo 这里待实现对action先手的判断
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
13
logic/service/fight/battle/node/Turn.go
Normal file
13
logic/service/fight/battle/node/Turn.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package node
|
||||
|
||||
// 回合开始前
|
||||
func (this *Node) PreTurnStart() func() {
|
||||
return this.OnTurnStart()
|
||||
|
||||
}
|
||||
|
||||
// 回合开始
|
||||
func (this *Node) OnTurnStart() func() {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -8,6 +8,8 @@ type NodeManager struct {
|
||||
Effects []Effect //effects 实际上全局就是effect无限回合
|
||||
}
|
||||
|
||||
var NodeM = &NodeManager{}
|
||||
|
||||
// 添加效果
|
||||
func (c *NodeManager) AddEffect(e Effect) {
|
||||
// 如果已有同 ID 的效果,尝试叠加
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
package node
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Effect interface {
|
||||
OnBattleStart() bool
|
||||
OnBattleEnd() bool
|
||||
BeforeEffect() bool
|
||||
AfterEffect() bool
|
||||
OnSwitch() bool
|
||||
OnTurnStart() bool
|
||||
OnBattleStart() func()
|
||||
OnBattleEnd() func()
|
||||
OnActive() func()
|
||||
OnSwitch() func()
|
||||
OnTurnStart() func()
|
||||
|
||||
Duration(int) int
|
||||
ID() int
|
||||
|
||||
Stack(int) int
|
||||
MaxStack() int
|
||||
OnBeforeAddMark() bool
|
||||
OnAnyMarkAdded() bool
|
||||
Duration(int) int
|
||||
}
|
||||
|
||||
///基础节点
|
||||
// 检查,激活,延后
|
||||
// /基础节点
|
||||
type Node struct {
|
||||
//Turn int // 当前回合数 ,回合数其实从战斗的上下文中获取
|
||||
//本质上ctx还要传入战斗双方数据来判断是否是本精灵切换
|
||||
@@ -43,7 +44,7 @@ func (this *Node) ID() int {
|
||||
return 0
|
||||
|
||||
}
|
||||
func (this *Node) Stacks(t int) int {
|
||||
func (this *Node) Stack(t int) int {
|
||||
if t != 0 {
|
||||
this.stacks = t
|
||||
}
|
||||
@@ -51,7 +52,7 @@ func (this *Node) Stacks(t int) int {
|
||||
return this.stacks
|
||||
|
||||
}
|
||||
func (this *Node) MaxStacks() int {
|
||||
func (this *Node) MaxStack() int {
|
||||
|
||||
return this.maxStack
|
||||
|
||||
@@ -61,36 +62,3 @@ func (this *Node) Duration(t int) int {
|
||||
return this.duration
|
||||
|
||||
}
|
||||
|
||||
//返回false阻止继续运行
|
||||
//回合开始
|
||||
func (this *Node) OnBattleStart() bool {
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
//回合结束
|
||||
|
||||
func (this *Node) OnBattleEnd() bool {
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
//技能效果前
|
||||
func (this *Node) BeforeEffect() bool {
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
//技能效果前
|
||||
func (this *Node) AfterEffect() bool {
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
//精灵切换时
|
||||
func (this *Node) OnSwitch() bool {
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user