Files
bl/logic/service/pet/pet.go
昔念 6979b7018d ```
feat(space): 替换并发安全map实现以提升性能

将原来基于`utils.ConcurrentMap`的玩家存储结构替换为
`github.com/mhmtszr/concurrent-swiss-map`提供的`CsMap`,
以获得更高效的并发读写能力。

同时修改了相关API调用方式:
- `Set` 改为 `Store`
- `Remove` 改为 `Delete`
- `IterCb` 改为 `Range`,并支持提前终止迭代
- `Items()` 不再使用

此外,调整了部分业务逻辑中对玩家列表遍历的方式,
确保在发送网络包后及时跳出循环,避免不必要的操作。

新增战斗类型处理函数`PET_King`用于处理宠物王相关的
战斗请求,并修复了`PET_MELEE`方法中的逻辑问题。

更新了go.mod和go.sum引入新的依赖库。
```
2025-11-15 15:22:58 +08:00

82 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package pet
import (
"blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/blazing/model"
)
type InInfo struct {
Head player.TomeeHeader `cmd:"2301" struc:"[0]pad"`
CatchTime uint32
}
type OutInfo struct {
model.PetInfo
}
// PetReleaseOutboundInfo 宠物释放出站消息
type PetReleaseOutboundInfo struct {
HomeEnergy uint32 `json:"home_energy" fieldDescription:"暂定0" autoCodec:"true" uint:"true"`
FirstPetTime uint32 `json:"first_pet_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
Flag uint32
PetInfo model.PetInfo `json:"pet_info" fieldDescription:"精灵信息" autoCodec:"true"`
}
// 放入背包或者加入仓库
type PetReleaseInboundInfo struct {
Head player.TomeeHeader `cmd:"2304" struc:"[0]pad"`
CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库1为放入背包" autoCodec:"true" uint:"true"`
}
type PetShowInboundInfo struct {
Head player.TomeeHeader `cmd:"2305" struc:"[0]pad"`
CatchTime uint32 `codec:"catchTime" inboundMessageType:"Pet_Show"`
Flag uint32 `codec:"flag"`
}
func (t *PetShowInboundInfo) Broadcast(mapid uint32, o PetShowOutboundInfo) {
space.GetSpace(mapid).User.Range(func(key uint32, v common.PlayerI) (stop bool) {
t.Head.Result = 0
v.SendPack(t.Head.Pack(&o))
return false
})
}
type PetShowOutboundInfo struct {
UserID uint32 `codec:"UserID" description:"米米号"`
CatchTime uint32 `codec:"CatchTime" description:"精灵获得的时间"`
ID uint32 `codec:"PetID" description:"精灵编号"`
Flag uint32 `codec:"flag" description:"1为显示 0为收回"`
Dv uint32 `codec:"dv" description:"个体"`
Shiny uint32 `codec:"shiny" description:"闪光状态标识"`
SkinID uint32 `codec:"skinID" description:"皮肤ID"`
Reserved1 [3]uint32
}
type PetOneCureInboundInfo struct {
Head player.TomeeHeader `cmd:"2310" struc:"[0]pad"`
CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"`
} // PetOneCureOutboundInfo 宠物单个治疗出站消息
type PetOneCureOutboundInfo struct {
CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"`
}
// PetDefaultInboundInfo
// 实现了InboundMessage接口
type PetDefaultInboundInfo struct {
Head player.TomeeHeader `cmd:"2308" struc:"[0]pad"`
CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true" autoCodec:"true" inboundMessageType:"Pet_Default"`
}
// PetDefaultOutboundInfo
// 实现了OutboundMessage接口
type PetDefaultOutboundInfo struct {
IsDefault uint32 `json:"isDefault" fieldDescription:"0: 首发设置失败1: 首发设置成功" uint:"true" autoCodec:"true" outboundMessageType:"Pet_Default"`
}