feat(fight): 添加效果工厂模式支持以解决闭包变量捕获问题 - 新增initskillFactory函数用于注册效果工厂 - 修改技能效果注册逻辑从直接实例化改为工厂模式 - 解决循环中闭包捕获变量导致的潜在问题 feat(fight): 实现对手输入获取逻辑优化回合处理 - 添加roundOpponentInput方法获取对手输入 - 重构enterturn方法中的先后手逻辑 - 确保攻击方和被攻击
This commit is contained in:
@@ -32,6 +32,7 @@ var EffectType = enum.New[struct {
|
||||
}]()
|
||||
|
||||
var NodeM = make(map[int64]Effect, 0)
|
||||
var NodeFactoryM = make(map[int64]func() Effect, 0)
|
||||
|
||||
func InitEffect(etype EnumEffectType, id int, t Effect) {
|
||||
pr := EffectIDCombiner{}
|
||||
@@ -41,6 +42,13 @@ func InitEffect(etype EnumEffectType, id int, t Effect) {
|
||||
|
||||
NodeM[pr.EffectID()] = t
|
||||
}
|
||||
|
||||
func InitEffectFactory(etype EnumEffectType, id int, factory func() Effect) {
|
||||
pr := EffectIDCombiner{}
|
||||
pr.Combine(etype, 0, gconv.Uint16(id))
|
||||
|
||||
NodeFactoryM[pr.EffectID()] = factory
|
||||
}
|
||||
func GeteffectIDs(etype EnumEffectType) []uint32 {
|
||||
|
||||
var ret []uint32 = make([]uint32, 0)
|
||||
@@ -60,6 +68,19 @@ func geteffect[T int | byte | uint16](etype EnumEffectType, id T) Effect {
|
||||
pr := EffectIDCombiner{}
|
||||
pr.Combine(etype, 0, gconv.Uint16(id))
|
||||
|
||||
if factory, ok := NodeFactoryM[pr.EffectID()]; ok {
|
||||
eff := factory()
|
||||
if eff == nil {
|
||||
return nil
|
||||
}
|
||||
eff.ID(pr)
|
||||
if etype == EffectType.Status {
|
||||
eff.CanStack(true)
|
||||
eff.Duration(grand.N(1, 2))
|
||||
}
|
||||
return eff
|
||||
}
|
||||
|
||||
//todo 获取前GetEffect
|
||||
ret, ok := NodeM[pr.EffectID()]
|
||||
if ok {
|
||||
|
||||
Reference in New Issue
Block a user