feat(map): 实现地图热度统计功能并优化数据类型

This commit is contained in:
1
2025-08-16 03:18:48 +00:00
parent a02de8a4b4
commit 92c2d95764
3 changed files with 32 additions and 4 deletions

View File

@@ -4,15 +4,24 @@ import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/logic/service/maphot"
"blazing/logic/service/space"
)
func (h Controller) MapHot(data *maphot.InInfo, c *entity.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
result = &maphot.OutInfo{
HotInfos: make([]maphot.MapHotInfo, 0),
}
return
ttt := space.GetMapHot()
for k, v := range ttt {
result.HotInfos = append(result.HotInfos, maphot.MapHotInfo{
MapID: uint32(k),
Count: uint32(space.GetPlanet(uint32(v)).Len()),
})
}
return
}

View File

@@ -4,8 +4,8 @@ import "blazing/common/socket/handler"
// MapHotInfo 表示地图热度信息
type MapHotInfo struct {
MapID uint64 `json:"mapId"` // 地图ID
Count uint64 `json:"count"` // 地图里的人数
MapID uint32 `json:"mapId"` // 地图ID
Count uint32 `json:"count"` // 地图里的人数
}
type InInfo struct {
Head handler.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录

View File

@@ -8,8 +8,27 @@ import (
"blazing/modules/blazing/model"
)
func GetMapHot() map[uint32]uint32 {
tt := make(map[uint32]uint32)
for _, v := range xml.MapConfig.Maps {
t1, ok := tt[uint32(v.Super)]
if ok {
tt[uint32(v.Super)] = uint32(int(t1) + GetPlanet(uint32(v.ID)).Len())
} else {
tt[uint32(v.Super)] = uint32(GetPlanet(uint32(v.ID)).Len())
}
}
return tt
}
// 获取星球
func GetPlanet(id uint32) *Space {
planet, ok := planetmap.Load(id)
if ok {
return planet