refactor(fight): 重构效果系统并优化回合结束逻辑

- 重构 Effect62 结构,增加 SkillUseEnd 和 OnSwitchIn 方法
- 移除 Active.go 文件中的冗余方法
- 修改 PetSwitch.go 中的 OnOwnerSwitchIn 方法,增加效果清除逻辑
- 更新 Battle 结构,将 Effects 字段改为 NodeManagerE 类型
- 重构 NodeManager 为 NodeManagerE,支持回合类和堆叠类效果的区分和管理
This commit is contained in:
2025-09-03 01:30:26 +08:00
parent c42e392efe
commit 3660e7520e
5 changed files with 62 additions and 31 deletions

View File

@@ -43,7 +43,25 @@ func (this *Effect62) TurnEnd() bool {
return true
}
// 激活回合,比如说镇魂歌秒杀
func (this *Effect62) OnActive() bool {
return !this.Hide //返回是否隐藏,正常的话都是可以使用的
func (this *Effect62) SkillUseEnd() bool {
if this.Hide { //如果还在隐藏,就直接返回
return true
}
defer func() { //延迟处理
this.GetBattle().Effects[this.GetInput().UserID].RemoveEffect(this) //如果生效就移除
}()
//否则触发秒杀 在对面使用技能后
return true
}
// 因为对方切精灵,这个效果也要无效掉
func (this *Effect62) OnSwitchIn() bool {
if this.Hide { //如果还在隐藏,就直接返回
return true
}
this.GetBattle().Effects[this.GetInput().UserID].RemoveEffect(this)
//否则触发秒杀 在对面使用技能后
return true
}

View File

@@ -1,13 +0,0 @@
package node
// 技能效果前
func (this *EffectNode) PreActive() bool {
return true
}
// 激活回合,比如说镇魂歌秒杀
func (this *EffectNode) OnActive() bool {
return true
}

View File

@@ -12,7 +12,9 @@ func (this *EffectNode) OnSwitchOut() bool {
}
func (this *EffectNode) OnOwnerSwitchIn() bool {
panic("not implemented") // TODO: Implement
//自身下场清除掉自身的回合效果
this.GetBattle().Effects[this.GetInput().UserID].RemoveEffect(this)
return true
}
func (this *EffectNode) OnOwnerSwitchOut() bool {

View File

@@ -12,7 +12,7 @@ type Battle struct {
Round int //回合数
BattleMode EnumBattleMode //战斗模式
opposite []BattleInputSourceEntity //不同阵营
Effects map[uint32]*NodeManager //挂载effect,实际上是给每个输入源,然后触发时候循环调用Effects ,
Effects map[uint32]*NodeManagerE //挂载effect,实际上是给每个输入源,然后触发时候循环调用Effects ,
//A的effect->触发死亡->这时候就应该调用对手的切换,实现effect62
}

View File

@@ -5,7 +5,6 @@ type Effect interface {
OnTurnStart() bool //回合开始
OnActive() bool //效果生效相当于每次激活
UseSkill() bool //使用技能 可以取消用技能节点
OnSkillPP() bool //技能PP减少节点
BeforeMultiHit() bool //多段攻击前
@@ -71,10 +70,23 @@ type NodeManager struct {
var NodeM = &NodeManager{}
type NodeManagerE struct {
Turn *NodeManager //回合类效果
Mark *NodeManager //堆叠类效果
}
// 添加效果
func (c *NodeManager) AddEffect(e Effect) {
func (c *NodeManagerE) AddEffect(e Effect) {
var fff *NodeManager
switch t := (e.Duration(0) > 1); t { //判断是否是回合类效果
case t: //t>0就是回合类效果了 -1和0都是非回合效果和无限效果,无法被断回合
fff = c.Turn
default:
fff = c.Mark
}
// 如果已有同 ID 的效果,尝试叠加
for _, eff := range c.Effects {
for _, eff := range fff.Effects {
if eff.ID() == e.ID() {
if eff.Stack(0) < eff.MaxStack() { //如果小于最大叠层
eff.Stack(eff.Stack(0)) //获取到当前叠层数然后叠加
@@ -88,31 +100,43 @@ func (c *NodeManager) AddEffect(e Effect) {
}
}
// 否则新加入
c.Effects = append(c.Effects, e)
fff.Effects = append(fff.Effects, e)
}
// 删除
func (c *NodeManager) RemoveEffect(e Effect) {
func (c *NodeManagerE) RemoveEffect(e Effect) {
var remain []Effect
for _, eff := range c.Effects {
if eff != e {
var fff *NodeManager
switch t := (e.Duration(0) > 1); t { //判断是否是回合类效果
case t: //t>0就是回合类效果了 -1和0都是非回合效果和无限效果,无法被断回合
fff = c.Turn
default:
fff = c.Mark
}
for _, eff := range fff.Effects {
if eff.ID() != e.ID() {
remain = append(remain, eff)
}
}
c.Effects = remain
fff.Effects = remain
}
// 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 *NodeManagerE) Exec(fn func(Effect) bool) bool {
var results bool
for _, effect := range c.Effects {
result := fn(effect)
if !result {
results = result //如果是false,说明存在阻止向下执行的effect比如免疫能力提升效果
execfun := func(nm *NodeManager) {
for _, effect := range nm.Effects {
result := fn(effect)
if !result {
results = result //如果是false,说明存在阻止向下执行的effect比如免疫能力提升效果
}
}
}
execfun(c.Mark)
execfun(c.Turn)
return results
}