Files
bl/logic/service/fight/effect/EffectRandomPower.go
2025-11-23 23:38:03 +00:00

59 lines
1.5 KiB
Go

package effect
import (
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
"github.com/gogf/gf/v2/util/grand"
)
// -----------------------------------------------------------
// 威力随机效果
// -----------------------------------------------------------
// 威力将在 [Min, Max] 区间内随机取值
type EffectRandomPower struct {
node.EffectNode
Min int
Max int
}
// -----------------------------------------------------------
// 初始化注册
// -----------------------------------------------------------
func init() {
registerRandomPower(61, 50, 150)
registerRandomPower(70, 140, 220)
registerRandomPower(118, 140, 180)
}
// -----------------------------------------------------------
// 工厂函数:注册不同威力范围的技能效果
// -----------------------------------------------------------
func registerRandomPower(effectID, min, max int) {
input.InitEffect(input.EffectType.Skill, effectID, &EffectRandomPower{
Min: min,
Max: max,
})
}
// -----------------------------------------------------------
// 命中时触发
// -----------------------------------------------------------
func (e *EffectRandomPower) Skill_Hit() bool {
if e.Max <= e.Min {
e.Ctx().SkillEntity.Power = e.Min
return true
}
// 如果 FightC 没提供随机器,使用 math/rand 兜底
var n int
if e.Input != nil && e.Input.FightC != nil {
n = int(e.Input.FightC.GetRand().Int31n(int32(e.Max-e.Min+1))) + e.Min
} else {
n = grand.Intn(e.Max-e.Min+1) + e.Min
}
e.Ctx().SkillEntity.Power = n
return true
}