114 lines
3.8 KiB
Go
114 lines
3.8 KiB
Go
package controller
|
||
|
||
import (
|
||
"blazing/common/socket/errorcode"
|
||
"blazing/modules/player/model"
|
||
"blazing/modules/player/service"
|
||
|
||
"blazing/logic/service/pet"
|
||
"blazing/logic/service/player"
|
||
"blazing/logic/service/room"
|
||
|
||
"github.com/jinzhu/copier"
|
||
)
|
||
|
||
// GetFitmentUsing 获取基地展示的家具物品
|
||
// data: 包含目标用户ID的输入信息
|
||
// c: 当前玩家对象
|
||
// 返回: 基地家具信息和错误码
|
||
func (h Controller) GetFitmentUsing(data *FitmentUseringInboundInfo, c *player.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) {
|
||
result = &room.FitmentUseringOutboundInfo{UserId: c.Info.UserID, RoomId: data.TargetUserID}
|
||
result.Fitments = make([]model.FitmentShowInfo, 0)
|
||
result.Fitments = append(result.Fitments, model.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
|
||
|
||
roomInfo := c.Service.Room.Get(data.TargetUserID)
|
||
result.Fitments = append(result.Fitments, roomInfo.PlacedItems...)
|
||
return
|
||
}
|
||
|
||
// GetRoomPetShowInfo 获取基地展示的精灵列表
|
||
// data: 包含目标用户ID的输入信息
|
||
// c: 当前玩家对象
|
||
// 返回: 精灵展示列表和错误码
|
||
func (h Controller) GetRoomPetShowInfo(data *PetRoomListInboundInfo, c *player.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
|
||
result = &room.PetRoomListOutboundInfo{}
|
||
result.Pets = make([]pet.PetShortInfo, 0)
|
||
showPets := service.NewPetService(data.TargetUserID).GetShowPets()
|
||
for i := range showPets {
|
||
var petShortInfo pet.PetShortInfo
|
||
copier.Copy(&petShortInfo, &showPets[i].Data)
|
||
result.Pets = append(result.Pets, petShortInfo)
|
||
}
|
||
return
|
||
}
|
||
|
||
// SetRoomPetShowInfo 设置基地展示精灵并返回最新展示列表(cmd:2323)
|
||
func (h Controller) SetRoomPetShowInfo(data *C2S_PET_ROOM_SHOW, c *player.Player) (result *room.S2C_PET_ROOM_SHOW, err errorcode.ErrorCode) {
|
||
result = &room.S2C_PET_ROOM_SHOW{}
|
||
result.PetShowList = make([]pet.PetShortInfo, 0)
|
||
|
||
catchTimes := make([]uint32, 0, len(data.PetShowList))
|
||
seen := make(map[uint32]struct{}, len(data.PetShowList))
|
||
for _, item := range data.PetShowList {
|
||
ct := uint32(item.CatchTime)
|
||
if ct == 0 {
|
||
continue
|
||
}
|
||
if _, ok := seen[ct]; ok {
|
||
continue
|
||
}
|
||
seen[ct] = struct{}{}
|
||
catchTimes = append(catchTimes, ct)
|
||
}
|
||
|
||
petSvc := service.NewPetService(c.Info.UserID)
|
||
if !petSvc.SetShowCatchTimes(catchTimes) {
|
||
err = errorcode.ErrorCodes.ErrSystemError
|
||
return
|
||
}
|
||
|
||
showPets := petSvc.GetShowPets()
|
||
for i := range showPets {
|
||
var petShortInfo pet.PetShortInfo
|
||
copier.Copy(&petShortInfo, &showPets[i].Data)
|
||
result.PetShowList = append(result.PetShowList, petShortInfo)
|
||
}
|
||
return
|
||
}
|
||
|
||
// GetAllFurniture 获取玩家的所有家具
|
||
// data: 空输入结构
|
||
// c: 当前玩家对象
|
||
// 返回: 玩家所有家具列表和错误码
|
||
func (h Controller) GetAllFurniture(data *FitmentAllInboundEmpty, c *player.Player) (result *room.FitmentAllOutboundInfo, err errorcode.ErrorCode) {
|
||
result = &room.FitmentAllOutboundInfo{}
|
||
result.Fitments = make([]room.FitmentItemInfo, 0)
|
||
|
||
items := c.Service.Item.Get(500000, 600000)
|
||
roomData := c.Service.Room.Get(c.Info.UserID)
|
||
for _, item := range items {
|
||
var itemInfo room.FitmentItemInfo
|
||
itemInfo.Id = item.ItemId
|
||
itemInfo.AllCount = uint32(item.ItemCnt)
|
||
i, ok := roomData.UsedItems[item.ItemId]
|
||
if ok {
|
||
itemInfo.UsedCount = i
|
||
}
|
||
result.Fitments = append(result.Fitments, itemInfo)
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
// GetRoomPetInfo 获取玩家跟随精灵的信息
|
||
// data: 包含用户ID和精灵捕获时间的输入信息
|
||
// c: 当前玩家对象
|
||
// 返回: 精灵详细信息和错误码
|
||
func (h Controller) GetRoomPetInfo(data *C2S_RoomPetInfo, c *player.Player) (result *pet.RoomPetInfo, err errorcode.ErrorCode) {
|
||
petInfo := c.Service.Pet.PetInfoOneOther(data.UserID, data.CatchTime)
|
||
result = &pet.RoomPetInfo{}
|
||
copier.CopyWithOption(result, &petInfo.Data, copier.Option{DeepCopy: true})
|
||
result.OwnerId = data.UserID
|
||
return
|
||
}
|