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,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func buildPetListOutboundInfo(petList []model.Pet) *pet.GetPetListOutboundInfo {
|
|
|
|
|
|
result := &pet.GetPetListOutboundInfo{
|
|
|
|
|
|
ShortInfoList: make([]pet.PetShortInfo, len(petList)),
|
|
|
|
|
|
}
|
|
|
|
|
|
for i := range petList {
|
|
|
|
|
|
result.ShortInfoList[i] = buildPetShortInfo(petList[i].Data)
|
|
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2025-12-25 12:21:15 +08:00
|
|
|
|
player *player.Player) (result *pet.OutInfo,
|
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 {
|
2025-11-23 23:38:03 +00:00
|
|
|
|
result = &pet.OutInfo{
|
2025-12-24 19:03:11 +08:00
|
|
|
|
PetInfo: *petInfo,
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
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
|
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
|
result = &pet.OutInfo{
|
2026-02-12 12:43:28 +08:00
|
|
|
|
PetInfo: ret.Data,
|
2025-12-24 19:03:11 +08:00
|
|
|
|
}
|
2025-09-11 02:44:21 +08:00
|
|
|
|
return result, 0
|
2025-08-30 21:59:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
// 返回: 精灵列表和错误码
|
|
|
|
|
|
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-03-31 09:19:36 +08:00
|
|
|
|
return buildPetListOutboundInfo(player.Service.Pet.PetInfo(0)), 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-03-31 09:19:36 +08:00
|
|
|
|
return buildPetListOutboundInfo(player.Service.Pet.PetInfo(1)), 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)
|
|
|
|
|
|
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
|
|
|
|
|
// 如果背包没找到,再放入背包
|
|
|
|
|
|
if inBag || freeForbidden == 1 {
|
|
|
|
|
|
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-03-26 04:51:36 +08:00
|
|
|
|
if !player.Service.Pet.UpdateFree(data.CatchTime, 0) {
|
2026-03-19 14:50:11 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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,
|
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
|
|
|
|
//擂台住不能换精灵
|
2025-12-25 12:21:15 +08:00
|
|
|
|
if player.GetSpace().Owner.UserID == player.Info.UserID {
|
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
|
|
|
|
|
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)
|
|
|
|
|
|
result.PetInfo = r.Data
|
|
|
|
|
|
}
|
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应该是空的
|
2025-11-20 21:37:37 +08:00
|
|
|
|
result = &pet.PetShowOutboundInfo{}
|
2025-12-25 12:21:15 +08:00
|
|
|
|
_, currentPet, ok := player.FindPet(data.CatchTime)
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if ok {
|
2026-03-31 09:19:36 +08:00
|
|
|
|
result = buildPetShowOutboundInfo(data.Head.UserID, data.Flag, currentPet)
|
2025-12-25 12:21:15 +08:00
|
|
|
|
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
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应该是空的
|
|
|
|
|
|
if player.GetSpace().Owner.UserID == player.Info.UserID {
|
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
|
|
|
|
//擂台住不能换精灵
|
2025-12-25 12:21:15 +08:00
|
|
|
|
if player.GetSpace().Owner.UserID == player.Info.UserID {
|
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
|
|
|
|
}
|