feat(pet): 实现宠物展示功能和稀有宠物塔配置 - 添加PetDisplay字段到Player结构体,用于管理宠物展示状态 - 实现PlayerShowPet方法,支持宠物展示逻辑,包括设置展示标识、 检查宠物存在性并返回相应错误码 - 在Space中添加RefreshUserInfo方法,用于刷新用户信息并应用 宠物展示信息到SimpleInfo - 扩展SimpleInfo结构体,添加PetRide字段用于宠物骑乘标识
112 lines
2.3 KiB
Go
112 lines
2.3 KiB
Go
package space
|
|
|
|
import (
|
|
"blazing/logic/service/common"
|
|
|
|
"blazing/logic/service/space/info"
|
|
|
|
"sync/atomic"
|
|
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
type petDisplayInfoProvider interface {
|
|
ApplyPetDisplayInfo(*info.SimpleInfo)
|
|
}
|
|
|
|
// 向其他人广播,不含自己
|
|
// 广播是c 为空就不特判,发给全体成员广播
|
|
func (s *Space) Broadcast(c common.PlayerI, cmd uint32, data any) {
|
|
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) {
|
|
info := &info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID}
|
|
c.SendPackCmd(2002, info)
|
|
s.User.Delete(c.GetInfo().UserID)
|
|
s.UserInfo.Delete(c.GetInfo().UserID)
|
|
s.Broadcast(c, 2002, info)
|
|
|
|
current, ok := maphot[s.Super]
|
|
if ok {
|
|
current.GetCount(-1)
|
|
|
|
}
|
|
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
|
|
|
|
s.Owner.Reset()
|
|
|
|
s.Broadcast(c, 2419, &s.Owner)
|
|
|
|
}
|
|
}
|
|
|
|
func (s *Space) EnterMap(c common.PlayerI) {
|
|
|
|
out := info.NewOutInfo()
|
|
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
|
|
if provider, ok := c.(petDisplayInfoProvider); ok {
|
|
provider.ApplyPetDisplayInfo(out)
|
|
}
|
|
c.SendPackCmd(2001, out)
|
|
|
|
s.Broadcast(c, 2001, out)
|
|
s.User.Store(c.GetInfo().UserID, c)
|
|
s.UserInfo.Store(c.GetInfo().UserID, *out)
|
|
curmaps, ok := maphot[s.Super]
|
|
if ok {
|
|
curmaps.GetCount(1)
|
|
//atomic.AddInt32(maphot[s.Super], 1)
|
|
}
|
|
|
|
}
|
|
|
|
func (s *Space) RefreshUserInfo(c common.PlayerI) {
|
|
current, ok := s.UserInfo.Load(c.GetInfo().UserID)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
if provider, ok := c.(petDisplayInfoProvider); ok {
|
|
provider.ApplyPetDisplayInfo(¤t)
|
|
s.UserInfo.Store(c.GetInfo().UserID, current)
|
|
}
|
|
}
|
|
|
|
func (s *Space) GetInfo(c common.PlayerI) []info.SimpleInfo {
|
|
|
|
ret := make([]info.SimpleInfo, 0)
|
|
s.UserInfo.Range(func(k uint32, v info.SimpleInfo) (stop bool) {
|
|
ret = append(ret, v)
|
|
return len(ret) > 50
|
|
})
|
|
|
|
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)
|
|
|
|
}
|