Files
bl/logic/service/space/space.go
昔念 08ebf849eb ```
feat(pet): 添加宠物收集功能和称号系统

- 实现了宠物收集任务状态查询功能
- 新增Collect方法处理宠物收集逻辑,包括类型验证和ID合法性检查
- 创建validTypeIDMap映射表统一管理合法的类型ID集合
- 重构任务状态判断逻辑,基于model.Completion状态进行判断

refactor(map): 统一玩家信息结构体

- 将OutInfo重命名为SimpleInfo并添加Title字段
- 更新EnterMap方法的返回类型为SimpleInfo
- 修改space包中的UserInfo映射类型为SimpleInfo

feat(task): 集成称号奖励到任务系统

- 在PlayerInfo结构体中添加Title字段
- 扩展TaskConfig模型支持称号奖励配置
- 更新用户信息服务处理用户名大小写转换

refactor(space): 优化空间服务数据结构

- 更新GetInfo方法返回SimpleInfo切片
- 调整UserInfo CsMap泛型类型参数
- 修改ListMapPlayerOutboundInfo中Player数组类型

style(login): 规范化用户名输入处理

- 登录时将用户名转换为小写进行比较
- 使用strings.EqualFold进行大小
2026-01-17 00:47:41 +08:00

143 lines
3.3 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/cool"
"blazing/logic/service/common"
"blazing/logic/service/space/info"
"github.com/gogf/gf/v2/util/grand"
csmap "github.com/mhmtszr/concurrent-swiss-map"
"github.com/samber/lo"
"github.com/tnnmigga/enum"
)
// 定义天气状态枚举实例
var WeatherStatus = enum.New[struct {
Normal uint32 `enum:"0"` // 正常
Rain uint32 `enum:"1"` // 下雨
Snow uint32 `enum:"2"` // 下雪
}]()
// 定义天气地图
var wermap = []uint32{32}
// 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
//CanWeather uint32
}
// NewSyncMap 创建一个新的玩家同步map
func NewSpace() *Space {
ret := &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, info.SimpleInfo](
// set the number of map shards. the default value is 32.
csmap.WithShardCount[uint32, info.SimpleInfo](32),
csmap.WithCustomHasher[uint32, info.SimpleInfo](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),
),
}
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
}
}
}
if _, ok := lo.Find(wermap, func(mapID uint32) bool { return mapID == ret.ID }); ok {
// ret.CanWeather = 1
cool.Cron.CustomFunc(ret, func() {
//if ret.CanWeather == 1 {
var neww uint32 = 0
if grand.Meet(1, 10) {
neww = uint32(grand.N(1, 2))
}
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 = &utils.SyncMap[uint32, *Space]{} //玩家数据