refactor: 重构宠物背包逻辑到玩家服务
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -12,35 +12,9 @@ func (h Controller) SavePetBagOrder(
|
||||
data *pet.SavePetBagOrderInboundInfo,
|
||||
player *player.Player) (result *fight.NullOutboundInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
|
||||
if len(data.PetList) > 6 || len(data.BackupPetList) > 6 {
|
||||
if !player.SavePetBagOrder(data.PetList, data.BackupPetList) {
|
||||
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 := buildPetInfoMap(player.Info.PetList, player.Info.BackupPetList)
|
||||
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
|
||||
}
|
||||
@@ -48,7 +22,7 @@ func (h Controller) SavePetBagOrder(
|
||||
// PetRetrieveFromWarehouse 领回仓库精灵
|
||||
func (h Controller) PetRetrieveFromWarehouse(
|
||||
data *pet.PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if _, ok := findPetListSlot(player, data.CatchTime); ok {
|
||||
if _, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
@@ -57,13 +31,7 @@ func (h Controller) PetRetrieveFromWarehouse(
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
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.AddPetToAvailableBag(petInfo.Data)
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
@@ -82,19 +50,19 @@ func (h Controller) TogglePetBagWarehouse(
|
||||
|
||||
switch data.Flag {
|
||||
case 0:
|
||||
slot, ok := findPetListSlot(player, data.CatchTime)
|
||||
slot, ok := player.FindPetBagSlot(data.CatchTime)
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
if !slot.isValid() {
|
||||
if !slot.IsValid() {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
if !player.Service.Pet.Update(slot.info) {
|
||||
if !player.Service.Pet.Update(slot.PetInfo()) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
slot.remove()
|
||||
if slot.kind == petListKindMain {
|
||||
slot.Remove()
|
||||
if slot.IsMainBag() {
|
||||
player.Service.Info.Save(*player.Info)
|
||||
}
|
||||
|
||||
@@ -102,7 +70,7 @@ func (h Controller) TogglePetBagWarehouse(
|
||||
if len(player.Info.PetList) >= 6 && len(player.Info.BackupPetList) >= 6 {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
if _, ok := findPetListSlot(player, data.CatchTime); ok {
|
||||
if _, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -110,11 +78,7 @@ func (h Controller) TogglePetBagWarehouse(
|
||||
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)
|
||||
}
|
||||
player.AddPetToAvailableBag(petInfo.Data)
|
||||
result.PetInfo = petInfo.Data
|
||||
}
|
||||
|
||||
@@ -151,7 +115,7 @@ func (h Controller) TogglePetBagWarehouseLegacy(
|
||||
}
|
||||
|
||||
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
|
||||
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
||||
player.RemoveBackupPet(data.CatchTime)
|
||||
player.Info.BackupPetList = append(player.Info.BackupPetList, *currentPet)
|
||||
|
||||
case 1:
|
||||
@@ -160,11 +124,11 @@ func (h Controller) TogglePetBagWarehouseLegacy(
|
||||
}
|
||||
|
||||
if _, _, ok := player.FindPet(data.CatchTime); ok {
|
||||
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
||||
player.RemoveBackupPet(data.CatchTime)
|
||||
break
|
||||
}
|
||||
|
||||
if index, backupPet, ok := findBackupPet(player, data.CatchTime); ok {
|
||||
if index, backupPet, ok := player.FindBackupPet(data.CatchTime); ok {
|
||||
if index < 0 || index >= len(player.Info.BackupPetList) {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user