2025-08-15 22:44:28 +08:00
|
|
|
|
package space
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-30 00:36:08 +08:00
|
|
|
|
"blazing/common/data/xmlres"
|
2025-08-16 03:36:13 +00:00
|
|
|
|
"blazing/common/utils"
|
2025-11-15 22:17:43 +00:00
|
|
|
|
|
2025-09-14 01:35:16 +08:00
|
|
|
|
"blazing/logic/service/common"
|
2025-11-15 19:11:23 +08:00
|
|
|
|
"blazing/logic/service/fight/info"
|
2025-11-16 11:56:57 +08:00
|
|
|
|
maps "blazing/logic/service/maps/info"
|
2025-11-15 15:22:58 +08:00
|
|
|
|
|
|
|
|
|
|
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
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
|
2025-11-16 11:56:57 +08:00
|
|
|
|
UserInfo *csmap.CsMap[uint32, maps.OutInfo]
|
|
|
|
|
|
CanRefresh bool //是否能够刷怪
|
|
|
|
|
|
Super uint32
|
|
|
|
|
|
SuperValue *int32
|
2025-10-10 23:16:45 +08:00
|
|
|
|
//ID uint32 // 地图ID
|
2025-11-15 19:11:23 +08:00
|
|
|
|
Name string //地图名称
|
|
|
|
|
|
ARENA info.S2C_ARENA_GET_INFO
|
|
|
|
|
|
ARENA_Player common.PlayerI
|
2025-10-10 20:46:16 +08:00
|
|
|
|
// DefaultPos model.Pos //默认位置DefaultPos
|
2025-10-10 04:31:52 +00:00
|
|
|
|
|
|
|
|
|
|
//Positions map[uint32]model.Pos //从上一个地图跳转后默认位置 无任何写操作
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-15 19:11:23 +08:00
|
|
|
|
func (s *Space) Can_ARENA(c common.PlayerI) common.PlayerI {
|
|
|
|
|
|
|
|
|
|
|
|
if s.ARENA.Flag != 3 {
|
|
|
|
|
|
s.ARENA.Flag = 3
|
|
|
|
|
|
s.ARENA.ChallengerID = c.GetInfo().UserID
|
|
|
|
|
|
return s.ARENA_Player
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// flag 0 取消 1为加入 3 为挑战
|
|
|
|
|
|
func (s *Space) UP_ARENA(c common.PlayerI, FLAG uint32) {
|
|
|
|
|
|
|
|
|
|
|
|
switch FLAG {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
if s.ARENA.Id != c.GetInfo().UserID { //说明不是自己退出
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
s.ARENA = info.S2C_ARENA_GET_INFO{}
|
2025-11-15 14:23:52 +00:00
|
|
|
|
s.ARENA_Player = nil
|
2025-11-15 19:11:23 +08:00
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
if s.ARENA.Id != 0 { //说明已经有人了
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
s.ARENA.Flag = 1
|
|
|
|
|
|
s.ARENA.Id = c.GetInfo().UserID //添加用户ID
|
|
|
|
|
|
s.ARENA.Nick = c.GetInfo().Nick
|
|
|
|
|
|
s.ARENA_Player = c //添加用户
|
|
|
|
|
|
case 3: //胜利替换
|
|
|
|
|
|
if s.ARENA.Flag != 3 { //说明没进入挑战
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if s.ARENA.Id != c.GetInfo().UserID && c.GetInfo().UserID != s.ARENA.ChallengerID { //说明已经有人了
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.GetInfo().UserID == s.ARENA.Id {
|
|
|
|
|
|
s.ARENA.HostWins += 1 //连胜+1
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
s.ARENA.Flag = 1
|
|
|
|
|
|
s.ARENA.Id = c.GetInfo().UserID //添加用户ID
|
|
|
|
|
|
s.ARENA.Nick = c.GetInfo().Nick
|
|
|
|
|
|
s.ARENA_Player = c //添加用户
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s.User.Range(func(playerID uint32, p common.PlayerI) bool {
|
|
|
|
|
|
|
|
|
|
|
|
p.Send_ARENA_GET_INFO(s.ARENA)
|
|
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-15 22:44:28 +08:00
|
|
|
|
// NewSyncMap 创建一个新的玩家同步map
|
|
|
|
|
|
func NewSpace() *Space {
|
|
|
|
|
|
return &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.
|
|
|
|
|
|
// csmap.WithCustomHasher[string, int](func(key string) uint64 {
|
|
|
|
|
|
// hash := fnv.New64a()
|
|
|
|
|
|
// hash.Write([]byte(key))
|
|
|
|
|
|
// return hash.Sum64()
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
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),
|
|
|
|
|
|
),
|
|
|
|
|
|
UserInfo: csmap.New[uint32, maps.OutInfo](
|
|
|
|
|
|
// set the number of map shards. the default value is 32.
|
|
|
|
|
|
csmap.WithShardCount[uint32, maps.OutInfo](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()
|
|
|
|
|
|
// }),
|
|
|
|
|
|
|
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-08-16 03:36:13 +00:00
|
|
|
|
// 获取星球
|
|
|
|
|
|
func GetSpace(id uint32) *Space {
|
|
|
|
|
|
|
|
|
|
|
|
planet, ok := planetmap.Load(id)
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
return planet
|
|
|
|
|
|
}
|
2025-10-10 23:16:45 +08:00
|
|
|
|
t := 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) { //找到这个地图
|
|
|
|
|
|
t := NewSpace()
|
2025-11-16 11:56:57 +08:00
|
|
|
|
t.Super = uint32(v.Super)
|
|
|
|
|
|
ok := maphot.Has(t.Super)
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
var tt int32 = 0
|
|
|
|
|
|
maphot.Store(uint32(v.Super), &tt)
|
|
|
|
|
|
t.SuperValue = &tt //创建一个
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
t.SuperValue, _ = maphot.Load(uint32(v.Super))
|
|
|
|
|
|
}
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
2025-10-10 23:16:45 +08:00
|
|
|
|
t.Name = v.Name
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
2025-10-10 23:16:45 +08:00
|
|
|
|
}
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-10 23:16:45 +08:00
|
|
|
|
planetmap.Store(id, t)
|
|
|
|
|
|
return t
|
2025-08-16 03:36:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据
|