202 lines
5.6 KiB
Go
202 lines
5.6 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)
|
||
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
|
||
|
||
isactive bool
|
||
can bool
|
||
}
|
||
|
||
// 工厂函数:创建属性同步/反转效果实例
|
||
func newEffectPropSyncReverse() *EffectPropSyncReverse {
|
||
return &EffectPropSyncReverse{}
|
||
}
|
||
|
||
// 初始化:批量注册所有属性同步/反转类效果
|
||
func init() {
|
||
registerPropSyncReverseEffects()
|
||
}
|
||
|
||
// 批量注册:绑定效果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()
|
||
}
|
||
func (e *EffectPropSyncReverse) OnSkill() bool {
|
||
|
||
if e.opppet != nil {
|
||
return true
|
||
}
|
||
e.ourpet = e.CarrierInput().CurPet[0]
|
||
e.opppet = e.TargetInput().CurPet[0]
|
||
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())
|
||
|
||
// }
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|