Files
bl/logic/service/space/in_out.go
昔念 1ea4b756f6 ```
feat(service): 更新地图与战斗信息服务结构及逻辑

- 移除 MapLeave 中对 player.Canmon 的重复设置
- 在 MapList 中增加对 TimeBoss 状态的处理并
2025-12-09 16:52:53 +08:00

176 lines
3.4 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/cool"
"blazing/logic/service/common"
"blazing/logic/service/maps/info"
maps "blazing/logic/service/maps/info"
"sync/atomic"
"time"
"github.com/gogf/gf/v2/util/grand"
"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)
_, ok := maphot[s.Super]
if ok {
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() []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 (s *Space) getfixboss(mapid uint32) {
var t info.MapBossSInfo
t.INFO = append(t.INFO, s.MapBossInfo)
switch mapid {
case 12:
s.MapBossInfo = info.MapBossInfo{
Id: 47,
Hp: 10,
}
cool.Cron.ScheduleFunc(10*time.Second, func() {
s.MapBossInfo.Pos = (grand.Intn(4) + 1 + s.MapBossInfo.Pos) % 5
println("pos", s.MapBossInfo.Pos, "hp", s.MapBossInfo.Hp)
t.INFO[0] = s.MapBossInfo
s.Broadcast(nil, 2021, &t)
})
cool.Cron.ScheduleFunc(300*time.Second, func() {
atomic.StoreInt32(&s.MapBossInfo.Hp, 10)
})
case 32:
s.MapBossInfo = info.MapBossInfo{
Id: 70,
}
cool.Cron.CustomFunc(s, func() {
r := grand.Intn(3)
s.Broadcast(nil, 50004, &info.S2C_50004{Id: uint32(r)})
if r == 1 {
s.MapBossInfo.Id = 70
t.INFO[0] = s.MapBossInfo
s.Broadcast(nil, 2021, &t)
} else {
s.MapBossInfo.Id = 0
t.INFO[0] = s.MapBossInfo
s.Broadcast(nil, 2021, &t)
}
})
case 108:
s.MapBossInfo = info.MapBossInfo{
Id: 219,
}
cool.Cron.ScheduleFunc(10*time.Second, func() {
s.MapBossInfo.Pos = (grand.Intn(6) + 1 + s.MapBossInfo.Pos) % 6
t.INFO[0] = s.MapBossInfo
s.Broadcast(nil, 2021, &t)
})
default:
cool.Cron.ScheduleFunc(10*time.Second, func() {
s.Broadcast(nil, 50004, &info.S2C_50004{Id: uint32(0)})
})
}
}
type leiyi struct {
}
func (t *Space) Next(time.Time) time.Time {
return time.Now().Add(time.Duration(grand.N(6, 30)) * time.Second)
}