2025-08-20 22:50:55 +08:00
|
|
|
|
package controller
|
2025-08-24 17:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-11 01:07:00 +08:00
|
|
|
|
"blazing/common/data/xmlres"
|
2025-08-24 17:33:19 +08:00
|
|
|
|
"blazing/common/socket/errorcode"
|
2025-11-24 11:56:20 +08:00
|
|
|
|
"blazing/logic/service/fight"
|
2025-08-24 17:33:19 +08:00
|
|
|
|
"blazing/logic/service/pet"
|
2025-09-14 01:35:16 +08:00
|
|
|
|
"blazing/logic/service/player"
|
2026-03-31 09:19:36 +08:00
|
|
|
|
"blazing/modules/player/model"
|
2025-08-24 17:33:19 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2026-03-31 09:19:36 +08:00
|
|
|
|
func buildPetShortInfo(info model.PetInfo) pet.PetShortInfo {
|
|
|
|
|
|
return pet.PetShortInfo{
|
|
|
|
|
|
ID: info.ID,
|
|
|
|
|
|
CatchTime: info.CatchTime,
|
|
|
|
|
|
Level: info.Level,
|
|
|
|
|
|
SkinID: info.SkinID,
|
|
|
|
|
|
ShinyLen: info.ShinyLen,
|
|
|
|
|
|
ShinyInfo: info.ShinyInfo,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 02:33:05 +08:00
|
|
|
|
func buildPetListOutboundInfo(petList []model.PetInfo) *pet.GetPetListOutboundInfo {
|
2026-03-31 09:19:36 +08:00
|
|
|
|
result := &pet.GetPetListOutboundInfo{
|
|
|
|
|
|
ShortInfoList: make([]pet.PetShortInfo, len(petList)),
|
|
|
|
|
|
}
|
|
|
|
|
|
for i := range petList {
|
2026-04-02 02:33:05 +08:00
|
|
|
|
result.ShortInfoList[i] = buildPetShortInfo(petList[i])
|
2026-03-31 09:19:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 02:33:05 +08:00
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 07:49:49 +08:00
|
|
|
|
func buildWarehousePetList(player *player.Player) []model.PetInfo {
|
|
|
|
|
|
allPets := player.Service.Pet.PetInfo(0)
|
|
|
|
|
|
if len(allPets) == 0 {
|
|
|
|
|
|
return make([]model.PetInfo, 0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
usedCatchTimes := make(map[uint32]struct{}, len(player.Info.PetList)+len(player.Info.BackupPetList))
|
|
|
|
|
|
for _, petInfo := range player.Info.PetList {
|
|
|
|
|
|
usedCatchTimes[petInfo.CatchTime] = struct{}{}
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, petInfo := range player.Info.BackupPetList {
|
|
|
|
|
|
usedCatchTimes[petInfo.CatchTime] = struct{}{}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result := make([]model.PetInfo, 0, len(allPets))
|
|
|
|
|
|
for i := range allPets {
|
|
|
|
|
|
catchTime := allPets[i].Data.CatchTime
|
|
|
|
|
|
if _, exists := usedCatchTimes[catchTime]; exists {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
result = append(result, allPets[i].Data)
|
|
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func findBackupPet(player *player.Player, catchTime uint32) (int, *model.PetInfo, bool) {
|
|
|
|
|
|
for i := range player.Info.BackupPetList {
|
|
|
|
|
|
if player.Info.BackupPetList[i].CatchTime == catchTime {
|
|
|
|
|
|
return i, &player.Info.BackupPetList[i], true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return -1, nil, false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 02:33:05 +08:00
|
|
|
|
func syncBackupPetList(player *player.Player) {
|
2026-04-02 07:49:49 +08:00
|
|
|
|
if player.Info.BackupPetList == nil {
|
|
|
|
|
|
player.Info.BackupPetList = make([]model.PetInfo, 0)
|
2026-04-02 02:33:05 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 07:49:49 +08:00
|
|
|
|
bagPets := player.Service.Pet.PetInfo(0)
|
|
|
|
|
|
if len(bagPets) == 0 {
|
2026-04-02 02:33:05 +08:00
|
|
|
|
player.Info.BackupPetList = make([]model.PetInfo, 0)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 07:49:49 +08:00
|
|
|
|
bagCatchTimes := make(map[uint32]struct{}, len(bagPets))
|
|
|
|
|
|
for i := range bagPets {
|
|
|
|
|
|
bagCatchTimes[bagPets[i].Data.CatchTime] = struct{}{}
|
2026-04-02 02:33:05 +08:00
|
|
|
|
}
|
2026-04-02 07:49:49 +08:00
|
|
|
|
|
|
|
|
|
|
mainPetCatchTimes := make(map[uint32]struct{}, len(player.Info.PetList))
|
|
|
|
|
|
for _, petInfo := range player.Info.PetList {
|
|
|
|
|
|
mainPetCatchTimes[petInfo.CatchTime] = struct{}{}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nextBackupList := make([]model.PetInfo, 0, len(player.Info.BackupPetList))
|
|
|
|
|
|
for _, petInfo := range player.Info.BackupPetList {
|
|
|
|
|
|
if _, inBag := bagCatchTimes[petInfo.CatchTime]; !inBag {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if _, inMain := mainPetCatchTimes[petInfo.CatchTime]; inMain {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
nextBackupList = append(nextBackupList, petInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
player.Info.BackupPetList = nextBackupList
|
2026-04-02 02:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 07:49:49 +08:00
|
|
|
|
func buildOrderedPetList(
|
|
|
|
|
|
catchTimes []uint32,
|
|
|
|
|
|
petMap map[uint32]model.PetInfo,
|
|
|
|
|
|
used map[uint32]struct{},
|
|
|
|
|
|
) ([]model.PetInfo, bool) {
|
|
|
|
|
|
result := make([]model.PetInfo, 0, len(catchTimes))
|
|
|
|
|
|
for _, catchTime := range catchTimes {
|
|
|
|
|
|
if catchTime == 0 {
|
|
|
|
|
|
return nil, false
|
|
|
|
|
|
}
|
|
|
|
|
|
if _, exists := used[catchTime]; exists {
|
|
|
|
|
|
return nil, false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
petInfo, exists := petMap[catchTime]
|
|
|
|
|
|
if !exists {
|
|
|
|
|
|
return nil, false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
used[catchTime] = struct{}{}
|
|
|
|
|
|
result = append(result, petInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
return result, true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 09:19:36 +08:00
|
|
|
|
func buildPetShowOutboundInfo(userID, flag uint32, info *model.PetInfo) *pet.PetShowOutboundInfo {
|
|
|
|
|
|
return &pet.PetShowOutboundInfo{
|
|
|
|
|
|
UserID: userID,
|
|
|
|
|
|
CatchTime: info.CatchTime,
|
|
|
|
|
|
ID: info.ID,
|
|
|
|
|
|
Flag: flag,
|
|
|
|
|
|
Dv: info.Dv,
|
|
|
|
|
|
ShinyLen: info.ShinyLen,
|
|
|
|
|
|
ShinyInfo: info.ShinyInfo,
|
|
|
|
|
|
SkinID: info.SkinID,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// GetPetInfo 获取精灵信息
|
|
|
|
|
|
// data: 包含精灵捕获时间的输入信息
|
2025-12-25 12:21:15 +08:00
|
|
|
|
// player: 当前玩家对象
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// 返回: 精灵信息和错误码
|
|
|
|
|
|
func (h Controller) GetPetInfo(
|
2025-08-30 21:59:52 +08:00
|
|
|
|
data *pet.InInfo,
|
2026-04-02 02:33:05 +08:00
|
|
|
|
player *player.Player) (result *model.PetInfo,
|
2025-12-24 19:03:11 +08:00
|
|
|
|
err errorcode.ErrorCode) {
|
2025-12-25 12:21:15 +08:00
|
|
|
|
_, petInfo, found := player.FindPet(data.CatchTime)
|
2025-09-11 02:44:21 +08:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
if found {
|
2026-04-02 02:33:05 +08:00
|
|
|
|
result = petInfo
|
2025-11-23 23:38:03 +00:00
|
|
|
|
return result, 0
|
2025-09-11 02:44:21 +08:00
|
|
|
|
}
|
2026-03-26 04:51:36 +08:00
|
|
|
|
ret := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
2026-01-20 16:01:15 +00:00
|
|
|
|
if ret == nil {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2026-04-02 02:33:05 +08:00
|
|
|
|
result = &ret.Data
|
2025-09-11 02:44:21 +08:00
|
|
|
|
return result, 0
|
2025-08-30 21:59:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-02 02:33:05 +08:00
|
|
|
|
// GetUserBagPetInfo 获取主背包和并列备用精灵列表
|
|
|
|
|
|
func (h Controller) GetUserBagPetInfo(
|
|
|
|
|
|
data *pet.GetUserBagPetInfoInboundEmpty,
|
|
|
|
|
|
player *player.Player) (result *pet.GetUserBagPetInfoOutboundInfo,
|
|
|
|
|
|
err errorcode.ErrorCode) {
|
|
|
|
|
|
return buildUserBagPetInfo(player), 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// GetPetList 获取仓库列表
|
|
|
|
|
|
// data: 空输入结构
|
2025-12-25 12:21:15 +08:00
|
|
|
|
// player: 当前玩家对象
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// 返回: 精灵列表和错误码
|
2026-04-02 07:49:49 +08:00
|
|
|
|
// SavePetBagOrder 保存当前主背包和备用背包顺序
|
|
|
|
|
|
func (h Controller) SavePetBagOrder(
|
|
|
|
|
|
data *pet.SavePetBagOrderInboundInfo,
|
|
|
|
|
|
player *player.Player) (result *fight.NullOutboundInfo,
|
|
|
|
|
|
err errorcode.ErrorCode) {
|
|
|
|
|
|
syncBackupPetList(player)
|
|
|
|
|
|
|
|
|
|
|
|
if len(data.PetList) > 6 || len(data.BackupPetList) > 6 {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
totalPetCount := len(player.Info.PetList) + len(player.Info.BackupPetList)
|
|
|
|
|
|
if len(data.PetList)+len(data.BackupPetList) != totalPetCount {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
petMap := make(map[uint32]model.PetInfo, totalPetCount)
|
|
|
|
|
|
for _, petInfo := range player.Info.PetList {
|
|
|
|
|
|
petMap[petInfo.CatchTime] = petInfo
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, petInfo := range player.Info.BackupPetList {
|
|
|
|
|
|
petMap[petInfo.CatchTime] = petInfo
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
used := make(map[uint32]struct{}, totalPetCount)
|
|
|
|
|
|
|
|
|
|
|
|
battleList, ok := buildOrderedPetList(data.PetList, petMap, used)
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
backupList, ok := buildOrderedPetList(data.BackupPetList, petMap, used)
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(used) != totalPetCount {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
player.Info.PetList = battleList
|
|
|
|
|
|
player.Info.BackupPetList = backupList
|
|
|
|
|
|
player.Service.Info.Save(*player.Info)
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
func (h Controller) GetPetList(
|
2025-09-01 01:03:46 +08:00
|
|
|
|
data *pet.GetPetListInboundEmpty,
|
2025-12-25 12:21:15 +08:00
|
|
|
|
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
2025-12-24 19:03:11 +08:00
|
|
|
|
err errorcode.ErrorCode) {
|
2026-04-02 02:33:05 +08:00
|
|
|
|
return buildPetListOutboundInfo(player.Info.PetList), 0
|
2025-09-01 01:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// GetPetReleaseList 获取放生列表
|
|
|
|
|
|
// data: 空输入结构
|
2025-12-25 12:21:15 +08:00
|
|
|
|
// player: 当前玩家对象
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// 返回: 放生精灵列表和错误码
|
|
|
|
|
|
func (h Controller) GetPetReleaseList(
|
2025-11-24 11:56:20 +08:00
|
|
|
|
data *pet.GetPetListFreeInboundEmpty,
|
2025-12-25 12:21:15 +08:00
|
|
|
|
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
2025-12-24 19:03:11 +08:00
|
|
|
|
err errorcode.ErrorCode) {
|
2026-04-02 02:33:05 +08:00
|
|
|
|
syncBackupPetList(player)
|
2026-04-02 07:49:49 +08:00
|
|
|
|
return buildPetListOutboundInfo(buildWarehousePetList(player)), 0
|
2025-11-24 11:56:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
|
|
|
|
|
// data: 包含精灵ID和捕获时间的输入信息
|
2025-12-25 12:21:15 +08:00
|
|
|
|
// player: 当前玩家对象
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// 返回: 无数据和错误码
|
|
|
|
|
|
func (h Controller) PetReleaseToWarehouse(
|
2025-12-25 12:21:15 +08:00
|
|
|
|
data *pet.PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-31 01:35:20 +08:00
|
|
|
|
_, _, inBag := player.FindPet(data.CatchTime)
|
2026-04-02 07:49:49 +08:00
|
|
|
|
_, _, inBackup := findBackupPet(player, data.CatchTime)
|
2025-12-31 01:35:20 +08:00
|
|
|
|
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
|
|
|
|
|
// 如果背包没找到,再放入背包
|
2026-04-02 07:49:49 +08:00
|
|
|
|
if inBag || inBackup || freeForbidden == 1 {
|
2025-12-31 01:35:20 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
|
|
|
|
|
}
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
2026-03-26 04:51:36 +08:00
|
|
|
|
if !player.Service.Pet.UpdateFree(data.CatchTime, 1) {
|
2026-03-19 14:50:11 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2025-12-06 23:59:00 +08:00
|
|
|
|
return nil, err
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// PetRetrieveFromWarehouse 领回包
|
|
|
|
|
|
func (h Controller) PetRetrieveFromWarehouse(
|
2025-12-25 12:21:15 +08:00
|
|
|
|
data *pet.PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
2025-12-31 01:35:20 +08:00
|
|
|
|
//如果背包没找到,再放入背包
|
|
|
|
|
|
if _, _, ok := player.FindPet(data.CatchTime); !ok {
|
2026-04-02 07:49:49 +08:00
|
|
|
|
if petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime); petInfo != nil {
|
|
|
|
|
|
syncBackupPetList(player)
|
|
|
|
|
|
if len(player.Info.PetList) < 6 {
|
|
|
|
|
|
player.Info.PetList = append(player.Info.PetList, petInfo.Data)
|
|
|
|
|
|
} else if len(player.Info.BackupPetList) < 6 {
|
|
|
|
|
|
player.Info.BackupPetList = append(player.Info.BackupPetList, petInfo.Data)
|
|
|
|
|
|
}
|
|
|
|
|
|
player.Service.Info.Save(*player.Info)
|
2026-03-19 14:50:11 +08:00
|
|
|
|
}
|
2025-12-31 01:35:20 +08:00
|
|
|
|
}
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// TogglePetBagWarehouse 精灵背包仓库切换
|
|
|
|
|
|
func (h Controller) TogglePetBagWarehouse(
|
2025-08-30 21:59:52 +08:00
|
|
|
|
data *pet.PetReleaseInboundInfo,
|
2026-04-02 07:49:49 +08:00
|
|
|
|
player *player.Player) (result *pet.PetReleaseOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
|
result = &pet.PetReleaseOutboundInfo{}
|
|
|
|
|
|
result.Flag = uint32(data.Flag)
|
|
|
|
|
|
|
2026-04-02 23:05:18 +08:00
|
|
|
|
if player.IsArenaSwitchLocked() {
|
2026-04-02 07:49:49 +08:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
syncBackupPetList(player)
|
|
|
|
|
|
|
|
|
|
|
|
switch data.Flag {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
if index, currentPet, ok := player.FindPet(data.CatchTime); ok {
|
|
|
|
|
|
if index < 0 || index >= len(player.Info.PetList) {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
if !player.Service.Pet.Update(*currentPet) {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
|
|
|
|
|
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
|
|
|
|
|
|
player.Service.Info.Save(*player.Info)
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
index, currentPet, ok := findBackupPet(player, data.CatchTime)
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
if index < 0 || index >= len(player.Info.BackupPetList) {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
if !player.Service.Pet.Update(*currentPet) {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
|
|
|
|
|
player.Info.BackupPetList = append(player.Info.BackupPetList[:index], player.Info.BackupPetList[index+1:]...)
|
|
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
if len(player.Info.PetList) >= 6 && len(player.Info.BackupPetList) >= 6 {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
|
|
|
|
}
|
|
|
|
|
|
if _, _, ok := player.FindPet(data.CatchTime); ok {
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
}
|
|
|
|
|
|
if _, _, ok := findBackupPet(player, data.CatchTime); ok {
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
|
|
|
|
|
if petInfo == nil {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(player.Info.PetList) < 6 {
|
|
|
|
|
|
player.Info.PetList = append(player.Info.PetList, petInfo.Data)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
player.Info.BackupPetList = append(player.Info.BackupPetList, petInfo.Data)
|
|
|
|
|
|
}
|
|
|
|
|
|
result.PetInfo = petInfo.Data
|
2026-04-02 10:23:07 +08:00
|
|
|
|
|
2026-04-02 07:49:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(player.Info.PetList) > 0 {
|
|
|
|
|
|
result.FirstPetTime = player.Info.PetList[0].CatchTime
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (h Controller) TogglePetBagWarehouseLegacy(
|
|
|
|
|
|
data *pet.PetReleaseLegacyInboundInfo,
|
2025-12-25 12:21:15 +08:00
|
|
|
|
player *player.Player) (
|
2025-08-30 21:59:52 +08:00
|
|
|
|
result *pet.PetReleaseOutboundInfo,
|
|
|
|
|
|
err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-08-31 06:53:42 +00:00
|
|
|
|
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
|
|
|
|
|
|
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
2025-11-20 05:57:29 +08:00
|
|
|
|
|
2025-08-31 06:53:42 +00:00
|
|
|
|
result = &pet.PetReleaseOutboundInfo{}
|
2025-09-01 01:03:46 +08:00
|
|
|
|
result.Flag = uint32(data.Flag)
|
2025-11-20 05:57:29 +08:00
|
|
|
|
//擂台住不能换精灵
|
2026-04-02 23:05:18 +08:00
|
|
|
|
if player.IsArenaSwitchLocked() {
|
2025-11-20 05:57:29 +08:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
|
|
|
|
}
|
2025-08-31 06:53:42 +00:00
|
|
|
|
switch data.Flag {
|
|
|
|
|
|
case 0:
|
2025-11-05 17:06:08 +00:00
|
|
|
|
|
2025-12-25 12:21:15 +08:00
|
|
|
|
index, pet, ok := player.FindPet(data.CatchTime)
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if ok {
|
2026-02-10 22:09:15 +08:00
|
|
|
|
// ========== 新增:index合法性校验 ==========
|
|
|
|
|
|
if index < 0 || index >= len(player.Info.PetList) {
|
2026-02-13 22:57:05 +08:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
2026-02-10 22:09:15 +08:00
|
|
|
|
}
|
2026-03-26 02:35:43 +08:00
|
|
|
|
|
2026-03-26 04:51:36 +08:00
|
|
|
|
if !player.Service.Pet.Update(*pet) {
|
2026-03-19 14:50:11 +08:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2026-01-20 04:40:36 +08:00
|
|
|
|
|
2026-04-02 02:33:05 +08:00
|
|
|
|
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
|
|
|
|
|
player.Info.BackupPetList = append(player.Info.BackupPetList, *pet)
|
2025-12-25 12:21:15 +08:00
|
|
|
|
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
|
2025-08-31 06:53:42 +00:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-11-05 17:06:08 +00:00
|
|
|
|
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
2025-08-31 06:53:42 +00:00
|
|
|
|
case 1:
|
2025-12-25 12:21:15 +08:00
|
|
|
|
if len(player.Info.PetList) < 6 {
|
2025-11-23 23:38:03 +00:00
|
|
|
|
//todo 背包
|
2025-12-31 01:35:20 +08:00
|
|
|
|
_, _, ok := player.FindPet(data.CatchTime)
|
2025-11-13 02:43:00 +08:00
|
|
|
|
|
2025-12-31 01:35:20 +08:00
|
|
|
|
//如果背包没找到,再放入背包
|
|
|
|
|
|
if !ok {
|
2026-03-26 04:51:36 +08:00
|
|
|
|
r := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
2026-01-09 19:58:12 +08:00
|
|
|
|
if r == nil {
|
2026-02-13 22:57:05 +08:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
2026-01-09 19:58:12 +08:00
|
|
|
|
}
|
2025-12-31 01:35:20 +08:00
|
|
|
|
player.Info.PetList = append(player.Info.PetList, r.Data)
|
2026-04-02 02:33:05 +08:00
|
|
|
|
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
2025-12-31 01:35:20 +08:00
|
|
|
|
result.PetInfo = r.Data
|
2026-04-02 02:33:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
2025-12-31 01:35:20 +08:00
|
|
|
|
}
|
2025-11-13 02:43:00 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
}
|
2025-08-31 06:53:42 +00:00
|
|
|
|
|
2025-09-07 05:58:47 +08:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-12-25 12:21:15 +08:00
|
|
|
|
if len(player.Info.PetList) > 0 {
|
|
|
|
|
|
result.FirstPetTime = player.Info.PetList[0].CatchTime //设置首发
|
2025-09-07 05:58:47 +08:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-08-31 06:53:42 +00:00
|
|
|
|
return result, 0
|
2025-08-24 17:33:19 +08:00
|
|
|
|
}
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// PlayerShowPet 精灵展示
|
|
|
|
|
|
func (h Controller) PlayerShowPet(
|
2025-12-25 12:21:15 +08:00
|
|
|
|
data *pet.PetShowInboundInfo, player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2026-04-01 02:48:09 +08:00
|
|
|
|
result = &pet.PetShowOutboundInfo{
|
|
|
|
|
|
UserID: data.Head.UserID,
|
|
|
|
|
|
CatchTime: data.CatchTime,
|
|
|
|
|
|
Flag: data.Flag,
|
|
|
|
|
|
}
|
2025-12-25 12:21:15 +08:00
|
|
|
|
_, currentPet, ok := player.FindPet(data.CatchTime)
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
2026-04-01 02:48:09 +08:00
|
|
|
|
if data.Flag == 0 {
|
|
|
|
|
|
player.SetPetDisplay(0, nil)
|
|
|
|
|
|
player.GetSpace().RefreshUserInfo(player)
|
2025-12-25 12:21:15 +08:00
|
|
|
|
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2026-04-01 02:48:09 +08:00
|
|
|
|
return
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
2026-04-01 02:48:09 +08:00
|
|
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
player.SetPetDisplay(data.Flag, currentPet)
|
|
|
|
|
|
player.GetSpace().RefreshUserInfo(player)
|
|
|
|
|
|
result = buildPetShowOutboundInfo(data.Head.UserID, data.Flag, currentPet)
|
|
|
|
|
|
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-18 20:52:04 +00:00
|
|
|
|
return
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// PetOneCure 单体治疗
|
|
|
|
|
|
func (h Controller) PetOneCure(
|
2025-12-25 12:21:15 +08:00
|
|
|
|
data *pet.PetOneCureInboundInfo, player *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2026-04-02 23:05:18 +08:00
|
|
|
|
if player.IsArenaHealLocked() {
|
2025-11-20 05:57:29 +08:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
2025-12-25 12:21:15 +08:00
|
|
|
|
_, currentPet, ok := player.FindPet(data.CatchTime)
|
2025-09-21 17:01:31 +00:00
|
|
|
|
if ok {
|
2025-12-24 19:03:11 +08:00
|
|
|
|
defer currentPet.Cure()
|
2025-11-29 19:26:56 +08:00
|
|
|
|
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-21 17:01:31 +00:00
|
|
|
|
return &pet.PetOneCureOutboundInfo{
|
|
|
|
|
|
CatchTime: data.CatchTime,
|
|
|
|
|
|
}, 0
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-12 19:21:39 +08:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// PetFirst 精灵首发
|
|
|
|
|
|
func (h Controller) PetFirst(
|
2025-12-25 12:21:15 +08:00
|
|
|
|
data *pet.PetDefaultInboundInfo, player *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-11-23 23:38:03 +00:00
|
|
|
|
//擂台住不能换精灵
|
2026-04-02 23:05:18 +08:00
|
|
|
|
if player.IsArenaSwitchLocked() {
|
2025-11-23 23:38:03 +00:00
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-12 19:21:39 +08:00
|
|
|
|
result = &pet.PetDefaultOutboundInfo{}
|
|
|
|
|
|
|
2025-12-25 12:21:15 +08:00
|
|
|
|
index, _, ok := player.FindPet(data.CatchTime)
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if ok && index != 0 {
|
|
|
|
|
|
|
2025-12-25 12:21:15 +08:00
|
|
|
|
player.Info.PetList[index], player.Info.PetList[0] = player.Info.PetList[0], player.Info.PetList[index]
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
|
|
|
|
|
result.IsDefault = 1
|
2025-09-12 19:21:39 +08:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-09-12 19:21:39 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-21 17:01:31 +00:00
|
|
|
|
|
2025-12-25 12:21:15 +08:00
|
|
|
|
// SetPetExp 设置宠物经验
|
|
|
|
|
|
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
|
_, currentPet, found := player.FindPet(data.CatchTime)
|
|
|
|
|
|
if found && currentPet.Level < 100 {
|
|
|
|
|
|
player.AddPetExp(currentPet, data.Exp)
|
2026-03-31 09:19:36 +08:00
|
|
|
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
2025-09-26 13:33:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 09:19:36 +08:00
|
|
|
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
2025-09-26 13:33:55 +08:00
|
|
|
|
}
|