统一处理效果45、51、55、56的属性同步与反转逻辑,优化代码结构并提高可维护性。新增通用效果结构体 `EffectPropSyncReverse` 和操作类型定义,集中管理不同属性操作行为。 fix(controller): 修复玩家离开地图逻辑错误 修正 `FRESH_LEAVE_FIGHT_LEVEL` 接口中 defer 调用为进入地图,并发送角色信息包给客户端以确保状态一致。 feat(effect): 新增天敌机制核心逻辑占位 在 `NewSel14` 效果中添加 `Turn_Start` 方法,实现若遇到天敌则害怕多回合的核心逻辑框架。 chore(config): 更新Boss配置怪物ID及血量 调整Boss ID为2的怪物配置,替换原有Monster ID并设置血量为10,用于测试或平衡调整。 refactor(fight): 优化战斗循环和精灵切换逻辑 整理战斗主循环中的血量赋值语句格式,调整精灵切换时变量顺序以避免潜在问题,并修复死亡标记逻辑。 refactor(node): 恢复BoolisFalse方法实现 取消注释 `BoolisFalse` 方法内容,恢复其正常功能以便其他模块正确判断布尔条件。 style(logic): 格式化代码空行和缩进 清理多余空行,对齐导入语句与其他代码块格式,增强整体代码可读性。 debug(effect): 增加烧伤伤害调试打印 在持续伤害效果中加入println语句,输出实际造成的真实伤害数值便于排查问题。
147 lines
4.3 KiB
Go
147 lines
4.3 KiB
Go
package effect
|
||
|
||
import (
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/logic/service/fight/input"
|
||
"blazing/logic/service/fight/node"
|
||
)
|
||
|
||
// -----------------------------------------------------------
|
||
// 通用效果:属性同步/反转类效果(45/51/55/56)
|
||
// -----------------------------------------------------------
|
||
|
||
// 操作类型定义:区分不同的属性操作
|
||
type propOpType int
|
||
|
||
const (
|
||
opDefenseSync propOpType = iota // 同步防御力(45)
|
||
opAttackSync // 同步攻击力(51)
|
||
opTypeReverse // 反转属性类型(55)
|
||
opTypeSync // 同步属性类型(56)
|
||
)
|
||
|
||
// 效果上下文:存储属性修改前的原始值(用于还原)
|
||
type propOpContext struct {
|
||
oldOurProp uint32 // 我方原始属性值(45/51)
|
||
oldOurType int // 我方原始类型值(56)
|
||
oldOppType int // 对方原始类型值(55)
|
||
propIndex int // 属性索引(0=攻击,1=防御)
|
||
opType propOpType
|
||
}
|
||
|
||
// 全局映射:关联效果ID与对应的操作配置
|
||
var propOpMap = make(map[int]func() propOpContext)
|
||
|
||
// EffectPropSyncReverse:属性同步/反转效果核心结构体
|
||
type EffectPropSyncReverse struct {
|
||
node.EffectNode
|
||
ctx propOpContext // 操作上下文(存储原始值)
|
||
bindpet *info.BattlePetEntity
|
||
}
|
||
|
||
// 工厂函数:创建属性同步/反转效果实例
|
||
func newEffectPropSyncReverse() *EffectPropSyncReverse {
|
||
return &EffectPropSyncReverse{}
|
||
}
|
||
|
||
// 初始化:批量注册所有属性同步/反转类效果
|
||
func init() {
|
||
registerPropSyncReverseEffects()
|
||
}
|
||
|
||
// 批量注册:绑定效果ID与对应的操作配置
|
||
func registerPropSyncReverseEffects() {
|
||
// 效果ID与操作配置的映射
|
||
effectMap := map[int]func() propOpContext{
|
||
45: func() propOpContext { // n回合防御力和对手相同
|
||
return propOpContext{opType: opDefenseSync, propIndex: 1}
|
||
},
|
||
51: func() propOpContext { // n回合攻击力和对手相同
|
||
return propOpContext{opType: opAttackSync, propIndex: 0}
|
||
},
|
||
55: func() propOpContext { // n回合反转属性类型
|
||
return propOpContext{opType: opTypeReverse}
|
||
},
|
||
56: func() propOpContext { // n回合同步属性类型
|
||
return propOpContext{opType: opTypeSync}
|
||
},
|
||
}
|
||
|
||
// 注册到全局映射,并初始化效果
|
||
for effectID, ctxFunc := range effectMap {
|
||
propOpMap[effectID] = ctxFunc
|
||
input.InitEffect(input.EffectType.Skill, effectID, newEffectPropSyncReverse())
|
||
}
|
||
}
|
||
|
||
// SetArgs:设置效果参数(回合数)
|
||
func (e *EffectPropSyncReverse) SetArgs(t *input.Input, a ...int) {
|
||
e.EffectNode.SetArgs(t, a...)
|
||
// 从SideEffectArgs[0]获取持续回合数
|
||
e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0])
|
||
// 初始化操作上下文
|
||
e.ctx = propOpMap[int(e.ID().Suffix())]()
|
||
}
|
||
func (e *EffectPropSyncReverse) OnSkill() bool {
|
||
|
||
if !e.Hit() {
|
||
return true
|
||
}
|
||
if e.bindpet != nil {
|
||
return true
|
||
}
|
||
ourPet := e.Ctx().Our.CurrentPet
|
||
oppPet := e.Ctx().Opp.CurrentPet
|
||
switch e.ctx.opType {
|
||
case opDefenseSync, opAttackSync:
|
||
// 同步攻防属性:保存我方原始值,覆盖为对方值
|
||
e.ctx.oldOurProp = ourPet.Info.Prop[e.ctx.propIndex]
|
||
ourPet.Info.Prop[e.ctx.propIndex] = oppPet.Info.Prop[e.ctx.propIndex]
|
||
|
||
case opTypeReverse:
|
||
// 反转属性类型:保存双方原始值,交换类型
|
||
e.ctx.oldOurType = ourPet.PetInfo.Type
|
||
e.ctx.oldOppType = oppPet.PetInfo.Type
|
||
ourPet.PetInfo.Type, oppPet.PetInfo.Type = oppPet.PetInfo.Type, ourPet.PetInfo.Type
|
||
|
||
case opTypeSync:
|
||
// 同步属性类型:保存我方原始值,覆盖为对方值
|
||
e.ctx.oldOurType = ourPet.PetInfo.Type
|
||
ourPet.PetInfo.Type = oppPet.PetInfo.Type
|
||
}
|
||
|
||
//绑定对方精灵
|
||
e.bindpet = e.Ctx().Opp.CurrentPet
|
||
return true
|
||
}
|
||
|
||
// Alive:效果存活判定(结束时还原属性)
|
||
func (e *EffectPropSyncReverse) Alive(t ...bool) bool {
|
||
if !e.Hit() {
|
||
return true
|
||
}
|
||
|
||
if e.BoolisFalse(t...) {
|
||
ourPet := e.Ctx().Our.CurrentPet
|
||
|
||
oppPet := e.bindpet
|
||
switch e.ctx.opType {
|
||
case opDefenseSync, opAttackSync:
|
||
// 还原攻防属性
|
||
ourPet.Info.Prop[e.ctx.propIndex] = e.ctx.oldOurProp
|
||
|
||
case opTypeReverse:
|
||
// 还原反转的属性类型(恢复双方原始值)
|
||
ourPet.PetInfo.Type = e.ctx.oldOurType
|
||
oppPet.PetInfo.Type = e.ctx.oldOppType
|
||
|
||
case opTypeSync:
|
||
// 还原同步的属性类型
|
||
ourPet.PetInfo.Type = e.ctx.oldOurType
|
||
}
|
||
}
|
||
|
||
return e.EffectNode.Alive(t...)
|
||
|
||
}
|