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:
@@ -62,9 +62,6 @@ func (h Controller) TogglePetBagWarehouse(
|
||||
}
|
||||
|
||||
slot.Remove()
|
||||
if slot.IsMainBag() {
|
||||
player.Service.Info.Save(*player.Info)
|
||||
}
|
||||
|
||||
case 1:
|
||||
if len(player.Info.PetList) >= 6 && len(player.Info.BackupPetList) >= 6 {
|
||||
@@ -88,69 +85,3 @@ func (h Controller) TogglePetBagWarehouse(
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
// TogglePetBagWarehouseLegacy 旧版精灵背包仓库切换
|
||||
func (h Controller) TogglePetBagWarehouseLegacy(
|
||||
data *pet.PetReleaseLegacyInboundInfo,
|
||||
player *player.Player) (result *pet.PetReleaseOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &pet.PetReleaseOutboundInfo{
|
||||
Flag: uint32(data.Flag),
|
||||
}
|
||||
|
||||
if player.IsArenaSwitchLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||||
}
|
||||
|
||||
switch data.Flag {
|
||||
case 0:
|
||||
index, currentPet, ok := player.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
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.RemoveBackupPet(data.CatchTime)
|
||||
player.Info.BackupPetList = append(player.Info.BackupPetList, *currentPet)
|
||||
|
||||
case 1:
|
||||
if len(player.Info.PetList) >= 6 {
|
||||
break
|
||||
}
|
||||
|
||||
if _, _, ok := player.FindPet(data.CatchTime); ok {
|
||||
player.RemoveBackupPet(data.CatchTime)
|
||||
break
|
||||
}
|
||||
|
||||
if index, backupPet, ok := player.FindBackupPet(data.CatchTime); ok {
|
||||
if index < 0 || index >= len(player.Info.BackupPetList) {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
|
||||
result.PetInfo = *backupPet
|
||||
player.Info.PetList = append(player.Info.PetList, *backupPet)
|
||||
player.Info.BackupPetList = append(player.Info.BackupPetList[:index], player.Info.BackupPetList[index+1:]...)
|
||||
break
|
||||
}
|
||||
|
||||
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
if petInfo == nil {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
player.Info.PetList = append(player.Info.PetList, petInfo.Data)
|
||||
result.PetInfo = petInfo.Data
|
||||
}
|
||||
|
||||
if len(player.Info.PetList) > 0 {
|
||||
result.FirstPetTime = player.Info.PetList[0].CatchTime
|
||||
}
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user