feat(item): 优化宠物道具使用逻辑与个体值处理

- 在获取用户物品列表时,过滤掉数量为0的物品
- 调整部分宠物道具ID判断条件,并修复神经元道具特殊处理逻辑
- 使用 DeepCopy 方式拷贝宠物数据,避免引用问题
- 移除冗余 copier 包引用,统一在需要处进行深拷贝操作
- 增加对宠物个体值(Dv)的操作边界检查,防止溢出
- 重构基因重组道具逻辑,调用封装
This commit is contained in:
2025-12-07 02:50:35 +08:00
parent 004eec219c
commit 3817fc1861
3 changed files with 52 additions and 28 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/jinzhu/copier"
)
type PetItemHandler func(itemid uint32, ctx *model.PetInfo) bool
@@ -148,27 +147,27 @@ func init() {
PetItemRegistry.RegisterExact(300790, func(itemid uint32, onpet *model.PetInfo) bool {
r := grand.Intn(2)
if r == 0 {
onpet.Dv--
if onpet.Dv > 0 {
onpet.Dv--
}
} else {
onpet.Dv++
if onpet.Dv < 31 {
onpet.Dv++
}
}
return true
})
//基因重组
PetItemRegistry.RegisterExact(300024, func(itemid uint32, onpet *model.PetInfo) bool {
oldcat := onpet.CatchTime
ab := 0
for _, v := range onpet.EffectInfo {
if v.Type == 1 {
ab = int(v.Idx)
}
}
r := model.GenPetInfo(int(onpet.ID), -1, -1, ab, 0, 1)
copier.Copy(onpet, r)
onpet.CatchTime = oldcat
onpet.Downgrade(1)
onpet.Update_EXP()
onpet.Ev = [6]uint32{}
onpet.Dv = uint32(grand.Intn(32))
onpet.Nature = (onpet.Nature + uint32(grand.Intn(25))) % 25
onpet.CalculatePetPane()
return true
})
@@ -178,13 +177,24 @@ func init() {
return true
})
PetItemRegistry.RegisterExact(300791, func(itemid uint32, onpet *model.PetInfo) bool {
if onpet.Dv >= 31 {
onpet.Dv = 31
return true
}
onpet.Dv = 31
return true
})
PetItemRegistry.RegisterExact(300792, func(itemid uint32, onpet *model.PetInfo) bool {
PetItemRegistry.RegisterExact(300702, func(itemid uint32, onpet *model.PetInfo) bool {
if onpet.Dv >= 31 {
onpet.Dv = 31
return true
}
onpet.Dv = onpet.Dv + uint32(grand.Intn(31-int(onpet.Dv))+1)
onpet.Dv = uint32(grand.Intn(31-int(onpet.Dv)) + 1)
if onpet.Dv >= 31 {
onpet.Dv = 31
//return true
}
return true
})
PetItemRegistry.RegisterExact(300053, func(itemid uint32, onpet *model.PetInfo) bool {