feat(item): 添加 NatureProbs 字段并优化宠物道具使用逻辑

- 在 `Item` 结构体中新增 `NatureProbs` 字段,用于支持性格概率配置
- 重构 `ItemUsePet` 控制器方法,引入处理器注册机制统一管理道具效果
- 修复神经元相关道具的特殊处理逻辑,增强代码可维护性
- 调整 `S2C_USE_PET_ITEM_OUT_OF_FIGHT` 响应结构体,增加技能列表长度字段
- 修改 `ResetNature` 方法命名及判断条件,提升语义清晰度与健壮性
- 新增 `PetInfo_One_Unscoped` 查询方法以支持软删除数据访问
- 实
This commit is contained in:
2025-12-07 01:43:12 +08:00
parent 35c89215f7
commit 004eec219c
6 changed files with 338 additions and 43 deletions

View File

@@ -1,16 +1,12 @@
package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service/fight"
"blazing/logic/service/item"
"blazing/logic/service/player"
"blazing/modules/blazing/model"
"strings"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/jinzhu/copier"
)
@@ -35,40 +31,33 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
if !ok {
return nil, errorcode.ErrorCodes.Err10401
}
// 绑定变量到switch显式匹配true
switch itemID := data.ItemID; true {
//这是学习力遗忘
case itemID >= 300037 && itemID <= 300041:
onpet.Ev[itemID-300037+1] = 0
// 体力遗忘
case itemID == 300042:
onpet.Ev[0] = 0
// 全能遗忘
case itemID == 300650:
onpet.Ev = [6]uint32{}
//性格随机
case itemID == 300025:
onpet.Nature = (onpet.Nature + uint32(grand.Intn(25))) % 25
//性格转换
case itemID >= 300081 && itemID <= 300086:
onpet.Nature = gconv.Uint32(*xmlres.ItemsMAP[int(itemID)].Nature)
//性格转换
case (itemID >= 300602 && itemID <= 300605) || itemID == 300119 || itemID == 300120:
rr := strings.Split(*xmlres.ItemsMAP[int(itemID)].NatureSet, " ")
onpet.Nature = gconv.Uint32(rr[grand.Intn(len(rr))-1])
default:
// 无效ID处理
return nil, errorcode.ErrorCodes.ErrSystemError
}
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 onpet.OldCatchTime == 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
oldpetc := onpet.CatchTime
oldpet := c.Service.Pet.PetInfo_One_Unscoped(onpet.OldCatchTime)
copier.Copy(onpet, oldpet.Data)
onpet.CatchTime = oldpetc
} else {
r := hd(data.ItemID, onpet)
if !r {
return nil, errorcode.ErrorCodes.ErrSystemError
}
}
c.Service.Item.SubItem(data.ItemID, 1)
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
onpet.CalculatePetPane()
@@ -77,8 +66,8 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
return result, 0
}
func (h Controller) RESET_NATURE(data *item.C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.Service.Item.CheakItem(data.ItemId) == 0 {
func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
_, onpet, ok := c.FindPet(data.CatchTime)