120 lines
2.4 KiB
Go
120 lines
2.4 KiB
Go
package space
|
||
|
||
import (
|
||
"blazing/common/data/xmlres"
|
||
"blazing/common/utils"
|
||
"blazing/cool"
|
||
"blazing/modules/config/service"
|
||
|
||
"blazing/logic/service/common"
|
||
"blazing/logic/service/space/info"
|
||
|
||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||
"github.com/tnnmigga/enum"
|
||
)
|
||
|
||
// 定义天气状态枚举实例
|
||
var WeatherStatus = enum.New[struct {
|
||
Normal uint32 `enum:"0"` // 正常
|
||
Rain uint32 `enum:"1"` // 下雨
|
||
Snow uint32 `enum:"2"` // 下雪
|
||
}]()
|
||
|
||
// Space 针对Player的并发安全map,键为uint32类型
|
||
type Space struct {
|
||
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
||
UserInfo *csmap.CsMap[uint32, info.SimpleInfo]
|
||
CanRefresh bool //是否能够刷怪
|
||
Super uint32
|
||
//SuperValue *int32
|
||
ID uint32 // 地图ID
|
||
Name string //地图名称
|
||
Owner ARENA
|
||
info.MapBossInfo
|
||
TimeBoss info.S2C_2022
|
||
Weather uint32
|
||
IsTime bool
|
||
//CanWeather uint32
|
||
}
|
||
|
||
// NewSyncMap 创建一个新的玩家同步map
|
||
func NewSpace() *Space {
|
||
|
||
ret := &Space{
|
||
User: csmap.New[uint32, common.PlayerI](),
|
||
UserInfo: csmap.New[uint32, info.SimpleInfo](),
|
||
}
|
||
|
||
return ret
|
||
}
|
||
|
||
// 获取星球
|
||
func GetSpace(id uint32) *Space {
|
||
|
||
planet, ok := planetmap.Load(id)
|
||
if ok {
|
||
return planet
|
||
}
|
||
ret := NewSpace()
|
||
|
||
if id < 10000 { //说明是玩家地图GetSpace
|
||
|
||
for _, v := range xmlres.MapConfig.Maps {
|
||
if v.ID == int(id) { //找到这个地图
|
||
|
||
ret.Super = uint32(v.Super)
|
||
if ret.Super == 0 {
|
||
ret.Super = uint32(v.ID)
|
||
}
|
||
ret.ID = uint32(v.ID)
|
||
ret.getfixboss(uint32(v.ID))
|
||
//t.gettimeboss(uint32(v.ID))
|
||
_, ok := maphot[ret.Super]
|
||
if !ok {
|
||
var t1 int32
|
||
maphot[ret.Super] = &t1
|
||
}
|
||
|
||
ret.Name = v.Name
|
||
break
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
r := service.NewMapService().GetData(ret.ID)
|
||
if r != nil {
|
||
if r.IsTimeSpace != 0 {
|
||
ret.IsTime = true
|
||
}
|
||
if len(r.WeatherType) > 1 {
|
||
// ret.CanWeather = 1
|
||
cool.Cron.CustomFunc(ret, func() {
|
||
//if ret.CanWeather == 1 {
|
||
var neww uint32 = 0
|
||
|
||
if len(r.WeatherType) == 2 {
|
||
neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{9, 1})
|
||
} else {
|
||
neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{8, 1, 1})
|
||
}
|
||
|
||
if neww != ret.Weather {
|
||
ret.Broadcast(nil, 50004, &info.S2C_50004{Id: uint32(neww)})
|
||
ret.Weather = neww
|
||
ret.getwerboss()
|
||
}
|
||
|
||
//}
|
||
|
||
})
|
||
}
|
||
|
||
}
|
||
|
||
planetmap.Store(id, ret)
|
||
return ret
|
||
}
|
||
|
||
var planetmap = csmap.New[uint32, *Space]()
|