Merge branch 'main' of https://cnb.cool/blzing/blazing
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-01 02:53:41 +08:00
committed by cnb
11 changed files with 179 additions and 57 deletions

View File

@@ -189,13 +189,28 @@ func (h Controller) TogglePetBagWarehouse(
// PlayerShowPet 精灵展示
func (h Controller) PlayerShowPet(
data *pet.PetShowInboundInfo, player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.PetShowOutboundInfo{}
result = &pet.PetShowOutboundInfo{
UserID: data.Head.UserID,
CatchTime: data.CatchTime,
Flag: data.Flag,
}
_, currentPet, ok := player.FindPet(data.CatchTime)
if ok {
result = buildPetShowOutboundInfo(data.Head.UserID, data.Flag, currentPet)
if data.Flag == 0 {
player.SetPetDisplay(0, nil)
player.GetSpace().RefreshUserInfo(player)
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
if !ok {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
player.SetPetDisplay(data.Flag, currentPet)
player.GetSpace().RefreshUserInfo(player)
result = buildPetShowOutboundInfo(data.Head.UserID, data.Flag, currentPet)
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}

View File

@@ -0,0 +1,60 @@
package player
import (
"blazing/common/data"
spaceinfo "blazing/logic/service/space/info"
"blazing/modules/player/model"
)
type PetDisplayState struct {
Flag uint32
CatchTime uint32
PetID uint32
Dv uint32
ShinyInfo []data.GlowFilter
SkinID uint32
}
func (p *Player) SetPetDisplay(flag uint32, petInfo *model.PetInfo) {
if flag == 0 || petInfo == nil {
p.PetDisplay = PetDisplayState{}
return
}
p.PetDisplay = PetDisplayState{
Flag: flag,
CatchTime: petInfo.CatchTime,
PetID: petInfo.ID,
Dv: petInfo.Dv,
ShinyInfo: append([]data.GlowFilter(nil), petInfo.ShinyInfo...),
SkinID: petInfo.SkinID,
}
}
func (p *Player) ApplyPetDisplayInfo(out *spaceinfo.SimpleInfo) {
if out == nil {
return
}
out.SpiritTime = 0
out.SpiritID = 0
out.PetDV = 0
out.ShinyLen = 0
out.ShinyInfo = nil
out.PetSkin = 0
out.PetRide = 0
if p.PetDisplay.CatchTime == 0 || p.PetDisplay.PetID == 0 || p.PetDisplay.Flag == 0 {
return
}
out.SpiritTime = p.PetDisplay.CatchTime
out.SpiritID = p.PetDisplay.PetID
out.PetDV = p.PetDisplay.Dv
out.ShinyInfo = append([]data.GlowFilter(nil), p.PetDisplay.ShinyInfo...)
out.ShinyLen = uint32(len(out.ShinyInfo))
out.PetSkin = p.PetDisplay.SkinID
if p.PetDisplay.Flag == 2 {
out.PetRide = 2
}
}

View File

@@ -103,6 +103,7 @@ type Player struct {
Logintime uint32 // 当前登录时间
OgrePet
PetDisplay PetDisplayState
Service *blservice.UserService
User *service.BaseSysUserService

View File

@@ -10,6 +10,10 @@ import (
"github.com/jinzhu/copier"
)
type petDisplayInfoProvider interface {
ApplyPetDisplayInfo(*info.SimpleInfo)
}
// 向其他人广播,不含自己
// 广播是c 为空就不特判,发给全体成员广播
func (s *Space) Broadcast(c common.PlayerI, cmd uint32, data any) {
@@ -53,6 +57,9 @@ func (s *Space) EnterMap(c common.PlayerI) {
out := info.NewOutInfo()
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
if provider, ok := c.(petDisplayInfoProvider); ok {
provider.ApplyPetDisplayInfo(out)
}
c.SendPackCmd(2001, out)
s.Broadcast(c, 2001, out)
@@ -65,6 +72,19 @@ func (s *Space) EnterMap(c common.PlayerI) {
}
}
func (s *Space) RefreshUserInfo(c common.PlayerI) {
current, ok := s.UserInfo.Load(c.GetInfo().UserID)
if !ok {
return
}
if provider, ok := c.(petDisplayInfoProvider); ok {
provider.ApplyPetDisplayInfo(&current)
s.UserInfo.Store(c.GetInfo().UserID, current)
}
}
func (s *Space) GetInfo(c common.PlayerI) []info.SimpleInfo {
ret := make([]info.SimpleInfo, 0)

View File

@@ -100,9 +100,9 @@ type SimpleInfo struct {
ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"`
ShinyInfo []data.GlowFilter `json:"ShinyInfo,omitempty"`
// 宠物皮肤暂时无法测试,给 0
PetSkin uint32 `struc:"uint32" fieldDesc:"宠物皮肤暂时无法测试, 给0" json:"pet_skin"`
// 填充字符
Reserved [3]uint32
PetSkin uint32 `struc:"uint32" fieldDesc:"宠物皮肤暂时无法测试, 给0" json:"pet_skin"`
PetRide uint32 `struc:"uint32" fieldDesc:"pet ride flag" json:"pet_ride"`
Reserved [2]uint32
// 暂时不明给0
FightFlag uint32 `struc:"uint32" fieldDesc:"暂时不明给0" json:"fight_flag"`