refactor(item_use): 重构道具使用逻辑并提取常量

- 添加 ItemDefaultLeftTime 和 ItemNeuronID 常量定义
- 使用结构体字面量初始化 itemInfo,替换手动赋值
- 将神经元道具处理逻辑提取为独立方法 handleNeuronItem
- 将普通宠物道具处理逻辑提取为独立方法 handleRegularPetItem
- 优化 UsePetItemOutOfFight 方法的条件判断结构

fix(NewSeIdx_700): 修复Boss技能伤害计算参数错误

- 修正 Skill_Useed 方法中 Div 方法的参数索引,从 Args()[1]
This commit is contained in:
2025-12-31 02:44:14 +08:00
parent 4fa60266f1
commit eebf46cc03
4 changed files with 101 additions and 83 deletions

View File

@@ -10,6 +10,13 @@ import (
"github.com/jinzhu/copier"
)
const (
// ItemDefaultLeftTime 道具默认剩余时间(毫秒)
ItemDefaultLeftTime = 360000
// ItemNeuronID 神经元道具ID
ItemNeuronID = 300036
)
// GetUserItemList 获取用户道具列表
// data: 包含分页参数的输入信息
// c: 当前玩家对象
@@ -20,10 +27,11 @@ func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Pl
items := c.Service.Item.Get(data.Param1, data.Param2)
for _, itemData := range items {
var itemInfo model.SingleItemInfo
itemInfo.ItemId = itemData.ItemId
itemInfo.ItemCnt = itemData.ItemCnt
itemInfo.LeftTime = 360000
itemInfo := model.SingleItemInfo{
ItemId: itemData.ItemId,
ItemCnt: itemData.ItemCnt,
LeftTime: ItemDefaultLeftTime,
}
if itemInfo.ItemCnt != 0 {
result.ItemList = append(result.ItemList, itemInfo)
}
@@ -45,27 +53,14 @@ func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGH
return nil, errorcode.ErrorCodes.ErrSystemError
}
if data.ItemID == 300036 {
// 神经元需要特殊处理
if currentPet.OldCatchTime == 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
oldPetCatchTime := currentPet.CatchTime
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
println(c.Info.UserID, "还原", len(c.Info.PetList), currentPet.ID, oldPet.Data.ID)
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
currentPet.CatchTime = oldPetCatchTime
println(c.Info.UserID, "还原后", len(c.Info.PetList), currentPet.ID, oldPet.Data.ID)
var errcode errorcode.ErrorCode
if data.ItemID == ItemNeuronID {
errcode = h.handleNeuronItem(currentPet, c)
} else {
handler := item.PetItemRegistry.GetHandler(data.ItemID)
if handler == nil {
return nil, errorcode.ErrorCodes.ErrSystemError
}
success := handler(data.ItemID, currentPet)
if !success {
return nil, errorcode.ErrorCodes.ErrSystemError
}
errcode = h.handleRegularPetItem(data.ItemID, currentPet)
}
if errcode != 0 {
return nil, errcode
}
c.Service.Item.UPDATE(data.ItemID, -1)
@@ -76,19 +71,49 @@ func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGH
return result, 0
}
// handleNeuronItem 处理神经元道具的特殊逻辑
func (h Controller) handleNeuronItem(currentPet *model.PetInfo, c *player.Player) errorcode.ErrorCode {
if currentPet.OldCatchTime == 0 {
return errorcode.ErrorCodes.ErrSystemError
}
originalCatchTime := currentPet.CatchTime
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
currentPet.CatchTime = originalCatchTime
currentPet.ShinyInfo = oldPet.Data.ShinyInfo
currentPet.EffectInfo = oldPet.Data.EffectInfo
return 0
}
// handleRegularPetItem 处理普通宠物道具
func (h Controller) handleRegularPetItem(itemID uint32, currentPet *model.PetInfo) errorcode.ErrorCode {
handler := item.PetItemRegistry.GetHandler(itemID)
if handler == nil {
return errorcode.ErrorCodes.ErrSystemError
}
if !handler(itemID, currentPet) {
return errorcode.ErrorCodes.ErrSystemError
}
return 0
}
// ResetNature 重置宠物性格
// data: 包含道具ID和宠物捕获时间的输入信息
// c: 当前玩家对象
// 返回: 无数据和错误码
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
}
_, currentPet, found := c.FindPet(data.CatchTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
}
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
currentPet.Nature = data.Nature
currentPet.CalculatePetPane(false)
c.Service.Item.UPDATE(data.ItemId, -1)