2025-11-25 12:29:50 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/common/socket/errorcode"
|
|
|
|
|
"blazing/logic/service/fight"
|
|
|
|
|
"blazing/logic/service/item"
|
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
"blazing/modules/blazing/model"
|
|
|
|
|
|
|
|
|
|
"github.com/jinzhu/copier"
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
// GetUserItemList 获取用户道具列表
|
|
|
|
|
// data: 包含分页参数的输入信息
|
|
|
|
|
// c: 当前玩家对象
|
|
|
|
|
// 返回: 道具列表和错误码
|
|
|
|
|
func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-25 12:29:50 +08:00
|
|
|
result = &item.ItemListOutboundInfo{}
|
|
|
|
|
result.ItemList = make([]model.SingleItemInfo, 0)
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
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
|
|
|
|
|
if itemInfo.ItemCnt != 0 {
|
|
|
|
|
result.ItemList = append(result.ItemList, itemInfo)
|
2025-12-07 02:50:35 +08:00
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
}
|
|
|
|
|
return result, 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
// UsePetItemOutOfFight 战斗外使用宠物道具
|
|
|
|
|
// data: 包含道具ID和宠物捕获时间的输入信息
|
|
|
|
|
// c: 当前玩家对象
|
|
|
|
|
// 返回: 使用后的宠物信息和错误码
|
|
|
|
|
func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *player.Player) (result *item.S2C_USE_PET_ITEM_OUT_OF_FIGHT, err errorcode.ErrorCode) {
|
|
|
|
|
_, currentPet, found := c.FindPet(data.CatchTime)
|
|
|
|
|
if !found {
|
2025-11-25 12:29:50 +08:00
|
|
|
return nil, errorcode.ErrorCodes.Err10401
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-07 01:43:12 +08:00
|
|
|
if c.Service.Item.CheakItem(data.ItemID) == 0 {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
2025-12-07 02:50:35 +08:00
|
|
|
|
|
|
|
|
if data.ItemID == 300036 {
|
2025-12-24 19:03:11 +08:00
|
|
|
// 神经元需要特殊处理
|
|
|
|
|
if currentPet.OldCatchTime == 0 {
|
2025-12-07 01:43:12 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
oldPetCatchTime := currentPet.CatchTime
|
|
|
|
|
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
|
2025-12-30 15:04:21 +00:00
|
|
|
currentPet = &oldPet.Data
|
2025-12-24 19:03:11 +08:00
|
|
|
currentPet.CatchTime = oldPetCatchTime
|
2025-12-07 01:43:12 +08:00
|
|
|
} else {
|
2025-12-24 19:03:11 +08:00
|
|
|
handler := item.PetItemRegistry.GetHandler(data.ItemID)
|
|
|
|
|
if handler == nil {
|
2025-12-07 02:50:35 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
success := handler(data.ItemID, currentPet)
|
|
|
|
|
if !success {
|
2025-12-07 01:43:12 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-16 06:54:27 +00:00
|
|
|
c.Service.Item.UPDATE(data.ItemID, -1)
|
2025-11-25 12:29:50 +08:00
|
|
|
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
2025-12-24 19:03:11 +08:00
|
|
|
currentPet.CalculatePetPane(false)
|
|
|
|
|
copier.Copy(&result, currentPet)
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
return result, 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
// ResetNature 重置宠物性格
|
|
|
|
|
// data: 包含道具ID和宠物捕获时间的输入信息
|
|
|
|
|
// c: 当前玩家对象
|
|
|
|
|
// 返回: 无数据和错误码
|
2025-12-07 01:43:12 +08:00
|
|
|
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 {
|
2025-11-25 12:29:50 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
_, currentPet, found := c.FindPet(data.CatchTime)
|
|
|
|
|
if !found {
|
2025-11-25 12:29:50 +08:00
|
|
|
return nil, errorcode.ErrorCodes.Err10401
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
currentPet.Nature = data.Nature
|
|
|
|
|
currentPet.CalculatePetPane(false)
|
2025-12-16 06:54:27 +00:00
|
|
|
c.Service.Item.UPDATE(data.ItemId, -1)
|
2025-11-25 12:29:50 +08:00
|
|
|
return result, 0
|
|
|
|
|
}
|