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进行大小
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
package space
|
||
|
||
import (
|
||
"blazing/logic/service/common"
|
||
|
||
"blazing/logic/service/space/info"
|
||
|
||
"sync/atomic"
|
||
|
||
"github.com/jinzhu/copier"
|
||
"github.com/panjf2000/ants/v2"
|
||
"golang.org/x/time/rate"
|
||
)
|
||
|
||
var mappool, _ = ants.NewPool(-1)
|
||
|
||
// 向其他人广播,不含自己
|
||
// 广播是c为空就不特判,发给全体成员广播
|
||
func (s *Space) Broadcast(c common.PlayerI, cmd uint32, data any) {
|
||
mappool.Submit(func() {
|
||
|
||
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
|
||
if c != nil {
|
||
if k != c.GetInfo().UserID {
|
||
v.SendPackCmd(cmd, data)
|
||
|
||
}
|
||
} else {
|
||
v.SendPackCmd(cmd, data)
|
||
}
|
||
|
||
return false
|
||
})
|
||
})
|
||
|
||
}
|
||
|
||
func (s *Space) LeaveMap(c common.PlayerI) {
|
||
|
||
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
|
||
|
||
s.Owner.Reset()
|
||
|
||
s.Broadcast(c, 2419, &s.Owner)
|
||
|
||
}
|
||
s.Broadcast(c, 2002, &info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
|
||
|
||
s.User.Delete(c.GetInfo().UserID)
|
||
s.UserInfo.Delete(c.GetInfo().UserID)
|
||
current, ok := maphot[s.Super]
|
||
if ok && *current > 0 {
|
||
atomic.AddInt32(maphot[s.Super], -1)
|
||
}
|
||
|
||
}
|
||
|
||
func (s *Space) EnterMap(c common.PlayerI) {
|
||
|
||
out := info.NewOutInfo()
|
||
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
|
||
|
||
s.User.Store(c.GetInfo().UserID, c)
|
||
s.UserInfo.Store(c.GetInfo().UserID, *out)
|
||
s.Broadcast(c, 2001, out)
|
||
_, ok := maphot[s.Super]
|
||
if ok {
|
||
atomic.AddInt32(maphot[s.Super], 1)
|
||
}
|
||
|
||
}
|
||
func (s *Space) GetInfo(c common.PlayerI) []info.SimpleInfo {
|
||
|
||
if atomic.LoadUint32(&s.TimeBoss.Flag) == 1 {
|
||
defer c.SendPackCmd(2022, &s.TimeBoss)
|
||
}
|
||
if s.MapBossInfo.Pos != 200 {
|
||
var t info.MapBossSInfo
|
||
t.INFO = append(t.INFO, s.MapBossInfo)
|
||
s.Broadcast(nil, 2021, &t)
|
||
|
||
}
|
||
defer c.SendPackCmd(50004, &info.S2C_50004{Id: uint32(s.Weather)}) //获取天气
|
||
ret := make([]info.SimpleInfo, 0)
|
||
s.UserInfo.Range(func(k uint32, v info.SimpleInfo) (stop bool) {
|
||
ret = append(ret, v)
|
||
return len(ret) > 30
|
||
})
|
||
|
||
return ret
|
||
|
||
}
|
||
|
||
var limiter = rate.NewLimiter(rate.Limit(10), 5)
|
||
|
||
func (s *Space) Walk(c common.PlayerI, info *info.WalkOutInfo) {
|
||
// cool.Limiter.Take()
|
||
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
|
||
if !limiter.Allow() {
|
||
return
|
||
}
|
||
|
||
s.Broadcast(c, 2101, info)
|
||
|
||
}
|