feat(socket): 统一使用 glog.Info 替代 glog.Infof

将 ServerEvent.go 中的 glog.Infof 更改为 glog.Info,以统一日志输出方式并减少格式化开销。

feat(controller): 优化宠物经验设置逻辑与错误码返回

在 SetPetExp 方法中提前返回结果,并修正最终返回的错误码为 ErrSystemError。同时规范化注释格式。

feat(space): 支持天气地图判断与动态天气 BOSS 刷新

引入 lo 包用于查找
This commit is contained in:
2025-12-13 18:35:17 +08:00
parent f638113c1a
commit 2ab7f59667
7 changed files with 24 additions and 14 deletions

View File

@@ -77,7 +77,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
return
}
func (s *Server) OnTick() (delay time.Duration, action gnet.Action) {
glog.Infof(context.Background(), gtime.Now().ISO8601(), "链接数", atomic.LoadInt64(&s.connected))
glog.Info(context.Background(), gtime.Now().ISO8601(), "链接数", atomic.LoadInt64(&s.connected))
if s.quit && atomic.LoadInt64(&s.connected) == 0 {
//执行正常退出逻辑
os.Exit(0)

View File

@@ -230,14 +230,17 @@ func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player)
if ok && onpet.Level < 100 {
defer c.AddPetExp(onpet, data.Exp)
return &pet.PetSetExpOutboundInfo{
Exp: c.Info.ExpPool,
}, 0
}
return &pet.PetSetExpOutboundInfo{
Exp: c.Info.ExpPool,
}, 0
}, errorcode.ErrorCodes.ErrSystemError
}
//精灵图鉴
// 精灵图鉴
func (h Controller) PetBargeList(data *pet.PetBargeListInboundInfo, c *player.Player) (result *pet.PetBargeListOutboundInfo, err errorcode.ErrorCode) {
return &pet.PetBargeListOutboundInfo{

View File

@@ -22,7 +22,7 @@ func (s *Space) getfixboss(mapid uint32) {
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)
println(s.Name, "pos", s.MapBossInfo.Pos, "hp", s.MapBossInfo.Hp)
var t info.MapBossSInfo
t.INFO = append(t.INFO, s.MapBossInfo)

View File

@@ -2,7 +2,6 @@ package space
import (
"blazing/logic/service/space/info"
"sync/atomic"
"time"
"github.com/gogf/gf/v2/util/grand"
@@ -15,23 +14,22 @@ func (s *Space) getwerboss() {
case 32:
atomic.StoreUint32(&s.CanWeather, 1)
s.MapBossInfo = info.MapBossInfo{
Id: 70,
}
var t info.MapBossSInfo
s.MapBossInfo.Id = 70
if s.Weather == 1 {
s.MapBossInfo.Id = 70
s.MapBossInfo.Pos = 0
} else {
s.MapBossInfo.Id = 0
s.MapBossInfo.Pos = 200
}
t.INFO = append(t.INFO, s.MapBossInfo)
println("天气变化地图", s.Name, "pos", s.MapBossInfo.Pos, "wer", s.Weather)
s.Broadcast(nil, 2021, &t)
}

View File

@@ -9,6 +9,7 @@ import (
"blazing/logic/service/space/info"
csmap "github.com/mhmtszr/concurrent-swiss-map"
"github.com/samber/lo"
"github.com/tnnmigga/enum"
)
@@ -19,6 +20,9 @@ var WeatherStatus = enum.New[struct {
Snow uint32 `enum:"2"` // 下雪
}]()
// 定义天气地图
var wermap = []uint32{32}
// Space 针对Player的并发安全map键为uint32类型
type Space struct {
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map键为玩家ID
@@ -107,9 +111,14 @@ func GetSpace(id uint32) *Space {
}
}
cool.Cron.CustomFunc(ret, func() {
})
if _, ok := lo.Find(wermap, func(mapID uint32) bool { return mapID == ret.ID }); ok {
ret.CanWeather = 1
cool.Cron.CustomFunc(ret, func() {
})
}
planetmap.Store(id, ret)
return ret
}

View File

@@ -84,11 +84,11 @@ type MoreUserInfoOutboundInfo struct {
// PetAllNum 所有精灵数量
// 对应 Java 注解: @FieldDescription("所有精灵数量") @UInt
PetAllNum uint32 `codec:"true"`
AllPetNumber uint32 `codec:"true"`
// PetMaxLev 精灵最大等级
// 对应 Java 注解: @FieldDescription("精灵最大等级") @UInt
PetMaxLev uint32 `codec:"true"`
PetMaxLevel uint32 `codec:"true"`
// BossAchievement spt boos成就 20字节 以任务状态完成 3为击败该boss, 目前spt只有12个, 剩下的长度以3填充
// 对应 Java 注解: @FieldDescription(...) @ArraySerialize(value = ArraySerializeType.FIXED_LENGTH, fixedLength = 20) @Builder.Default