Files
bl/logic/service/fight/effect/effect_attr.go
昔念 bf79c0fd6a
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
refactor(fight): 移除调试打印语句并优化阻塞策略

移除了effect_attr.go中的调试println语句,将注释掉相关的日志输出,
同时在pack.go中更新了锁策略,从SleepBlockStrategy切换到
ConditionBlockStrategy,并移除了未使用的time包导入
```
2026-03-04 14:45:52 +08:00

178 lines
5.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
opTypeMaxHP // 减少最大生命值38
)
// 效果上下文:存储属性修改前的原始值(用于还原)
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 // 操作上下文(存储原始值)
ourpet *info.BattlePetEntity
opppet *info.BattlePetEntity
isactive bool
can bool
}
// 工厂函数:创建属性同步/反转效果实例
func newEffectPropSyncReverse() *EffectPropSyncReverse {
return &EffectPropSyncReverse{}
}
// 初始化:批量注册所有属性同步/反转类效果
func init() {
registerPropSyncReverseEffects()
}
// 批量注册绑定效果ID与对应的操作配置
func registerPropSyncReverseEffects() {
// 效果ID与操作配置的映射
effectMap := map[int]func() propOpContext{
38: func() propOpContext { // 减少最大生命值
return propOpContext{opType: opTypeMaxHP}
},
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.opppet != nil {
return true
}
e.ourpet = e.Ctx().Our.CurrentPet
e.opppet = e.Ctx().Opp.CurrentPet
e.can = true
e.active(true)
return true
}
// Alive效果存活判定结束时还原属性
func (e *EffectPropSyncReverse) Alive(t ...bool) bool {
if len(t) > 0 {
if t[0] {
e.active(true)
} else {
e.active(false)
}
}
return e.EffectNode.Alive(t...)
}
// Alive效果存活判定结束时还原属性
func (e *EffectPropSyncReverse) active(is bool) {
//println("属性类测试", t)
if !e.can {
return
}
if !is && e.isactive { //取消反转
e.isactive = false
switch e.ctx.opType {
case opDefenseSync, opAttackSync:
// 还原攻防属性
e.ourpet.Info.Prop[e.ctx.propIndex] = e.ctx.oldOurProp
case opTypeReverse:
// 还原反转的属性类型(恢复双方原始值)
e.ourpet.PetInfo.Type = e.ctx.oldOurType
e.ourpet.PetInfo.Type = e.ctx.oldOppType
// println("Effect55_o取消效果", e.ourpet.PetInfo.Type, e.opppet.PetInfo.Type)
case opTypeSync:
// 还原同步的属性类型
e.ourpet.PetInfo.Type = e.ctx.oldOurType
default:
// case opTypeMaxHP: // 减少最大生命值
// oppPet.Info.MaxHp += uint32(e.Args()[0].IntPart())
}
}
if is && !e.isactive { //激活
e.isactive = true
switch e.ctx.opType {
case opDefenseSync, opAttackSync:
// 同步攻防属性:保存我方原始值,覆盖为对方值
e.ctx.oldOurProp = e.ourpet.Info.Prop[e.ctx.propIndex]
e.ourpet.Info.Prop[e.ctx.propIndex] = e.opppet.Info.Prop[e.ctx.propIndex]
case opTypeReverse:
// 反转属性类型:保存双方原始值,交换类型
e.ctx.oldOurType = e.ourpet.PetInfo.Type
e.ctx.oldOppType = e.opppet.PetInfo.Type
e.ourpet.PetInfo.Type, e.opppet.PetInfo.Type = e.opppet.PetInfo.Type, e.ourpet.PetInfo.Type
// println("Effect55_o激活效果", e.ourpet.PetInfo.Type, e.opppet.PetInfo.Type)
case opTypeSync:
// 同步属性类型:保存我方原始值,覆盖为对方值
e.ctx.oldOurType = e.ourpet.PetInfo.Type
e.ourpet.PetInfo.Type = e.opppet.PetInfo.Type
// case opTypeMaxHP: // 减少最大生命值
// if e.opppet.GetMaxHP().Cmp(e.Args()[0]) == -1 {
// e.opppet.Info.MaxHp -= uint32(e.Args()[0].IntPart())
// }
}
}
}