feat(fight): 优化擂台战斗逻辑与状态管理 - 修改了擂台主人设置逻辑,引入 `Set` 方法统一处理玩家信息更新 - 增加对擂主是否可战斗的判断,防止无效挑战 - 调整连胜计算和广播机制,确保数据一致性 - 修复擂台挑战失败时的状态回滚问题 - 引入错误码替代硬编码返回值,提高代码可读性与维护性 - 统一访问擂台玩家的方式,移除冗余字段
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package space
|
||
|
||
import (
|
||
"blazing/common/data/xmlres"
|
||
"blazing/common/utils"
|
||
|
||
"blazing/logic/service/common"
|
||
maps "blazing/logic/service/maps/info"
|
||
|
||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||
)
|
||
|
||
// Space 针对Player的并发安全map,键为uint32类型
|
||
type Space struct {
|
||
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
||
UserInfo *csmap.CsMap[uint32, maps.OutInfo]
|
||
CanRefresh bool //是否能够刷怪
|
||
Super uint32
|
||
//SuperValue *int32
|
||
//ID uint32 // 地图ID
|
||
Name string //地图名称
|
||
Owner ARENA
|
||
}
|
||
|
||
// NewSyncMap 创建一个新的玩家同步map
|
||
func NewSpace() *Space {
|
||
|
||
return &Space{
|
||
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[uint32, common.PlayerI](func(key uint32) uint64 {
|
||
|
||
return uint64(key)
|
||
}),
|
||
|
||
// 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),
|
||
csmap.WithCustomHasher[uint32, maps.OutInfo](func(key uint32) uint64 {
|
||
|
||
return uint64(key)
|
||
}),
|
||
// // 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 GetSpace(id uint32) *Space {
|
||
|
||
planet, ok := planetmap.Load(id)
|
||
if ok {
|
||
return planet
|
||
}
|
||
t := NewSpace()
|
||
|
||
if id < 10000 { //说明是玩家地图GetSpace
|
||
|
||
for _, v := range xmlres.MapConfig.Maps {
|
||
if v.ID == int(id) { //找到这个地图
|
||
|
||
t.Super = uint32(v.Super)
|
||
if t.Super == 0 {
|
||
t.Super = uint32(v.ID)
|
||
}
|
||
|
||
_, ok := maphot[t.Super]
|
||
if !ok {
|
||
var t1 int32
|
||
maphot[t.Super] = &t1
|
||
}
|
||
|
||
t.Name = v.Name
|
||
break
|
||
}
|
||
|
||
}
|
||
}
|
||
planetmap.Store(id, t)
|
||
return t
|
||
}
|
||
|
||
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据
|