Files
bl/logic/service/space/hot.go
昔念 0a8ef3d555 feat(fight_boss): 新增怪物ID处理逻辑,支持随机选择与过滤空值
新增 `processMonID` 函数用于处理 BOSS 战斗中怪物 ID 的字符串分割、
过滤空值,并在多个 ID 中随机选取一个。优化新手任务 BOSS 战逻辑,
使其更灵活地适配不同的配置输入。

---

refactor(map): 使用 ants 协程池优化地图进出逻辑并移除无用导入

将原本通过
2025-11-16 11:56:57 +08:00

69 lines
1.7 KiB
Go

package space
import (
csmap "github.com/mhmtszr/concurrent-swiss-map"
"golang.org/x/sync/singleflight"
)
var requestGroup singleflight.Group // SingleFlight 实例
// MapHotInfo 表示地图热度信息
type MapHotInfo struct {
MapID uint32 `json:"mapId"` // 地图ID
Count int32 `struc:"uint32" json:"count"` // 地图里的人数
}
var maphot = csmap.New[uint32, *int32](
// set the number of map shards. the default value is 32.
csmap.WithShardCount[uint32, *int32](32),
// // if don't set custom hasher, use the built-in maphash.
// csmap.WithCustomHasher[string, int](func(key string) uint64 {
// hash := fnv.New64a()
// hash.Write([]byte(key))
// return hash.Sum64()
// }),
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
// csmap.WithSize[string, int](1000),
)
func GetMapHot() []MapHotInfo {
ret := make([]MapHotInfo, 0)
maphot.Range(func(key uint32, value *int32) (stop bool) {
ret = append(ret, MapHotInfo{
MapID: key,
Count: *value,
})
return true
})
return ret
// result1, _, _ := requestGroup.Do("map_hot", func() (interface{}, error) {
// tt := make(map[uint32]uint32)
// for _, v := range xmlres.MapConfig.Maps {
// t1, ok := tt[uint32(v.Super)]
// if ok {
// tt[uint32(v.Super)] = uint32(int(t1) + GetSpace(uint32(v.ID)).User.Count())
// } else {
// tt[uint32(v.Super)] = uint32(GetSpace(uint32(v.ID)).User.Count())
// }
// }
// var result = make([]MapHotInfo, 0)
// for k, v := range tt {
// result = append(result, MapHotInfo{
// MapID: uint32(k),
// Count: uint32(v),
// })
// }
// return result, nil
// })
}