feat(pet): 优化宠物仓库和背包功能的数据库操作

- 使用copier.CopyWithOption替代直接赋值,确保深拷贝操作
- 移除冗余的model导入,简化代码结构
- 重构PetReleaseToWarehouse和PetRetrieveFromWarehouse方法,
  直接调用UPdateFree方法更新宠物状态
- 优化TogglePetBagWarehouse方法中的宠物数据更新逻辑
- 添加
This commit is contained in:
2025-12-31 01:35:20 +08:00
parent b86ab8d5a9
commit be70f50939
4 changed files with 34 additions and 46 deletions

View File

@@ -7,8 +7,6 @@ import (
"blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/modules/blazing/model"
"github.com/jinzhu/copier"
)
@@ -76,17 +74,14 @@ func (h Controller) GetPetReleaseList(
// 返回: 无数据和错误码
func (h Controller) PetReleaseToWarehouse(
data *pet.PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
player.Service.Pet.PetInfo_One_exec(data.CatchTime, func(petInfo *model.PetEX) {
_, _, inBag := player.FindPet(data.CatchTime)
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
// 如果背包没找到,再放入背包
if !inBag && petInfo.CatchTime != 0 && freeForbidden == 0 {
petInfo.Free = 1
} else {
err = errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
}
})
_, _, inBag := player.FindPet(data.CatchTime)
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
// 如果背包没找到,再放入背包
if inBag || freeForbidden == 1 {
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
}
player.Service.Pet.UPdateFree(data.CatchTime, 1)
return nil, err
}
@@ -95,14 +90,10 @@ func (h Controller) PetReleaseToWarehouse(
func (h Controller) PetRetrieveFromWarehouse(
data *pet.PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
player.Service.Pet.PetInfo_One_exec(data.CatchTime, func(petInfo *model.PetEX) {
//如果背包没找到,再放入背包
if _, _, ok := player.FindPet(data.CatchTime); !ok && petInfo.CatchTime != 0 {
petInfo.Free = 0
}
})
//如果背包没找到,再放入背包
if _, _, ok := player.FindPet(data.CatchTime); !ok {
player.Service.Pet.UPdateFree(data.CatchTime, 0)
}
return nil, 0
@@ -128,11 +119,7 @@ func (h Controller) TogglePetBagWarehouse(
index, pet, ok := player.FindPet(data.CatchTime)
if ok {
player.Service.Pet.PetInfo_One_exec(data.CatchTime, func(petData *model.PetEX) {
petData.Data = *pet
//t.InBag = 0
})
player.Service.Pet.UPdate(*pet)
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
}
@@ -140,18 +127,15 @@ func (h Controller) TogglePetBagWarehouse(
case 1:
if len(player.Info.PetList) < 6 {
//todo 背包
player.Service.Pet.PetInfo_One_exec(data.CatchTime, func(petData *model.PetEX) {
_, _, ok := player.FindPet(data.CatchTime)
_, _, ok := player.FindPet(data.CatchTime)
//如果背包没找到,再放入背包
if !ok {
r := player.Service.Pet.PetInfo_One(data.CatchTime)
player.Info.PetList = append(player.Info.PetList, r.Data)
result.PetInfo = r.Data
}
//如果背包没找到,再放入背包
if !ok && petData.CatchTime != 0 {
//t.InBag = 1
player.Info.PetList = append(player.Info.PetList, petData.Data)
result.PetInfo = petData.Data
}
})
}
}
@@ -242,4 +226,4 @@ func (h Controller) GetPetBargeList(data *pet.PetBargeListInboundInfo, player *p
return &pet.PetBargeListOutboundInfo{
PetBargeList: make([]pet.PetBargeListInfo, 0),
}, 0
}
}