Files
bl/logic/service/fight/input/id.go
昔念 f15f08189f feat(effect): 实现多个新技能效果逻辑
新增了多个宠物战斗中的技能效果实现,包括伤害反弹、必杀技增强、先手权调整、
回复机制以及特殊条件触发逻辑。同时修复了部分技能判断条件与执行顺序问题,
优化了 AI 在 NPC 战斗中的行为表现,并完善了相关配置文件内容。
2025-11-26 18:39:23 +08:00

121 lines
4.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package input
import "fmt"
// -------------------------- 位运算常量(统一管理) --------------------------
const (
// 位移偏移量64位ID结构 = [高16位:效果类型][中32位:CatchTime][低16位:扩展标识]
prefixOffset = 48 // 高16位uint16效果类型
catchOffset = 16 // 中32位uint32CatchTime核心调整点
suffixOffset = 0 // 低16位uint16扩展标识/子ID
// 掩码(提取对应位段)
suffixMask = 0xFFFF // 低16位掩码
catchMask = 0xFFFFFFFF // 中32位掩码CatchTime专属
prefixMask = 0xFFFF // 高16位掩码
maxPrefix = prefixMask // 效果类型最大值uint16范围
maxCatch = catchMask // CatchTime最大值uint32范围
maxSuffix = suffixMask // 扩展标识最大值uint16范围
)
// -------------------------- 64位拼接工具无状态工具类 --------------------------
// EffectIDCombiner 64位效果ID拼接器[效果类型(uint16)+CatchTime(uint32)+扩展标识(uint16)] → int64
// 无状态设计,可全局复用
type EffectIDCombiner struct {
Base int64
}
// Combine 拼接三个字段为64位效果ID
// 参数:
// prefix: 高16位效果类型如EffectType.Skill
// catchTime: 中32位核心字段32位CatchTime
// suffix: 低16位扩展标识/子ID
// 返回拼接后的int64参数超出范围返回错误
func (c *EffectIDCombiner) Combine(prefix EnumEffectType, catchTime uint32, suffix uint16) {
// // 范围校验(避免溢出)
// if prefix > maxPrefix {
// return 0, fmt.Errorf("效果类型值%d超出uint16范围最大%d", prefix, maxPrefix)
// }
// if catchTime > maxCatch {
// return 0, fmt.Errorf("CatchTime值%d超出uint32范围最大%d", catchTime, maxCatch)
// }
// if suffix > maxSuffix {
// return 0, fmt.Errorf("扩展标识值%d超出uint16范围最大%d", suffix, maxSuffix)
// }
c.Base = (int64(prefix) << prefixOffset) |
(int64(catchTime) << catchOffset) |
int64(suffix)
}
// EffectID 获取完整的64位效果ID
func (e *EffectIDCombiner) EffectID() int64 {
return e.Base
}
// EffectType 读取/替换效果类型(读写一体)
// 参数t可选传入则替换当前效果类型不传则仅读取
// 返回当前的效果类型EnumEffectType
func (e *EffectIDCombiner) SetEffectType(t ...EnumEffectType) {
e.Base = (e.Base & ^prefixMask) | (int64(t[0]) << prefixOffset)
}
func (e EffectIDCombiner) GetEffectType() EnumEffectType {
return EnumEffectType((e.Base >> prefixOffset) & 0xFFFF)
}
// CatchTime 读取/替换CatchTime读写一体完全保留你的写法
// 参数t可选传入则替换当前CatchTime不传则仅读取
// 返回当前的CatchTime值
func (e *EffectIDCombiner) SetCatchTime(t ...uint32) {
e.Base = (e.Base & ^catchMask) | (int64(t[0]) << catchOffset)
}
func (e EffectIDCombiner) GetCatchTime() uint32 {
return uint32((e.Base >> catchOffset) & catchMask)
}
// Suffix 读取/替换扩展标识读写一体和CatchTime写法一致
// 参数t可选传入则替换当前扩展标识不传则仅读取
// 返回:当前的扩展标识值
func (e EffectIDCombiner) Suffix() uint16 {
// if len(t) > 0 {
// // 替换逻辑先清空低16位再设置新值
// e.Base = (e.Base & ^suffixMask) | int64(t[0])
// }
// 读取并返回当前扩展标识
return uint16(e.Base & suffixMask)
}
// -------------------------- 自由取值方法(核心需求:按需取不同类型) --------------------------
func Test() {
combiner := &EffectIDCombiner{}
// 1. 初始化拼接ID
combiner.Combine(EffectType.Skill, 123456, 789)
fmt.Println("=== 初始值 ===")
fmt.Printf("完整ID%d\n", combiner.EffectID())
fmt.Printf("效果类型:%d\n", combiner.GetEffectType()) // 仅读取
fmt.Printf("CatchTime%d\n", combiner.GetCatchTime()) // 仅读取
fmt.Printf("扩展标识:%d\n", combiner.Suffix()) // 仅读取
// 2. 替换字段(传参即替换)
combiner.SetEffectType(EffectType.NewSel) // 替换效果类型为Buff
combiner.SetCatchTime(987654) // 替换CatchTime
// 替换扩展标识
fmt.Println("\n=== 替换后 ===")
fmt.Printf("完整ID%d\n", combiner.EffectID())
fmt.Printf("效果类型:%d\n", combiner.GetEffectType())
fmt.Printf("CatchTime%d\n", combiner.GetCatchTime())
fmt.Printf("扩展标识:%d\n", combiner.Suffix())
// 3. 链式替换+读取(一行完成替换并获取新值)
combiner.SetCatchTime(111222) // 替换并返回新值
fmt.Printf("\n替换CatchTime并读取%d\n", combiner.GetCatchTime())
}