refactor: 重构效果参数处理逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-04 09:26:57 +08:00
committed by cnb
parent ce7be73e49
commit 257a979f93
4 changed files with 44 additions and 895 deletions

View File

@@ -109,21 +109,12 @@ func (e *Effect121) Skill_Use() bool {
// Effect 123: {0}回合内受到任何伤害,自身{1}提高{2}个等级
type Effect123 struct {
node.EffectNode
roundCount int
can bool
}
func (e *Effect123) SetArgs(t *input.Input, a ...int) {
e.EffectNode.SetArgs(t, a...)
e.roundCount = e.EffectNode.SideEffectArgs[0]
RoundEffectSideArg0Base
can bool
}
func (e *Effect123) TurnStart(at, de *action.SelectSkillAction) {
if e.roundCount > 0 {
e.can = true
e.roundCount--
}
e.can = true
}
func (e *Effect123) Be_Damage(at, _ alpacadecimal.Decimal) {

View File

@@ -30,8 +30,13 @@ type propOpContext struct {
opType propOpType
}
type propOpConfig struct {
newContext func() propOpContext
initDuration bool
}
// 全局映射关联效果ID与对应的操作配置
var propOpMap = make(map[int]func() propOpContext)
var propOpMap = make(map[int]propOpConfig)
// EffectPropSyncReverse属性同步/反转效果核心结构体
type EffectPropSyncReverse struct {
@@ -57,27 +62,41 @@ func init() {
// 批量注册绑定效果ID与对应的操作配置
func registerPropSyncReverseEffects() {
// 效果ID与操作配置的映射
effectMap := map[int]func() propOpContext{
38: func() propOpContext { // 减少最大生命值
return propOpContext{opType: opTypeMaxHP}
effectMap := map[int]propOpConfig{
38: {
newContext: func() propOpContext { // 减少最大生命值
return propOpContext{opType: opTypeMaxHP}
},
},
45: func() propOpContext { // n回合防御力和对手相同
return propOpContext{opType: opDefenseSync, propIndex: 1}
45: {
newContext: func() propOpContext { // n回合防御力和对手相同
return propOpContext{opType: opDefenseSync, propIndex: 1}
},
initDuration: true,
},
51: func() propOpContext { // n回合攻击力和对手相同
return propOpContext{opType: opAttackSync, propIndex: 0}
51: {
newContext: func() propOpContext { // n回合攻击力和对手相同
return propOpContext{opType: opAttackSync, propIndex: 0}
},
initDuration: true,
},
55: func() propOpContext { // n回合反转属性类型
return propOpContext{opType: opTypeReverse}
55: {
newContext: func() propOpContext { // n回合反转属性类型
return propOpContext{opType: opTypeReverse}
},
initDuration: true,
},
56: func() propOpContext { // n回合同步属性类型
return propOpContext{opType: opTypeSync}
56: {
newContext: func() propOpContext { // n回合同步属性类型
return propOpContext{opType: opTypeSync}
},
initDuration: true,
},
}
// 注册到全局映射,并初始化效果
for effectID, ctxFunc := range effectMap {
propOpMap[effectID] = ctxFunc
for effectID, config := range effectMap {
propOpMap[effectID] = config
input.InitEffect(input.EffectType.Skill, effectID, newEffectPropSyncReverse())
}
}
@@ -85,10 +104,15 @@ func registerPropSyncReverseEffects() {
// SetArgs设置效果参数回合数
func (e *EffectPropSyncReverse) SetArgs(t *input.Input, a ...int) {
e.EffectNode.SetArgs(t, a...)
// 从SideEffectArgs[0]获取持续回合数
e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0])
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 = propOpMap[int(e.ID().Suffix())]()
e.ctx = config.newContext()
}
func (e *EffectPropSyncReverse) OnSkill() bool {