81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/pet"
|
|
"blazing/logic/service/player"
|
|
)
|
|
|
|
// SavePetBagOrder 保存当前主背包和备用背包顺序
|
|
func (h Controller) SavePetBagOrder(
|
|
data *SavePetBagOrderInboundInfo,
|
|
player *player.Player) (result *fight.NullOutboundInfo,
|
|
err errorcode.ErrorCode) {
|
|
if !player.SavePetBagOrder(data.PetList, data.BackupPetList) {
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
}
|
|
player.Service.Info.Save(*player.Info)
|
|
return nil, 0
|
|
}
|
|
|
|
// PetRetrieveFromWarehouse 从放生仓库领回精灵
|
|
func (h Controller) PetRetrieveFromWarehouse(
|
|
data *PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if !player.Service.Pet.UpdateFree(data.CatchTime, 1, 0) {
|
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
}
|
|
|
|
return nil, 0
|
|
}
|
|
|
|
// TogglePetBagWarehouse 精灵背包仓库切换
|
|
func (h Controller) TogglePetBagWarehouse(
|
|
data *PetReleaseInboundInfo,
|
|
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:
|
|
slot, ok := player.FindPetBagSlot(data.CatchTime)
|
|
if !ok {
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
}
|
|
if !slot.IsValid() {
|
|
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
}
|
|
if !player.Service.Pet.Update(slot.PetInfo()) {
|
|
return result, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
slot.Remove()
|
|
|
|
case 1:
|
|
if len(player.Info.PetList) >= 6 && len(player.Info.BackupPetList) >= 6 {
|
|
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
|
}
|
|
if _, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
|
return result, 0
|
|
}
|
|
|
|
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
|
if petInfo == nil {
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
}
|
|
player.AddPetToAvailableBag(petInfo.Data)
|
|
result.PetInfo = petInfo.Data
|
|
}
|
|
|
|
if len(player.Info.PetList) > 0 {
|
|
result.FirstPetTime = player.Info.PetList[0].CatchTime
|
|
}
|
|
|
|
return result, 0
|
|
}
|