Files
bl/logic/service/space/space.go
昔念 105c6f5a23 ```
fix(fight): 修复战斗逻辑中的一些潜在问题

- 在 `fight_leitai.go` 中增加玩家是否可以战斗的判断,避免非法挑战
- 注释掉部分冗余的日志打印与广播调用,并调整了擂台状态更新逻辑
- 修正 `effect_62.go` 中镇魂歌效果持续时间的处理方式,引入独立计数器 `duy`
- 优化随机精灵生成逻辑,确保 CatchTime 正确设置
- 增加对数据库操作错误的 panic 处理,提高代码健壮性
- 调整部分结构体指针传递,统一返回结构体指针以避免拷贝问题
- 移除未使用的导入包和调试日志,清理无用代码
```
2025-11-20 21:37:37 +08:00

99 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
ARENA_Player common.PlayerI
}
// 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 := NewSpace()
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))
}
t.Name = v.Name
}
}
}
planetmap.Store(id, t)
return t
}
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据