2025-08-15 22:44:28 +08:00
|
|
|
|
package space
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-30 00:36:08 +08:00
|
|
|
|
"blazing/common/data/xmlres"
|
2025-12-09 16:14:47 +00:00
|
|
|
|
"blazing/cool"
|
2025-11-15 22:17:43 +00:00
|
|
|
|
|
2025-09-14 01:35:16 +08:00
|
|
|
|
"blazing/logic/service/common"
|
2025-12-12 19:10:09 +00:00
|
|
|
|
"blazing/logic/service/space/info"
|
2025-11-15 15:22:58 +08:00
|
|
|
|
|
2025-12-16 08:35:22 +00:00
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2025-11-15 15:22:58 +08:00
|
|
|
|
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
2025-12-13 18:35:17 +08:00
|
|
|
|
"github.com/samber/lo"
|
2025-12-09 16:14:47 +00:00
|
|
|
|
"github.com/tnnmigga/enum"
|
2025-08-15 22:44:28 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-09 16:14:47 +00:00
|
|
|
|
// 定义天气状态枚举实例
|
|
|
|
|
|
var WeatherStatus = enum.New[struct {
|
|
|
|
|
|
Normal uint32 `enum:"0"` // 正常
|
|
|
|
|
|
Rain uint32 `enum:"1"` // 下雨
|
|
|
|
|
|
Snow uint32 `enum:"2"` // 下雪
|
|
|
|
|
|
}]()
|
|
|
|
|
|
|
2025-12-13 18:35:17 +08:00
|
|
|
|
// 定义天气地图
|
|
|
|
|
|
var wermap = []uint32{32}
|
|
|
|
|
|
|
2025-08-15 22:44:28 +08:00
|
|
|
|
// Space 针对Player的并发安全map,键为uint32类型
|
|
|
|
|
|
type Space struct {
|
2025-11-15 15:22:58 +08:00
|
|
|
|
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
2026-01-17 00:47:41 +08:00
|
|
|
|
UserInfo *csmap.CsMap[uint32, info.SimpleInfo]
|
2025-11-16 11:56:57 +08:00
|
|
|
|
CanRefresh bool //是否能够刷怪
|
|
|
|
|
|
Super uint32
|
2025-11-25 21:10:52 +08:00
|
|
|
|
//SuperValue *int32
|
2025-12-09 16:52:53 +08:00
|
|
|
|
ID uint32 // 地图ID
|
2025-11-28 00:16:51 +08:00
|
|
|
|
Name string //地图名称
|
|
|
|
|
|
Owner ARENA
|
2025-12-09 14:52:55 +08:00
|
|
|
|
info.MapBossInfo
|
2025-12-16 08:35:22 +00:00
|
|
|
|
TimeBoss info.S2C_2022
|
|
|
|
|
|
Weather uint32
|
|
|
|
|
|
//CanWeather uint32
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewSyncMap 创建一个新的玩家同步map
|
|
|
|
|
|
func NewSpace() *Space {
|
2025-11-17 15:31:23 +00:00
|
|
|
|
|
2025-12-09 14:52:55 +08:00
|
|
|
|
ret := &Space{
|
2025-11-15 15:22:58 +08:00
|
|
|
|
User: csmap.New[uint32, common.PlayerI](
|
|
|
|
|
|
// set the number of map shards. the default value is 32.
|
|
|
|
|
|
csmap.WithShardCount[uint32, common.PlayerI](32),
|
|
|
|
|
|
|
|
|
|
|
|
// // if don't set custom hasher, use the built-in maphash.
|
2025-11-20 21:37:37 +08:00
|
|
|
|
csmap.WithCustomHasher[uint32, common.PlayerI](func(key uint32) uint64 {
|
|
|
|
|
|
|
|
|
|
|
|
return uint64(key)
|
|
|
|
|
|
}),
|
2025-11-15 15:22:58 +08:00
|
|
|
|
|
2025-11-16 11:56:57 +08:00
|
|
|
|
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
|
|
|
|
|
// csmap.WithSize[string, int](1000),
|
|
|
|
|
|
),
|
2026-01-17 00:47:41 +08:00
|
|
|
|
UserInfo: csmap.New[uint32, info.SimpleInfo](
|
2025-11-16 11:56:57 +08:00
|
|
|
|
// set the number of map shards. the default value is 32.
|
2026-01-17 00:47:41 +08:00
|
|
|
|
csmap.WithShardCount[uint32, info.SimpleInfo](32),
|
|
|
|
|
|
csmap.WithCustomHasher[uint32, info.SimpleInfo](func(key uint32) uint64 {
|
2025-11-16 11:56:57 +08:00
|
|
|
|
|
2025-11-20 21:37:37 +08:00
|
|
|
|
return uint64(key)
|
|
|
|
|
|
}),
|
2025-11-16 11:56:57 +08:00
|
|
|
|
// // 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()
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
2025-11-15 15:22:58 +08:00
|
|
|
|
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
|
|
|
|
|
// csmap.WithSize[string, int](1000),
|
|
|
|
|
|
),
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
2025-12-09 14:52:55 +08:00
|
|
|
|
|
|
|
|
|
|
return ret
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-16 03:36:13 +00:00
|
|
|
|
// 获取星球
|
|
|
|
|
|
func GetSpace(id uint32) *Space {
|
|
|
|
|
|
|
|
|
|
|
|
planet, ok := planetmap.Load(id)
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
return planet
|
|
|
|
|
|
}
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret := NewSpace()
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
2025-10-10 23:16:45 +08:00
|
|
|
|
if id < 10000 { //说明是玩家地图GetSpace
|
2025-08-20 22:34:45 +08:00
|
|
|
|
|
2025-10-10 23:16:45 +08:00
|
|
|
|
for _, v := range xmlres.MapConfig.Maps {
|
|
|
|
|
|
if v.ID == int(id) { //找到这个地图
|
2025-11-16 11:56:57 +08:00
|
|
|
|
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret.Super = uint32(v.Super)
|
|
|
|
|
|
if ret.Super == 0 {
|
|
|
|
|
|
ret.Super = uint32(v.ID)
|
2025-11-26 01:33:48 +08:00
|
|
|
|
}
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret.ID = uint32(v.ID)
|
|
|
|
|
|
ret.getfixboss(uint32(v.ID))
|
2025-12-09 16:52:53 +08:00
|
|
|
|
//t.gettimeboss(uint32(v.ID))
|
2025-12-10 11:59:32 +08:00
|
|
|
|
_, ok := maphot[ret.Super]
|
2025-11-25 21:10:52 +08:00
|
|
|
|
if !ok {
|
|
|
|
|
|
var t1 int32
|
2025-12-10 11:59:32 +08:00
|
|
|
|
maphot[ret.Super] = &t1
|
2025-11-16 11:56:57 +08:00
|
|
|
|
}
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret.Name = v.Name
|
2025-11-25 21:10:52 +08:00
|
|
|
|
break
|
2025-10-10 23:16:45 +08:00
|
|
|
|
}
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-09 16:14:47 +00:00
|
|
|
|
|
2025-12-13 18:35:17 +08:00
|
|
|
|
if _, ok := lo.Find(wermap, func(mapID uint32) bool { return mapID == ret.ID }); ok {
|
2025-12-16 08:35:22 +00:00
|
|
|
|
// ret.CanWeather = 1
|
2025-12-13 18:35:17 +08:00
|
|
|
|
cool.Cron.CustomFunc(ret, func() {
|
2025-12-16 08:35:22 +00:00
|
|
|
|
//if ret.CanWeather == 1 {
|
|
|
|
|
|
var neww uint32 = 0
|
|
|
|
|
|
|
|
|
|
|
|
if grand.Meet(1, 10) {
|
|
|
|
|
|
neww = uint32(grand.N(1, 2))
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if neww != ret.Weather {
|
|
|
|
|
|
ret.Broadcast(nil, 50004, &info.S2C_50004{Id: uint32(neww)})
|
|
|
|
|
|
ret.Weather = neww
|
|
|
|
|
|
ret.getwerboss()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
2025-12-13 18:35:17 +08:00
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-12-10 11:59:32 +08:00
|
|
|
|
planetmap.Store(id, ret)
|
|
|
|
|
|
return ret
|
2025-08-16 03:36:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-23 14:59:15 +00:00
|
|
|
|
var planetmap = csmap.New[uint32, *Space]()
|