Files
bl/logic/service/space/in_out.go
昔念 a6c11e0837 ```
fix(service): 修复玩家离开地图时的逻辑判断

移除重复的 MapID 检查逻辑,避免在 controller 和 service 中
同时进行相同判断。原 controller 中的 MapID 重置逻辑已被注释,
确保 leave map 流程的一致性和正确性。
```
2025-11-16 12:23:30 +08:00

94 lines
1.9 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/logic/service/common"
"blazing/logic/service/maps/info"
maps "blazing/logic/service/maps/info"
"sync/atomic"
"github.com/jinzhu/copier"
"golang.org/x/time/rate"
)
func (s *Space) LeaveMap(c common.PlayerI) {
if c == nil {
return
}
if c.GetInfo() == nil {
return
}
s.UP_ARENA(c, 0) //退出擂台
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
if k != c.GetInfo().UserID {
v.SendLeaveMapInfo(info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
}
return false
})
s.User.Delete(c.GetInfo().UserID)
s.UserInfo.Delete(c.GetInfo().UserID)
if s.SuperValue != nil {
atomic.AddInt32(s.SuperValue, -1)
}
}
func (s *Space) EnterMap(c common.PlayerI) {
out := info.NewOutInfo()
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
if k != c.GetInfo().UserID {
v.SendEnterMapInfo(*out)
}
return false
})
s.User.Store(c.GetInfo().UserID, c)
s.UserInfo.Store(c.GetInfo().UserID, *out)
if s.SuperValue != nil {
atomic.AddInt32(s.SuperValue, 1)
}
}
func (s *Space) GetInfo() []maps.OutInfo {
ret := make([]maps.OutInfo, 0)
s.UserInfo.Range(func(k uint32, v maps.OutInfo) (stop bool) {
ret = append(ret, v)
return len(ret) > 30
})
return ret
}
var limiter = rate.NewLimiter(rate.Limit(10), 5)
func (s *Space) Walk(b maps.WalkOutInfo) {
// cool.Limiter.Take()
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
if !limiter.Allow() {
return
}
s.User.Range(func(playerID uint32, player common.PlayerI) bool {
player.SendWalkMapInfo(b)
return false
})
}
func LastFourElements[T any](s []T) []T {
n := len(s)
if n <= 30 {
// 切片长度小于等于4时返回整个切片
return s
}
// 切片长度大于4时返回最后4个元素从n-4索引到末尾
return s[n-30:]
}