diff --git a/logic/controller/pet_info.go b/logic/controller/pet_info.go index 3373b1aa4..79b80db0e 100644 --- a/logic/controller/pet_info.go +++ b/logic/controller/pet_info.go @@ -20,16 +20,54 @@ func buildPetShortInfo(info model.PetInfo) pet.PetShortInfo { } } -func buildPetListOutboundInfo(petList []model.Pet) *pet.GetPetListOutboundInfo { +func buildPetListOutboundInfo(petList []model.PetInfo) *pet.GetPetListOutboundInfo { result := &pet.GetPetListOutboundInfo{ ShortInfoList: make([]pet.PetShortInfo, len(petList)), } for i := range petList { - result.ShortInfoList[i] = buildPetShortInfo(petList[i].Data) + result.ShortInfoList[i] = buildPetShortInfo(petList[i]) } return result } +func removePetByCatchTime(petList []model.PetInfo, catchTime uint32) []model.PetInfo { + for i := range petList { + if petList[i].CatchTime == catchTime { + return append(petList[:i], petList[i+1:]...) + } + } + return petList +} + +func syncBackupPetList(player *player.Player) { + if len(player.Info.BackupPetList) > 0 { + return + } + + storagePets := player.Service.Pet.PetInfo(1) + if len(storagePets) == 0 { + player.Info.BackupPetList = make([]model.PetInfo, 0) + return + } + + player.Info.BackupPetList = make([]model.PetInfo, len(storagePets)) + for i := range storagePets { + player.Info.BackupPetList[i] = storagePets[i].Data + } +} + +func buildUserBagPetInfo(player *player.Player) *pet.GetUserBagPetInfoOutboundInfo { + syncBackupPetList(player) + + result := &pet.GetUserBagPetInfoOutboundInfo{ + PetList: make([]model.PetInfo, len(player.Info.PetList)), + BackupPetList: make([]model.PetInfo, len(player.Info.BackupPetList)), + } + copy(result.PetList, player.Info.PetList) + copy(result.BackupPetList, player.Info.BackupPetList) + return result +} + func buildPetShowOutboundInfo(userID, flag uint32, info *model.PetInfo) *pet.PetShowOutboundInfo { return &pet.PetShowOutboundInfo{ UserID: userID, @@ -49,26 +87,30 @@ func buildPetShowOutboundInfo(userID, flag uint32, info *model.PetInfo) *pet.Pet // 返回: 精灵信息和错误码 func (h Controller) GetPetInfo( data *pet.InInfo, - player *player.Player) (result *pet.OutInfo, + player *player.Player) (result *model.PetInfo, err errorcode.ErrorCode) { _, petInfo, found := player.FindPet(data.CatchTime) if found { - result = &pet.OutInfo{ - PetInfo: *petInfo, - } + result = petInfo return result, 0 } ret := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime) if ret == nil { return nil, errorcode.ErrorCodes.ErrPokemonNotExists } - result = &pet.OutInfo{ - PetInfo: ret.Data, - } + result = &ret.Data return result, 0 } +// GetUserBagPetInfo 获取主背包和并列备用精灵列表 +func (h Controller) GetUserBagPetInfo( + data *pet.GetUserBagPetInfoInboundEmpty, + player *player.Player) (result *pet.GetUserBagPetInfoOutboundInfo, + err errorcode.ErrorCode) { + return buildUserBagPetInfo(player), 0 +} + // GetPetList 获取仓库列表 // data: 空输入结构 // player: 当前玩家对象 @@ -77,7 +119,7 @@ func (h Controller) GetPetList( data *pet.GetPetListInboundEmpty, player *player.Player) (result *pet.GetPetListOutboundInfo, err errorcode.ErrorCode) { - return buildPetListOutboundInfo(player.Service.Pet.PetInfo(0)), 0 + return buildPetListOutboundInfo(player.Info.PetList), 0 } // GetPetReleaseList 获取放生列表 @@ -88,7 +130,8 @@ func (h Controller) GetPetReleaseList( data *pet.GetPetListFreeInboundEmpty, player *player.Player) (result *pet.GetPetListOutboundInfo, err errorcode.ErrorCode) { - return buildPetListOutboundInfo(player.Service.Pet.PetInfo(1)), 0 + syncBackupPetList(player) + return buildPetListOutboundInfo(player.Info.BackupPetList), 0 } // PetReleaseToWarehouse 将精灵从仓库包中放生 @@ -156,6 +199,8 @@ func (h Controller) TogglePetBagWarehouse( return result, errorcode.ErrorCodes.ErrSystemError } + player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime) + player.Info.BackupPetList = append(player.Info.BackupPetList, *pet) player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...) } @@ -172,7 +217,10 @@ func (h Controller) TogglePetBagWarehouse( return result, errorcode.ErrorCodes.ErrPokemonNotExists } player.Info.PetList = append(player.Info.PetList, r.Data) + player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime) result.PetInfo = r.Data + } else { + player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime) } } diff --git a/logic/service/pet/bag_info.go b/logic/service/pet/bag_info.go new file mode 100644 index 000000000..9f96651b1 --- /dev/null +++ b/logic/service/pet/bag_info.go @@ -0,0 +1,17 @@ +package pet + +import ( + "blazing/logic/service/common" + "blazing/modules/player/model" +) + +type GetUserBagPetInfoInboundEmpty struct { + Head common.TomeeHeader `cmd:"4483" struc:"skip"` +} + +type GetUserBagPetInfoOutboundInfo struct { + PetListLen uint32 `struc:"int32,sizeof=PetList"` + PetList []model.PetInfo + BackupPetListLen uint32 `struc:"int32,sizeof=BackupPetList"` + BackupPetList []model.PetInfo +} diff --git a/logic/service/pet/pet.go b/logic/service/pet/pet.go index 2b9c7fb70..7b086e616 100644 --- a/logic/service/pet/pet.go +++ b/logic/service/pet/pet.go @@ -12,10 +12,6 @@ type InInfo struct { CatchTime uint32 } -type OutInfo struct { - model.PetInfo -} - // PetReleaseOutboundInfo 宠物释放出站消息 type PetReleaseOutboundInfo struct { HomeEnergy uint32 `json:"home_energy" fieldDescription:"暂定0" autoCodec:"true" uint:"true"` diff --git a/modules/config/model/map_model.go b/modules/config/model/map_model.go index a16f19c08..7c492e390 100644 --- a/modules/config/model/map_model.go +++ b/modules/config/model/map_model.go @@ -26,31 +26,22 @@ const ( MapModelDirectionRightUp ) -// MapModelBroadcastNode 地图模型广播节点配置 -type MapModelBroadcastNode struct { - TriggerID uint32 `gorm:"comment:'触发器ID'" json:"trigger_id" description:"触发器ID"` - Pos string `gorm:"type:varchar(255);default:'';comment:'位置'" json:"pos" description:"位置"` - HP int32 `gorm:"type:int;default:0;comment:'血量'" json:"hp" description:"血量"` - Direction int32 `gorm:"type:int;default:2;comment:'BOSS方向(0-7)'" json:"direction" description:"BOSS方向"` -} - // MapModel 地图模型配置表(NPC/宠物) type MapModel struct { *cool.Model // 保留通用Model(ID/创建时间/更新时间等) - *MapModelBroadcastNode MapID int32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"` - NodeID uint32 `gorm:"not null;default:0;comment:'节点ID'" json:"node_id" description:"节点ID"` - ModelID uint32 `gorm:"not null;default:0;comment:'模型ID(NPCID或精灵ID)'" json:"model_id" description:"模型ID"` ModelType int32 `gorm:"type:int;default:0;comment:'模型类型(0:精灵,1:NPC)'" json:"model_type" description:"模型类型"` ModelName string `gorm:"type:varchar(100);default:'';comment:'模型名称'" json:"model_name" description:"模型名称"` - HeadTalk string `gorm:"type:varchar(255);default:'';comment:'头顶对话框内容'" json:"head_talk" description:"头顶对话框内容"` - + HeadTalk string `gorm:"type:varchar(255);default:'';comment:'头顶对话框内容'" json:"head_talk" description:"头顶对话框内容"` + Pos string `gorm:"type:varchar(255);default:'';comment:'位置'" json:"pos" description:"位置"` + HP int32 `gorm:"type:int;default:0;comment:'血量'" json:"hp" description:"血量"` + Direction int32 `gorm:"type:int;default:2;comment:'方向(0-7)'" json:"direction" description:"BOSS方向"` TriggerPlotID uint32 `gorm:"default:0;comment:'触发剧情ID(0表示无剧情)'" json:"trigger_plot_id" description:"触发剧情ID"` Cloths []uint32 `gorm:"type:varchar(255);default:'';comment:'服装'" json:"cloths" description:"服装"` Shinyid int32 `gorm:"type:int;default:0;comment:'是否发光'" json:"shiny" description:"是否发光"` @@ -66,8 +57,7 @@ func (*MapModel) GroupName() string { func NewMapModel() *MapModel { return &MapModel{ - Model: cool.NewModel(), - MapModelBroadcastNode: &MapModelBroadcastNode{}, + Model: cool.NewModel(), } } diff --git a/modules/config/service/map_model.go b/modules/config/service/map_model.go index 067c9d786..21d3baa0b 100644 --- a/modules/config/service/map_model.go +++ b/modules/config/service/map_model.go @@ -76,6 +76,6 @@ func (s *MapmodelService) ServiceList(ctx context.Context, req *cool.ListReq) (d } func (s *MapmodelService) GetDataByModelId(modelid uint32) (ret *model.MapModel) { - dbm_notenable(s.Model).Where("model_id", modelid).Scan(&ret) + dbm_notenable(s.Model).Where("id", modelid).Scan(&ret) return } diff --git a/modules/player/model/info.go b/modules/player/model/info.go index 056a2d877..c6fe30541 100644 --- a/modules/player/model/info.go +++ b/modules/player/model/info.go @@ -54,8 +54,9 @@ func (p *PeopleItemInfo) InitDefaults() { func NewPlayerInfo() PlayerInfo { l := PlayerInfo{ - Clothes: make([]PeopleItemInfo, 0), - PetList: make([]PetInfo, 0), + Clothes: make([]PeopleItemInfo, 0), + PetList: make([]PetInfo, 0), + BackupPetList: make([]PetInfo, 0), } // 自动填充 struct tag 里的 default 值 @@ -198,16 +199,17 @@ type PlayerInfo struct { Nick string `struc:"[16]byte" default:"nono" json:"nono_nick"` // nono名字(16字节) } - TeamInfo TeamInfo `struc:"struct" json:"team_info"` // 战队信息24字节 - TeamPkInfo TeamPKInfo `struc:"struct" json:"team_pk_info"` // 8字节 - Reserved byte `struc:"byte" json:"reserved"` // 1字节无内容 - Badge uint32 `struc:"uint32" default:"0" json:"badge"` // 默认0 - Reserved1 [27]byte `struc:"[27]byte" default:"3" json:"reserved1"` // 27字节默认3 - TaskList [1000]byte `struc:"[1000]byte" default:"0" json:"task_list"` // 任务状态数组500字节,默认3 - PetListCount uint32 `struc:"sizeof=PetList" json:"pet_list_count"` // 精灵列表长度 - PetList []PetInfo ` json:"pet_list"` // 精灵背包内信息 - ClothesCount uint32 `struc:"sizeof=Clothes" json:"clothes_count"` // 穿戴装备数量 - Clothes []PeopleItemInfo ` json:"clothes"` // 穿戴装备 + TeamInfo TeamInfo `struc:"struct" json:"team_info"` // 战队信息24字节 + TeamPkInfo TeamPKInfo `struc:"struct" json:"team_pk_info"` // 8字节 + Reserved byte `struc:"byte" json:"reserved"` // 1字节无内容 + Badge uint32 `struc:"uint32" default:"0" json:"badge"` // 默认0 + Reserved1 [27]byte `struc:"[27]byte" default:"3" json:"reserved1"` // 27字节默认3 + TaskList [1000]byte `struc:"[1000]byte" default:"0" json:"task_list"` // 任务状态数组500字节,默认3 + PetListCount uint32 `struc:"sizeof=PetList" json:"pet_list_count"` // 精灵列表长度 + PetList []PetInfo ` json:"pet_list"` // 精灵背包内信息 + BackupPetList []PetInfo `struc:"skip" json:"backup_pet_list"` // 精灵并列备用列表 + ClothesCount uint32 `struc:"sizeof=Clothes" json:"clothes_count"` // 穿戴装备数量 + Clothes []PeopleItemInfo ` json:"clothes"` // 穿戴装备 } // trace("个人装扮是否半价:",MainManager.isClothHalfDay); diff --git a/modules/player/service/info.go b/modules/player/service/info.go index a5f9aeea1..247d62091 100644 --- a/modules/player/service/info.go +++ b/modules/player/service/info.go @@ -65,6 +65,13 @@ func (s *InfoService) GetLogin() *model.PlayerInfo { return nil } tt.Data.AllPetNumber = uint32(NewPetService(s.userid).PetCount(0)) + if len(tt.Data.BackupPetList) == 0 { + storagePets := NewPetService(s.userid).PetInfo(1) + tt.Data.BackupPetList = make([]model.PetInfo, len(storagePets)) + for i := range storagePets { + tt.Data.BackupPetList[i] = storagePets[i].Data + } + } if tt.Data.MapID > 300 || tt.Data.MapID == 0 { //如果位于基地,就重置到传送仓 tt.Data.MapID = 1