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

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

100 lines
2.0 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"
"github.com/panjf2000/ants/v2"
"golang.org/x/time/rate"
)
var mappool, _ = ants.NewPool(-1)
// 向其他人广播,不含自己
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 k != c.GetInfo().UserID {
v.SendPackCmd(cmd, data)
}
return false
})
//})
}
func (s *Space) LeaveMap(c common.PlayerI) {
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
s.ARENA_Player = nil
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)
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.Store(c.GetInfo().UserID, c)
s.UserInfo.Store(c.GetInfo().UserID, *out)
s.Broadcast(c, 2001, 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(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)
}
func LastFourElements[T any](s []T) []T {
n := len(s)
if n <= 30 {
// 切片长度小于等于4时返回整个切片
return s
}
// 切片长度大于4时返回最后4个元素从n-4索引到末尾
return s[n-30:]
}