Files
bl/logic/service/fight/effect/effect_attr.go

202 lines
5.6 KiB
Go
Raw Normal View History

package effect
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
)
2025-12-18 13:10:40 +00:00
// -----------------------------------------------------------
// 通用效果:属性同步/反转类效果45/51/55/56
2025-12-18 13:10:40 +00:00
// -----------------------------------------------------------
// 操作类型定义:区分不同的属性操作
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
}
type propOpConfig struct {
newContext func() propOpContext
initDuration bool
}
// 全局映射关联效果ID与对应的操作配置
var propOpMap = make(map[int]propOpConfig)
// EffectPropSyncReverse属性同步/反转效果核心结构体
type EffectPropSyncReverse struct {
node.EffectNode
ctx propOpContext // 操作上下文(存储原始值)
ourpet *info.BattlePetEntity
opppet *info.BattlePetEntity
2026-01-22 16:01:52 +00:00
isactive bool
can bool
}
// 工厂函数:创建属性同步/反转效果实例
func newEffectPropSyncReverse() *EffectPropSyncReverse {
return &EffectPropSyncReverse{}
2025-12-18 13:10:40 +00:00
}
// 初始化:批量注册所有属性同步/反转类效果
2025-12-18 13:10:40 +00:00
func init() {
registerPropSyncReverseEffects()
2025-12-18 13:10:40 +00:00
}
// 批量注册绑定效果ID与对应的操作配置
func registerPropSyncReverseEffects() {
// 效果ID与操作配置的映射
effectMap := map[int]propOpConfig{
38: {
newContext: func() propOpContext { // 减少最大生命值
return propOpContext{opType: opTypeMaxHP}
},
},
45: {
newContext: func() propOpContext { // n回合防御力和对手相同
return propOpContext{opType: opDefenseSync, propIndex: 1}
},
initDuration: true,
},
51: {
newContext: func() propOpContext { // n回合攻击力和对手相同
return propOpContext{opType: opAttackSync, propIndex: 0}
},
initDuration: true,
},
55: {
newContext: func() propOpContext { // n回合反转属性类型
return propOpContext{opType: opTypeReverse}
},
initDuration: true,
},
56: {
newContext: func() propOpContext { // n回合同步属性类型
return propOpContext{opType: opTypeSync}
},
initDuration: true,
},
}
// 注册到全局映射,并初始化效果
for effectID, config := range effectMap {
propOpMap[effectID] = config
input.InitEffect(input.EffectType.Skill, effectID, newEffectPropSyncReverse())
}
}
// SetArgs设置效果参数回合数
func (e *EffectPropSyncReverse) SetArgs(t *input.Input, a ...int) {
e.EffectNode.SetArgs(t, a...)
config, ok := propOpMap[int(e.ID().Suffix())]
if !ok {
return
}
if config.initDuration && len(e.EffectNode.SideEffectArgs) > 0 {
e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0])
}
// 初始化操作上下文
e.ctx = config.newContext()
2025-12-18 13:10:40 +00:00
}
func (e *EffectPropSyncReverse) OnSkill() bool {
if e.opppet != nil {
return true
}
e.ourpet = e.CarrierInput().CurPet[0]
e.opppet = e.TargetInput().CurPet[0]
2026-01-22 16:01:52 +00:00
e.can = true
e.active(true)
2026-01-22 16:01:52 +00:00
return true
}
2026-01-22 16:01:52 +00:00
// Alive效果存活判定结束时还原属性
func (e *EffectPropSyncReverse) Alive(t ...bool) bool {
if len(t) > 0 {
if t[0] {
e.active(true)
} else {
e.active(false)
}
}
2026-01-22 16:01:52 +00:00
return e.EffectNode.Alive(t...)
}
// Alive效果存活判定结束时还原属性
2026-01-22 16:01:52 +00:00
func (e *EffectPropSyncReverse) active(is bool) {
//println("属性类测试", t)
2026-01-22 16:01:52 +00:00
if !e.can {
return
}
2025-11-17 19:31:51 +00:00
2026-01-22 16:01:52 +00:00
if !is && e.isactive { //取消反转
2026-01-22 16:01:52 +00:00
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())
}
2025-11-16 20:30:17 +00:00
2026-01-22 16:01:52 +00:00
}
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())
// }
}
}
}