feat(pet): 宠物系统重构和功能增强 - 修复战斗boss中effect ID索引错误问题 - 实现宠物仓库和背包管理功能 - 添加宠物列表排序保存功能 - 重构宠物备份列表同步逻辑 - 优化宠物释放和获取逻辑 - 添加宠物背包仓库切换功能 - 修复地图模型广播信息结构问题 - 调整宠物特效数据库查询逻辑 ```
This commit is contained in:
@@ -160,7 +160,7 @@ func appendPetEffects(monster *model.PetInfo, effectIDs []uint32) {
|
||||
effects := service.NewEffectService().Args(effectIDs)
|
||||
for _, effect := range effects {
|
||||
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
|
||||
Idx: uint16(effect.SeIdx),
|
||||
Idx: uint16(effect.ID),
|
||||
EID: gconv.Uint16(effect.Eid),
|
||||
Args: gconv.Ints(effect.Args),
|
||||
})
|
||||
|
||||
@@ -224,7 +224,7 @@ func buildTowerMonsterInfo(towerBoss configmodel.BaseTowerConfig) (*model.Player
|
||||
effects := service.NewEffectService().Args(boss.Effect)
|
||||
for _, effect := range effects {
|
||||
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
|
||||
Idx: uint16(effect.SeIdx),
|
||||
Idx: uint16(effect.ID),
|
||||
EID: gconv.Uint16(effect.Eid),
|
||||
Args: gconv.Ints(effect.Args),
|
||||
})
|
||||
|
||||
@@ -39,21 +39,73 @@ func removePetByCatchTime(petList []model.PetInfo, catchTime uint32) []model.Pet
|
||||
return petList
|
||||
}
|
||||
|
||||
func syncBackupPetList(player *player.Player) {
|
||||
if len(player.Info.BackupPetList) > 0 {
|
||||
return
|
||||
func buildWarehousePetList(player *player.Player) []model.PetInfo {
|
||||
allPets := player.Service.Pet.PetInfo(0)
|
||||
if len(allPets) == 0 {
|
||||
return make([]model.PetInfo, 0)
|
||||
}
|
||||
|
||||
storagePets := player.Service.Pet.PetInfo(1)
|
||||
if len(storagePets) == 0 {
|
||||
usedCatchTimes := make(map[uint32]struct{}, len(player.Info.PetList)+len(player.Info.BackupPetList))
|
||||
for _, petInfo := range player.Info.PetList {
|
||||
usedCatchTimes[petInfo.CatchTime] = struct{}{}
|
||||
}
|
||||
for _, petInfo := range player.Info.BackupPetList {
|
||||
usedCatchTimes[petInfo.CatchTime] = struct{}{}
|
||||
}
|
||||
|
||||
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 syncBackupPetList(player *player.Player) {
|
||||
if player.Info.BackupPetList == nil {
|
||||
player.Info.BackupPetList = make([]model.PetInfo, 0)
|
||||
return
|
||||
}
|
||||
|
||||
player.Info.BackupPetList = make([]model.PetInfo, len(storagePets))
|
||||
for i := range storagePets {
|
||||
player.Info.BackupPetList[i] = storagePets[i].Data
|
||||
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 := make(map[uint32]struct{}, len(player.Info.PetList))
|
||||
for _, petInfo := range player.Info.PetList {
|
||||
mainPetCatchTimes[petInfo.CatchTime] = struct{}{}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -68,6 +120,31 @@ func buildUserBagPetInfo(player *player.Player) *pet.GetUserBagPetInfoOutboundIn
|
||||
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,
|
||||
@@ -115,6 +192,52 @@ func (h Controller) GetUserBagPetInfo(
|
||||
// data: 空输入结构
|
||||
// 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 := make(map[uint32]model.PetInfo, totalPetCount)
|
||||
for _, petInfo := range player.Info.PetList {
|
||||
petMap[petInfo.CatchTime] = petInfo
|
||||
}
|
||||
for _, petInfo := range player.Info.BackupPetList {
|
||||
petMap[petInfo.CatchTime] = petInfo
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (h Controller) GetPetList(
|
||||
data *pet.GetPetListInboundEmpty,
|
||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
||||
@@ -131,7 +254,7 @@ func (h Controller) GetPetReleaseList(
|
||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
syncBackupPetList(player)
|
||||
return buildPetListOutboundInfo(player.Info.BackupPetList), 0
|
||||
return buildPetListOutboundInfo(buildWarehousePetList(player)), 0
|
||||
}
|
||||
|
||||
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
||||
@@ -141,9 +264,10 @@ func (h Controller) GetPetReleaseList(
|
||||
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 || freeForbidden == 1 {
|
||||
if inBag || inBackup || freeForbidden == 1 {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||
}
|
||||
|
||||
@@ -160,10 +284,15 @@ func (h Controller) PetRetrieveFromWarehouse(
|
||||
|
||||
//如果背包没找到,再放入背包
|
||||
if _, _, ok := player.FindPet(data.CatchTime); !ok {
|
||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 0) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
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
|
||||
@@ -173,6 +302,76 @@ func (h Controller) PetRetrieveFromWarehouse(
|
||||
// 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.GetSpace().Owner.UserID == player.Info.UserID {
|
||||
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:]...)
|
||||
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 := 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
|
||||
player.Service.Info.Save(*player.Info)
|
||||
}
|
||||
|
||||
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应该是空的
|
||||
|
||||
@@ -15,3 +15,12 @@ type GetUserBagPetInfoOutboundInfo struct {
|
||||
BackupPetListLen uint32 `struc:"int32,sizeof=BackupPetList"`
|
||||
BackupPetList []model.PetInfo
|
||||
}
|
||||
|
||||
type SavePetBagOrderInboundInfo struct {
|
||||
Head common.TomeeHeader `cmd:"4484" struc:"skip"`
|
||||
|
||||
PetListLen uint32 `struc:"int32,sizeof=PetList"`
|
||||
PetList []uint32
|
||||
BackupPetListLen uint32 `struc:"int32,sizeof=BackupPetList"`
|
||||
BackupPetList []uint32
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ type PetReleaseInboundInfo struct {
|
||||
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
}
|
||||
|
||||
type PetReleaseLegacyInboundInfo struct {
|
||||
Head common.TomeeHeader `cmd:"52304" struc:"skip"`
|
||||
CatchTime uint32
|
||||
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
}
|
||||
|
||||
type PetShowInboundInfo struct {
|
||||
Head common.TomeeHeader `cmd:"2305" struc:"skip"`
|
||||
|
||||
|
||||
24
logic/service/space/info/map_model_broadcast.go
Normal file
24
logic/service/space/info/map_model_broadcast.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
configm "blazing/modules/config/model"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
type MapModelBroadcastInfo struct {
|
||||
Wer int32 `struc:"uint32"`
|
||||
InfoLen uint32 `struc:"sizeof=INFO" json:"info_len"`
|
||||
|
||||
INFO []MapModelBroadcastEntry
|
||||
}
|
||||
|
||||
type MapModelBroadcastEntry struct {
|
||||
ModelID uint32 `json:"model_id" protobuf:"1,req,name=model_id"`
|
||||
Region uint32 `json:"region" protobuf:"2,req,name=region"`
|
||||
Hp int32 `struc:"uint32" json:"hp" protobuf:"3,req,name=hp"`
|
||||
PosIndex uint32 `struc:"uint32" json:"pos_index" protobuf:"4,req,name=pos_index"`
|
||||
IsShow int32 `struc:"uint32" json:"is_show"`
|
||||
PosInfo []model.Pos `struc:"skip"`
|
||||
Config configm.MapNode `struc:"skip"`
|
||||
Model configm.MapModel `struc:"skip"`
|
||||
}
|
||||
@@ -34,10 +34,10 @@ type Space struct {
|
||||
CanRefresh bool
|
||||
Super uint32
|
||||
|
||||
ID uint32
|
||||
Name string
|
||||
Owner ARENA
|
||||
info.MapBossSInfo
|
||||
ID uint32
|
||||
Name string
|
||||
Owner ARENA
|
||||
MapBossSInfo info.MapModelBroadcastInfo
|
||||
|
||||
WeatherType []uint32
|
||||
TimeBoss info.S2C_2022
|
||||
@@ -183,8 +183,8 @@ func (ret *Space) init() {
|
||||
if r.IsTimeSpace != 0 {
|
||||
ret.IsTime = true
|
||||
}
|
||||
ret.MapBossSInfo = info.MapBossSInfo{}
|
||||
ret.MapBossSInfo.INFO = make([]info.MapBossInfo, 0)
|
||||
ret.MapBossSInfo = info.MapModelBroadcastInfo{}
|
||||
ret.MapBossSInfo.INFO = make([]info.MapModelBroadcastEntry, 0)
|
||||
if len(r.WeatherType) > 1 {
|
||||
ret.WeatherType = r.WeatherType
|
||||
|
||||
@@ -196,8 +196,8 @@ func (ret *Space) init() {
|
||||
if r == nil {
|
||||
continue
|
||||
}
|
||||
info := info.MapBossInfo{
|
||||
Id: uint32(r.ID),
|
||||
info := info.MapModelBroadcastEntry{
|
||||
ModelID: uint32(r.ID),
|
||||
Region: v.NodeID,
|
||||
Hp: r.HP,
|
||||
PosInfo: ParseCoordinateString(r.Pos),
|
||||
@@ -239,9 +239,9 @@ func (p *Space) IsMatch(t model.Event) bool {
|
||||
return true
|
||||
|
||||
}
|
||||
func (ret *Space) GenBoss(isfrist bool) *info.MapBossSInfo {
|
||||
var res info.MapBossSInfo
|
||||
res.Wer = ret.Wer
|
||||
func (ret *Space) GenBoss(isfrist bool) *info.MapModelBroadcastInfo {
|
||||
var res info.MapModelBroadcastInfo
|
||||
res.Wer = ret.MapBossSInfo.Wer
|
||||
for i := 0; i < len(ret.MapBossSInfo.INFO); i++ {
|
||||
if !ret.IsMatch(*ret.MapBossSInfo.INFO[i].Config.Event) {
|
||||
|
||||
@@ -254,7 +254,7 @@ func (ret *Space) GenBoss(isfrist bool) *info.MapBossSInfo {
|
||||
}
|
||||
s := len(ret.MapBossSInfo.INFO[i].PosInfo)
|
||||
if s != 0 {
|
||||
ret.MapBossSInfo.INFO[i].Pos = ret.MapBossSInfo.INFO[i].PosInfo[(grand.Intn(s-1)+1+int(ret.MapBossSInfo.INFO[i].PosIndex))%s]
|
||||
ret.MapBossSInfo.INFO[i].PosIndex = uint32(grand.Intn(s))
|
||||
}
|
||||
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 1
|
||||
|
||||
Reference in New Issue
Block a user