新增了多个宠物战斗中的技能效果实现,包括伤害反弹、必杀技增强、先手权调整、 回复机制以及特殊条件触发逻辑。同时修复了部分技能判断条件与执行顺序问题, 优化了 AI 在 NPC 战斗中的行为表现,并完善了相关配置文件内容。
121 lines
4.6 KiB
Go
121 lines
4.6 KiB
Go
package input
|
||
|
||
import "fmt"
|
||
|
||
// -------------------------- 位运算常量(统一管理) --------------------------
|
||
const (
|
||
// 位移偏移量:64位ID结构 = [高16位:效果类型][中32位:CatchTime][低16位:扩展标识]
|
||
prefixOffset = 48 // 高16位(uint16):效果类型
|
||
catchOffset = 16 // 中32位(uint32):CatchTime(核心调整点)
|
||
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())
|
||
|
||
}
|