feat: 新增精灵仓库管理及战斗特效逻辑
This commit is contained in:
199
logic/controller/pet_bag.go
Normal file
199
logic/controller/pet_bag.go
Normal file
@@ -0,0 +1,199 @@
|
||||
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 *pet.SavePetBagOrderInboundInfo,
|
||||
player *player.Player) (result *fight.NullOutboundInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
syncBackupPetList(player)
|
||||
|
||||
if len(data.PetList) > 6 || len(data.BackupPetList) > 6 {
|
||||
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
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
if petInfo == nil {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
syncBackupPetList(player)
|
||||
changed := false
|
||||
if len(player.Info.PetList) < 6 {
|
||||
player.Info.PetList = append(player.Info.PetList, petInfo.Data)
|
||||
changed = true
|
||||
} else if len(player.Info.BackupPetList) < 6 {
|
||||
player.Info.BackupPetList = append(player.Info.BackupPetList, petInfo.Data)
|
||||
changed = true
|
||||
}
|
||||
if changed {
|
||||
player.Service.Info.Save(*player.Info)
|
||||
}
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// TogglePetBagWarehouse 精灵背包仓库切换
|
||||
func (h Controller) TogglePetBagWarehouse(
|
||||
data *pet.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
|
||||
}
|
||||
|
||||
syncBackupPetList(player)
|
||||
|
||||
switch data.Flag {
|
||||
case 0:
|
||||
slot, ok := findPetListSlot(player, data.CatchTime)
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
if !slot.isValid() {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
if !player.Service.Pet.Update(slot.info) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
slot.remove()
|
||||
if slot.kind == petListKindMain {
|
||||
player.Service.Info.Save(*player.Info)
|
||||
}
|
||||
|
||||
case 1:
|
||||
if len(player.Info.PetList) >= 6 && len(player.Info.BackupPetList) >= 6 {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
if _, ok := findPetListSlot(player, data.CatchTime); ok {
|
||||
return result, 0
|
||||
}
|
||||
|
||||
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
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)
|
||||
}
|
||||
result.PetInfo = petInfo.Data
|
||||
}
|
||||
|
||||
if len(player.Info.PetList) > 0 {
|
||||
result.FirstPetTime = player.Info.PetList[0].CatchTime
|
||||
}
|
||||
|
||||
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.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, 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.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
||||
break
|
||||
}
|
||||
|
||||
if index, backupPet, ok := findBackupPet(player, 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
|
||||
}
|
||||
@@ -52,187 +52,10 @@ func (h Controller) GetPetReleaseList(
|
||||
return buildPetListOutboundInfo(buildWarehousePetList(player)), 0
|
||||
}
|
||||
|
||||
<<<<<<< ours
|
||||
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
||||
// data: 包含精灵ID和捕获时间的输入信息
|
||||
// player: 当前玩家对象
|
||||
// 返回: 无数据和错误码
|
||||
func (h Controller) PetReleaseToWarehouse(
|
||||
data *pet.PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, _, inBag := player.FindPet(data.CatchTime)
|
||||
_, _, inBackup := findBackupPet(player, data.CatchTime)
|
||||
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
||||
// 如果背包没找到,再放入背包
|
||||
if inBag || inBackup || freeForbidden == 1 {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||
}
|
||||
|
||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 1) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
return nil, err
|
||||
|
||||
}
|
||||
|
||||
// PetRetrieveFromWarehouse 领回包
|
||||
func (h Controller) PetRetrieveFromWarehouse(
|
||||
data *pet.PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
//如果背包没找到,再放入背包
|
||||
if _, _, ok := player.FindPet(data.CatchTime); !ok {
|
||||
if petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime); petInfo != nil {
|
||||
syncBackupPetList(player)
|
||||
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.Service.Info.Save(*player.Info)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, 0
|
||||
|
||||
}
|
||||
|
||||
// TogglePetBagWarehouse 精灵背包仓库切换
|
||||
func (h Controller) TogglePetBagWarehouse(
|
||||
data *pet.PetReleaseInboundInfo,
|
||||
player *player.Player) (result *pet.PetReleaseOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &pet.PetReleaseOutboundInfo{}
|
||||
result.Flag = uint32(data.Flag)
|
||||
|
||||
if player.IsArenaSwitchLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||||
}
|
||||
|
||||
syncBackupPetList(player)
|
||||
|
||||
switch data.Flag {
|
||||
case 0:
|
||||
if index, currentPet, ok := player.FindPet(data.CatchTime); ok {
|
||||
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.Service.Info.Save(*player.Info)
|
||||
break
|
||||
}
|
||||
|
||||
index, currentPet, ok := findBackupPet(player, data.CatchTime)
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
if index < 0 || index >= len(player.Info.BackupPetList) {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
if !player.Service.Pet.Update(*currentPet) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
player.Info.BackupPetList = append(player.Info.BackupPetList[:index], player.Info.BackupPetList[index+1:]...)
|
||||
|
||||
case 1:
|
||||
if len(player.Info.PetList) >= 6 && len(player.Info.BackupPetList) >= 6 {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
if _, _, ok := player.FindPet(data.CatchTime); ok {
|
||||
return result, 0
|
||||
}
|
||||
if _, _, ok := findBackupPet(player, data.CatchTime); ok {
|
||||
return result, 0
|
||||
}
|
||||
|
||||
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
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)
|
||||
}
|
||||
result.PetInfo = petInfo.Data
|
||||
|
||||
}
|
||||
|
||||
if len(player.Info.PetList) > 0 {
|
||||
result.FirstPetTime = player.Info.PetList[0].CatchTime
|
||||
}
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
func (h Controller) TogglePetBagWarehouseLegacy(
|
||||
data *pet.PetReleaseLegacyInboundInfo,
|
||||
player *player.Player) (
|
||||
result *pet.PetReleaseOutboundInfo,
|
||||
err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
|
||||
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
||||
|
||||
result = &pet.PetReleaseOutboundInfo{}
|
||||
result.Flag = uint32(data.Flag)
|
||||
//擂台住不能换精灵
|
||||
if player.IsArenaSwitchLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||||
}
|
||||
switch data.Flag {
|
||||
case 0:
|
||||
|
||||
index, pet, ok := player.FindPet(data.CatchTime)
|
||||
if ok {
|
||||
// ========== 新增:index合法性校验 ==========
|
||||
if index < 0 || index >= len(player.Info.PetList) {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
|
||||
if !player.Service.Pet.Update(*pet) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
||||
player.Info.BackupPetList = append(player.Info.BackupPetList, *pet)
|
||||
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
|
||||
}
|
||||
|
||||
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
||||
case 1:
|
||||
if len(player.Info.PetList) < 6 {
|
||||
//todo 背包
|
||||
_, _, ok := player.FindPet(data.CatchTime)
|
||||
|
||||
//如果背包没找到,再放入背包
|
||||
if !ok {
|
||||
r := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
if r == nil {
|
||||
return result, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
player.Info.PetList = append(player.Info.PetList, r.Data)
|
||||
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
||||
result.PetInfo = r.Data
|
||||
} else {
|
||||
player.Info.BackupPetList = removePetByCatchTime(player.Info.BackupPetList, data.CatchTime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(player.Info.PetList) > 0 {
|
||||
result.FirstPetTime = player.Info.PetList[0].CatchTime //设置首发
|
||||
}
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> theirs
|
||||
// PlayerShowPet 精灵展示
|
||||
func (h Controller) PlayerShowPet(
|
||||
data *pet.PetShowInboundInfo, player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) {
|
||||
data *pet.PetShowInboundInfo,
|
||||
player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &pet.PetShowOutboundInfo{
|
||||
UserID: data.Head.UserID,
|
||||
CatchTime: data.CatchTime,
|
||||
@@ -256,60 +79,4 @@ func (h Controller) PlayerShowPet(
|
||||
result = buildPetShowOutboundInfo(data.Head.UserID, data.Flag, currentPet)
|
||||
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
||||
return
|
||||
<<<<<<< ours
|
||||
|
||||
}
|
||||
|
||||
// PetOneCure 单体治疗
|
||||
func (h Controller) PetOneCure(
|
||||
data *pet.PetOneCureInboundInfo, player *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
if player.IsArenaHealLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
||||
}
|
||||
|
||||
_, currentPet, ok := player.FindPet(data.CatchTime)
|
||||
if ok {
|
||||
defer currentPet.Cure()
|
||||
|
||||
}
|
||||
|
||||
return &pet.PetOneCureOutboundInfo{
|
||||
CatchTime: data.CatchTime,
|
||||
}, 0
|
||||
|
||||
}
|
||||
|
||||
// PetFirst 精灵首发
|
||||
func (h Controller) PetFirst(
|
||||
data *pet.PetDefaultInboundInfo, player *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
//擂台住不能换精灵
|
||||
if player.IsArenaSwitchLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||||
}
|
||||
|
||||
result = &pet.PetDefaultOutboundInfo{}
|
||||
|
||||
index, _, ok := player.FindPet(data.CatchTime)
|
||||
if ok && index != 0 {
|
||||
|
||||
player.Info.PetList[index], player.Info.PetList[0] = player.Info.PetList[0], player.Info.PetList[index]
|
||||
|
||||
result.IsDefault = 1
|
||||
}
|
||||
|
||||
return result, 0
|
||||
|
||||
}
|
||||
|
||||
// SetPetExp 设置宠物经验
|
||||
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, currentPet, found := player.FindPet(data.CatchTime)
|
||||
if found && currentPet.Level < 100 {
|
||||
player.AddPetExp(currentPet, data.Exp)
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
||||
}
|
||||
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
||||
=======
|
||||
>>>>>>> theirs
|
||||
}
|
||||
|
||||
220
logic/controller/pet_info_helpers.go
Normal file
220
logic/controller/pet_info_helpers.go
Normal file
@@ -0,0 +1,220 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
type petListKind uint8
|
||||
|
||||
const (
|
||||
petListKindMain petListKind = iota
|
||||
petListKindBackup
|
||||
)
|
||||
|
||||
type petListSlot struct {
|
||||
list *[]model.PetInfo
|
||||
index int
|
||||
info model.PetInfo
|
||||
kind petListKind
|
||||
}
|
||||
|
||||
func (slot petListSlot) isValid() bool {
|
||||
return slot.list != nil && slot.index >= 0 && slot.index < len(*slot.list)
|
||||
}
|
||||
|
||||
func (slot petListSlot) remove() {
|
||||
*slot.list = append((*slot.list)[:slot.index], (*slot.list)[slot.index+1:]...)
|
||||
}
|
||||
|
||||
func buildPetShortInfo(info model.PetInfo) pet.PetShortInfo {
|
||||
return pet.PetShortInfo{
|
||||
ID: info.ID,
|
||||
CatchTime: info.CatchTime,
|
||||
Level: info.Level,
|
||||
SkinID: info.SkinID,
|
||||
ShinyLen: info.ShinyLen,
|
||||
ShinyInfo: info.ShinyInfo,
|
||||
}
|
||||
}
|
||||
|
||||
func buildPetListOutboundInfo(petList []model.PetInfo) *pet.GetPetListOutboundInfo {
|
||||
result := &pet.GetPetListOutboundInfo{
|
||||
ShortInfoList: make([]pet.PetShortInfo, len(petList)),
|
||||
}
|
||||
for i := range petList {
|
||||
result.ShortInfoList[i] = buildPetShortInfo(petList[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func removePetByCatchTime(petList []model.PetInfo, catchTime uint32) []model.PetInfo {
|
||||
for i := range petList {
|
||||
if petList[i].CatchTime == catchTime {
|
||||
return append(petList[:i], petList[i+1:]...)
|
||||
}
|
||||
}
|
||||
return petList
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func buildPetInfoMap(petLists ...[]model.PetInfo) map[uint32]model.PetInfo {
|
||||
total := 0
|
||||
for _, petList := range petLists {
|
||||
total += len(petList)
|
||||
}
|
||||
|
||||
petMap := make(map[uint32]model.PetInfo, total)
|
||||
for _, petList := range petLists {
|
||||
for _, petInfo := range petList {
|
||||
petMap[petInfo.CatchTime] = petInfo
|
||||
}
|
||||
}
|
||||
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) {
|
||||
for i := range player.Info.BackupPetList {
|
||||
if player.Info.BackupPetList[i].CatchTime == catchTime {
|
||||
return i, &player.Info.BackupPetList[i], true
|
||||
}
|
||||
}
|
||||
return -1, nil, false
|
||||
}
|
||||
|
||||
func findPetListSlot(player *player.Player, catchTime uint32) (petListSlot, bool) {
|
||||
if index, petInfo, ok := player.FindPet(catchTime); ok {
|
||||
return petListSlot{
|
||||
list: &player.Info.PetList,
|
||||
index: index,
|
||||
info: *petInfo,
|
||||
kind: petListKindMain,
|
||||
}, true
|
||||
}
|
||||
|
||||
if index, petInfo, ok := findBackupPet(player, catchTime); ok {
|
||||
return petListSlot{
|
||||
list: &player.Info.BackupPetList,
|
||||
index: index,
|
||||
info: *petInfo,
|
||||
kind: petListKindBackup,
|
||||
}, true
|
||||
}
|
||||
|
||||
return petListSlot{}, false
|
||||
}
|
||||
|
||||
func syncBackupPetList(player *player.Player) {
|
||||
if player.Info.BackupPetList == nil {
|
||||
player.Info.BackupPetList = make([]model.PetInfo, 0)
|
||||
return
|
||||
}
|
||||
|
||||
bagPets := player.Service.Pet.PetInfo(0)
|
||||
if len(bagPets) == 0 {
|
||||
player.Info.BackupPetList = make([]model.PetInfo, 0)
|
||||
return
|
||||
}
|
||||
|
||||
bagCatchTimes := make(map[uint32]struct{}, len(bagPets))
|
||||
for i := range bagPets {
|
||||
bagCatchTimes[bagPets[i].Data.CatchTime] = struct{}{}
|
||||
}
|
||||
|
||||
mainPetCatchTimes := buildCatchTimeSet(player.Info.PetList)
|
||||
nextBackupList := make([]model.PetInfo, 0, len(player.Info.BackupPetList))
|
||||
for _, petInfo := range player.Info.BackupPetList {
|
||||
if _, inBag := bagCatchTimes[petInfo.CatchTime]; !inBag {
|
||||
continue
|
||||
}
|
||||
if _, inMain := mainPetCatchTimes[petInfo.CatchTime]; inMain {
|
||||
continue
|
||||
}
|
||||
nextBackupList = append(nextBackupList, petInfo)
|
||||
}
|
||||
|
||||
player.Info.BackupPetList = nextBackupList
|
||||
}
|
||||
|
||||
func buildUserBagPetInfo(player *player.Player) *pet.GetUserBagPetInfoOutboundInfo {
|
||||
syncBackupPetList(player)
|
||||
|
||||
result := &pet.GetUserBagPetInfoOutboundInfo{
|
||||
PetList: make([]model.PetInfo, len(player.Info.PetList)),
|
||||
BackupPetList: make([]model.PetInfo, len(player.Info.BackupPetList)),
|
||||
}
|
||||
copy(result.PetList, player.Info.PetList)
|
||||
copy(result.BackupPetList, player.Info.BackupPetList)
|
||||
return result
|
||||
}
|
||||
|
||||
func buildOrderedPetList(
|
||||
catchTimes []uint32,
|
||||
petMap map[uint32]model.PetInfo,
|
||||
used map[uint32]struct{},
|
||||
) ([]model.PetInfo, bool) {
|
||||
result := make([]model.PetInfo, 0, len(catchTimes))
|
||||
for _, catchTime := range catchTimes {
|
||||
if catchTime == 0 {
|
||||
return nil, false
|
||||
}
|
||||
if _, exists := used[catchTime]; exists {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
petInfo, exists := petMap[catchTime]
|
||||
if !exists {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
used[catchTime] = struct{}{}
|
||||
result = append(result, petInfo)
|
||||
}
|
||||
return result, true
|
||||
}
|
||||
|
||||
func buildPetShowOutboundInfo(userID, flag uint32, info *model.PetInfo) *pet.PetShowOutboundInfo {
|
||||
return &pet.PetShowOutboundInfo{
|
||||
UserID: userID,
|
||||
CatchTime: info.CatchTime,
|
||||
ID: info.ID,
|
||||
Flag: flag,
|
||||
Dv: info.Dv,
|
||||
ShinyLen: info.ShinyLen,
|
||||
ShinyInfo: info.ShinyInfo,
|
||||
SkinID: info.SkinID,
|
||||
}
|
||||
}
|
||||
73
logic/controller/pet_manage.go
Normal file
73
logic/controller/pet_manage.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
)
|
||||
|
||||
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
||||
func (h Controller) PetReleaseToWarehouse(
|
||||
data *pet.PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, _, inBag := player.FindPet(data.CatchTime)
|
||||
_, _, inBackup := findBackupPet(player, data.CatchTime)
|
||||
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
||||
if inBag || inBackup || freeForbidden == 1 {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||
}
|
||||
|
||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 1) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// PetOneCure 单体治疗
|
||||
func (h Controller) PetOneCure(
|
||||
data *pet.PetOneCureInboundInfo, player *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) {
|
||||
if player.IsArenaHealLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
||||
}
|
||||
|
||||
_, currentPet, ok := player.FindPet(data.CatchTime)
|
||||
if ok {
|
||||
defer currentPet.Cure()
|
||||
}
|
||||
|
||||
return &pet.PetOneCureOutboundInfo{
|
||||
CatchTime: data.CatchTime,
|
||||
}, 0
|
||||
}
|
||||
|
||||
// PetFirst 精灵首发
|
||||
func (h Controller) PetFirst(
|
||||
data *pet.PetDefaultInboundInfo, player *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) {
|
||||
if player.IsArenaSwitchLocked() {
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||||
}
|
||||
|
||||
result = &pet.PetDefaultOutboundInfo{}
|
||||
index, _, ok := player.FindPet(data.CatchTime)
|
||||
if ok && index != 0 {
|
||||
player.Info.PetList[index], player.Info.PetList[0] = player.Info.PetList[0], player.Info.PetList[index]
|
||||
result.IsDefault = 1
|
||||
}
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
// SetPetExp 设置宠物经验
|
||||
func (h Controller) SetPetExp(
|
||||
data *pet.PetSetExpInboundInfo,
|
||||
player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, currentPet, found := player.FindPet(data.CatchTime)
|
||||
if !found || currentPet.Level >= 100 {
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
player.AddPetExp(currentPet, data.Exp)
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
||||
}
|
||||
Reference in New Issue
Block a user