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" ) // GetUserItemList 获取用户道具列表 // data: 包含分页参数的输入信息 // c: 当前玩家对象 // 返回: 道具列表和错误码 func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) { result = &item.ItemListOutboundInfo{} result.ItemList = make([]model.SingleItemInfo, 0) 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) } } return result, 0 } // 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 { return nil, errorcode.ErrorCodes.Err10401 } if c.Service.Item.CheakItem(data.ItemID) == 0 { 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) currentPet = &oldPet.Data currentPet.CatchTime = oldPetCatchTime } 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 } } c.Service.Item.UPDATE(data.ItemID, -1) result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{} currentPet.CalculatePetPane(false) copier.Copy(&result, currentPet) return result, 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 } currentPet.Nature = data.Nature currentPet.CalculatePetPane(false) c.Service.Item.UPDATE(data.ItemId, -1) return result, 0 }