refactor: 重构宠物仓库列表获取逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
|
"blazing/logic/service/common"
|
||||||
"blazing/logic/service/pet"
|
"blazing/logic/service/pet"
|
||||||
"blazing/logic/service/player"
|
"blazing/logic/service/player"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
@@ -43,13 +44,17 @@ func (h Controller) GetPetList(
|
|||||||
return buildPetListOutboundInfo(player.Info.PetList), 0
|
return buildPetListOutboundInfo(player.Info.PetList), 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetPetListFreeInboundEmpty struct {
|
||||||
|
Head common.TomeeHeader `cmd:"2320" struc:"skip"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetPetReleaseList 获取仓库可放生列表
|
// GetPetReleaseList 获取仓库可放生列表
|
||||||
func (h Controller) GetPetReleaseList(
|
func (h Controller) GetPetReleaseList(
|
||||||
data *pet.GetPetListFreeInboundEmpty,
|
data *GetPetListFreeInboundEmpty,
|
||||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
||||||
err errorcode.ErrorCode) {
|
err errorcode.ErrorCode) {
|
||||||
|
|
||||||
return buildPetListOutboundInfo(buildWarehousePetList(player)), 0
|
return buildPetListOutboundInfo(player.WarehousePetList()), 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlayerShowPet 精灵展示
|
// PlayerShowPet 精灵展示
|
||||||
|
|||||||
@@ -88,23 +88,7 @@ func buildPetInfoMap(petLists ...[]model.PetInfo) map[uint32]model.PetInfo {
|
|||||||
return petMap
|
return petMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildWarehousePetList(player *player.Player) []model.PetInfo {
|
|
||||||
allPets := player.Service.Pet.PetInfo(0)
|
|
||||||
if len(allPets) == 0 {
|
|
||||||
return make([]model.PetInfo, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
usedCatchTimes := buildCatchTimeSet(player.Info.PetList, player.Info.BackupPetList)
|
|
||||||
result := make([]model.PetInfo, 0, len(allPets))
|
|
||||||
for i := range allPets {
|
|
||||||
catchTime := allPets[i].Data.CatchTime
|
|
||||||
if _, exists := usedCatchTimes[catchTime]; exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
result = append(result, allPets[i].Data)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func findBackupPet(player *player.Player, catchTime uint32) (int, *model.PetInfo, bool) {
|
func findBackupPet(player *player.Player, catchTime uint32) (int, *model.PetInfo, bool) {
|
||||||
for i := range player.Info.BackupPetList {
|
for i := range player.Info.BackupPetList {
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ import (
|
|||||||
type GetPetListInboundEmpty struct {
|
type GetPetListInboundEmpty struct {
|
||||||
Head common.TomeeHeader `cmd:"2303" struc:"skip"`
|
Head common.TomeeHeader `cmd:"2303" struc:"skip"`
|
||||||
}
|
}
|
||||||
type GetPetListFreeInboundEmpty struct {
|
|
||||||
Head common.TomeeHeader `cmd:"2320" struc:"skip"`
|
|
||||||
}
|
|
||||||
type GetPetListOutboundInfo struct {
|
type GetPetListOutboundInfo struct {
|
||||||
ShortInfoListLen uint32 `struc:"int32,sizeof=ShortInfoList"`
|
ShortInfoListLen uint32 `struc:"int32,sizeof=ShortInfoList"`
|
||||||
ShortInfoList []PetShortInfo
|
ShortInfoList []PetShortInfo
|
||||||
|
|||||||
@@ -11,6 +11,18 @@ import (
|
|||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (player *Player) WarehousePetList() []model.PetInfo {
|
||||||
|
allPets := player.Service.Pet.PetInfo(0)
|
||||||
|
if len(allPets) == 0 {
|
||||||
|
return make([]model.PetInfo, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result := make([]model.PetInfo, 0, len(allPets))
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// AddPetExp 添加宠物经验
|
// AddPetExp 添加宠物经验
|
||||||
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||||
if addExp < 0 {
|
if addExp < 0 {
|
||||||
|
|||||||
33
logic/service/player/pet_bag.go
Normal file
33
logic/service/player/pet_bag.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/logic/service/pet"
|
||||||
|
"blazing/modules/player/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildCatchTimeSet(petLists ...[]model.PetInfo) map[uint32]struct{} {
|
||||||
|
total := 0
|
||||||
|
for _, petList := range petLists {
|
||||||
|
total += len(petList)
|
||||||
|
}
|
||||||
|
|
||||||
|
catchTimes := make(map[uint32]struct{}, total)
|
||||||
|
for _, petList := range petLists {
|
||||||
|
for _, petInfo := range petList {
|
||||||
|
catchTimes[petInfo.CatchTime] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return catchTimes
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserBagPetInfo 返回主背包和并列备用精灵列表。
|
||||||
|
func (p *Player) GetUserBagPetInfo() *pet.GetUserBagPetInfoOutboundInfo {
|
||||||
|
|
||||||
|
result := &pet.GetUserBagPetInfoOutboundInfo{
|
||||||
|
PetList: make([]model.PetInfo, len(p.Info.PetList)),
|
||||||
|
BackupPetList: make([]model.PetInfo, len(p.Info.BackupPetList)),
|
||||||
|
}
|
||||||
|
copy(result.PetList, p.Info.PetList)
|
||||||
|
copy(result.BackupPetList, p.Info.BackupPetList)
|
||||||
|
return result
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user