feat(logic/service/fight/effect): 添加新的状态函数注册逻辑 新增三个状态函数注册项: - 状态码132:判断当前宠物血量是否小于对方宠物血量 - 状态码401:判断当前宠物类型是否与对方宠物类型相同 - 调整代码结构,优化状态函数注册方式 ```
91 lines
2.4 KiB
Go
91 lines
2.4 KiB
Go
package effect
|
|
|
|
import (
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/logic/service/fight/input"
|
|
"blazing/logic/service/fight/node"
|
|
)
|
|
|
|
// ---- 全局函数表自动管理 ----
|
|
var statusFuncRegistry = newStatusFuncRegistry()
|
|
|
|
type statusFuncRegistryType struct {
|
|
funcs map[int]func(*input.Input, *input.Input) bool
|
|
}
|
|
|
|
func newStatusFuncRegistry() *statusFuncRegistryType {
|
|
return &statusFuncRegistryType{funcs: make(map[int]func(*input.Input, *input.Input) bool)}
|
|
}
|
|
|
|
func (r *statusFuncRegistryType) Register(id int, f func(*input.Input, *input.Input) bool) {
|
|
r.funcs[id] = f
|
|
}
|
|
|
|
func (r *statusFuncRegistryType) Get(id int) func(*input.Input, *input.Input) bool {
|
|
return r.funcs[id]
|
|
}
|
|
|
|
// ---- Effect96 ----
|
|
type Effect96 struct {
|
|
node.EffectNode
|
|
StatusID int
|
|
}
|
|
|
|
func (e *Effect96) Skill_Hit() bool {
|
|
if f := statusFuncRegistry.Get(e.StatusID); f != nil && f(e.Ctx().Our, e.Ctx().Opp) {
|
|
e.Ctx().SkillEntity.Power *= 2
|
|
}
|
|
return true
|
|
}
|
|
|
|
// ---- 注册所有效果 ----
|
|
func init() {
|
|
registerStatusFunc(2, func(i, o *input.Input) bool {
|
|
return o.CurrentPet.Info.Hp < (o.CurrentPet.Info.MaxHp / 2)
|
|
})
|
|
registerStatusFunc(30, func(i, o *input.Input) bool {
|
|
return !i.FightC.IsFirst(i.Player)
|
|
})
|
|
registerStatusFunc(40, func(i, o *input.Input) bool {
|
|
return i.FightC.IsFirst(i.Player)
|
|
})
|
|
registerStatusFunc(64, func(i, o *input.Input) bool {
|
|
if i.StatEffect_Exist(info.PetStatus.Burned) {
|
|
return true
|
|
}
|
|
if i.StatEffect_Exist(info.PetStatus.Frozen) {
|
|
return true
|
|
}
|
|
if i.StatEffect_Exist(info.PetStatus.Poisoned) {
|
|
return true
|
|
}
|
|
return false
|
|
})
|
|
registerStatusFunc(96, func(i, o *input.Input) bool {
|
|
return o.StatEffect_Exist(info.PetStatus.Burned)
|
|
})
|
|
registerStatusFunc(97, func(i, o *input.Input) bool {
|
|
return o.StatEffect_Exist(info.PetStatus.Frozen)
|
|
})
|
|
registerStatusFunc(102, func(i, o *input.Input) bool {
|
|
return o.StatEffect_Exist(info.PetStatus.Paralysis)
|
|
})
|
|
|
|
registerStatusFunc(132, func(i, o *input.Input) bool {
|
|
return i.CurrentPet.Info.Hp < o.CurrentPet.Info.Hp
|
|
})
|
|
registerStatusFunc(168, func(i, o *input.Input) bool {
|
|
return o.StatEffect_Exist(info.PetStatus.Sleep)
|
|
})
|
|
registerStatusFunc(401, func(i, o *input.Input) bool {
|
|
return i.CurrentPet.PType == o.CurrentPet.PType
|
|
})
|
|
|
|
}
|
|
|
|
// 小助手函数,让注册看起来更自然
|
|
func registerStatusFunc(id int, fn func(*input.Input, *input.Input) bool) {
|
|
statusFuncRegistry.Register(id, fn)
|
|
input.InitEffect(input.EffectType.Skill, id, &Effect96{StatusID: id})
|
|
}
|