refactor(fight): 重构击败触发效果机制,优化代码结构 将 EffectDefeatTrigger 中的回调函数模式改为基于 effectID 的 switch-case 实现, 移除冗余的 defeatTriggerFunc 类型定义。统一通过 triggerByID 方法根据 ID 分发执行具体行为, 提高可维护性和扩展性。 同时更新 AddEffect 方法签名以支持传入主动方输入上下文,增强效果添加时的控制逻辑。 修复部分效果在添加状态时未正确传递施加者信息的问题。 此外,清理了部分注释和无用代码,使逻辑更清晰。 ```
48 lines
839 B
Go
48 lines
839 B
Go
package effect
|
||
|
||
import (
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/logic/service/fight/input"
|
||
"blazing/logic/service/fight/node"
|
||
|
||
"github.com/shopspring/decimal"
|
||
)
|
||
|
||
/**
|
||
* 将所受的伤害n倍反馈给对手
|
||
*/
|
||
|
||
func init() {
|
||
input.InitEffect(input.EffectType.Skill, 34, &Effect34{})
|
||
|
||
}
|
||
|
||
type Effect34 struct {
|
||
node.EffectNode
|
||
can bool
|
||
}
|
||
|
||
// 使用技能时,不可被继承,继承Miss和Hit就行
|
||
func (e *Effect34) OnSkill() bool {
|
||
if !e.Hit() {
|
||
return true
|
||
}
|
||
e.can = true
|
||
return true
|
||
}
|
||
|
||
// 被攻击时候反弹
|
||
func (e *Effect34) Damage_Floor(t *info.DamageZone) bool {
|
||
|
||
if !e.can {
|
||
return true
|
||
}
|
||
//不是技能
|
||
if e.Ctx().SkillEntity == nil {
|
||
return true
|
||
}
|
||
t.Damage = decimal.NewFromInt(int64(e.Ctx().Opp.DamageZone.Damage.IntPart())).Mul(decimal.NewFromInt(int64(e.SideEffectArgs[0])))
|
||
|
||
return true
|
||
}
|