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

@@ -20,7 +20,10 @@ func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *player.Playe
vv.ItemId = v.ItemId
vv.ItemCnt = v.ItemCnt
vv.LeftTime = 360000
result.ItemList = append(result.ItemList, vv)
if vv.ItemCnt != 0 {
result.ItemList = append(result.ItemList, vv)
}
}
return result, 0
@@ -35,11 +38,8 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
if c.Service.Item.CheakItem(data.ItemID) == 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
hd := item.PetItemRegistry.GetHandler(data.ItemID)
if hd == nil {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if data.ItemID == 300025 {
if data.ItemID == 300036 {
//神经元需要特殊处理
if onpet.OldCatchTime == 0 {
@@ -48,9 +48,13 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
oldpetc := onpet.CatchTime
oldpet := c.Service.Pet.PetInfo_One_Unscoped(onpet.OldCatchTime)
copier.Copy(onpet, oldpet.Data)
copier.CopyWithOption(onpet, oldpet.Data, copier.Option{DeepCopy: true})
onpet.CatchTime = oldpetc
} else {
hd := item.PetItemRegistry.GetHandler(data.ItemID)
if hd == nil {
return nil, errorcode.ErrorCodes.ErrSystemError
}
r := hd(data.ItemID, onpet)
if !r {
return nil, errorcode.ErrorCodes.ErrSystemError

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 {

View File

@@ -34,6 +34,16 @@ type PetEX struct {
Data PetInfo `orm:"data" json:"data"`
}
type Attr uint32
func (r Attr) sub() uint32 {
if r > 0 {
return uint32(r) - 1
}
return 0
}
// PetInfo 精灵信息结构(合并后的优化版本)
type PetInfo struct {
@@ -44,7 +54,7 @@ type PetInfo struct {
Name string `struc:"[16]byte" `
// 个体值(@UInt long → uint32
Dv uint32 `fieldDesc:"个体值" `
Dv uint32 `struc:"uint32" `
// 性格(@UInt long → uint32
Nature uint32 `fieldDesc:"性格" `
@@ -213,7 +223,7 @@ func (pet *PetInfo) RnadAN() {
Args: v.ArgsS,
}
_, eff1, ok := utils.FindWithIndex(pet.EffectInfo, func(item PetEffectInfo) bool {
return uint16(item.Type) == 1
return gconv.Int(xmlres.EffectMAP[int(item.Idx)].Stat) == 1
})
if ok {
copier.Copy(eff1, ret)
@@ -229,7 +239,7 @@ func (pet *PetInfo) RnadAN() {
func (pet *PetInfo) HaveAN() bool {
_, _, ok := utils.FindWithIndex(pet.EffectInfo, func(item PetEffectInfo) bool {
return uint16(item.Type) == 1
return gconv.Int(xmlres.EffectMAP[int(item.Idx)].Stat) == 1
})
return ok
}