fix(space): 修复地图ID判断逻辑并优化空间初始化流程

移除未使用的地图ID字段,调整GetSpace函数中关于玩家地图的判断条件,
确保能正确加载星球配置并初始化Space实例。同时清理冗余代码,
提升逻辑可读性与执行效率。
This commit is contained in:
2025-10-10 23:16:45 +08:00
parent a1f6ce956e
commit 646eeeaa2b
2 changed files with 11 additions and 23 deletions

Binary file not shown.

View File

@@ -11,8 +11,8 @@ import (
type Space struct {
User utils.ConcurrentMap[uint32, common.PlayerI] // 存储玩家数据的map键为玩家ID
CanRefresh bool //是否能够刷怪
ID uint32 // 地图ID
Name string //地图名称
//ID uint32 // 地图ID
Name string //地图名称
// DefaultPos model.Pos //默认位置DefaultPos
//Positions map[uint32]model.Pos //从上一个地图跳转后默认位置 无任何写操作
@@ -47,34 +47,22 @@ func GetSpace(id uint32) *Space {
if ok {
return planet
}
t := NewSpace()
if id > 10000 { //说明是玩家地图GetSpace
if id < 10000 { //说明是玩家地图GetSpace
t := NewSpace()
planetmap.Store(id, t)
return t
}
//如果不ok,说明星球未创建,那就新建星球
for _, v := range xmlres.MapConfig.Maps {
if v.ID == int(id) { //找到这个地图
t := NewSpace()
for _, v := range xmlres.MapConfig.Maps {
if v.ID == int(id) { //找到这个地图
t := NewSpace()
//t.DefaultPos = model.Pos{X: uint32(v.X), Y: uint32(v.Y)}
t.ID = uint32(v.ID)
t.Name = v.Name
// t.Positions = make(map[uint32]model.Pos)
// for _, v := range v.Entries.Entries { //添加地图入口
// t.Positions[uint32(v.FromMap)] = model.Pos{X: uint32(v.PosX), Y: uint32(v.PosY)}
t.Name = v.Name
// }
planetmap.Store(id, t)
return t
}
}
}
return nil
planetmap.Store(id, t)
return t
}
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据