Files
bl/logic/service/space/in_out.go
昔念 f6a305de77 ```
feat(fight): 添加 BOSS 战斗逻辑与地图交互功能

- 在 fight_boss.go 中增加对 BOSS 血量是否为 0 的判断,避免无效赋值
- 在 map.go 中移除旧的测试代码,并将 Canmon 状态设置移至 MapList 方法中
- 新增 Attack_Boss 接口方法用于处理玩家攻击 BOSS 请求
- 修改 MapBossInfo 结构体字段类型
2025-12-09 14:52:55 +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) gettimeboss(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)
}