"refactor(socket): 添加玩家断开连接时的登录状态标记并优化刷怪逻辑"

This commit is contained in:
1
2025-08-25 18:10:45 +00:00
parent cd229c1ca7
commit be5a0e144f
3 changed files with 38 additions and 367 deletions

View File

@@ -42,7 +42,7 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps
case <-ticker.C:
// 刷新当前地图的怪物
if !c.IsFighting && c.MapId != 0 {
spawnMonsters(currentMap, c)
spawnMonsters(c)
}
}
@@ -85,28 +85,58 @@ func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *entity.Play
}
// 刷怪具体实现
func spawnMonsters(mapID int, c *entity.Player) {
func spawnMonsters(c *entity.Player) {
// 获取当前地图的怪物配置
if mservice.NewMonsterService().GetId(c.MapId) == 0 {
if c == nil || mservice.NewMonsterService().GetId(c.MapId) == 0 { //用户离线
return
}
if !c.IsLogin {
defer func() {
if c.StopChan != nil {
close(c.StopChan)
c.StopChan = nil
}
}()
}
// 创建数据包
tt := handler.NewTomeeHeader(2004, c.UserID)
t1 := genMonster(c.MapId)
c.SendPack(tt.Pack(&t1))
}
func genMonster(id uint32) maps.OgreInfo {
// 设置怪物信息
t1 := maps.OgreInfo{}
//copy(t1.Data[:], monsterConfig) // 使用地图对应的怪物配置
var localMenu = make([]int, 0)
for i := 7; i <= 448; i++ {
if bitsCount(i) == 3 {
localMenu = append(localMenu, i)
}
}
for i := 0; i < 3; i++ {
ttt := maps.OgrePetInfo{}
ttt.Id = mservice.NewMonsterService().GetId(c.MapId)
ttt.Id = mservice.NewMonsterService().GetId(id)
ttt.Shiny = uint32(i + 1)
//t1.Data[i] = mservice.NewMonsterService().GetId(c.MapId)
t1.Data[i] = ttt
}
// 发送数据包
c.SendPack(tt.Pack(&t1))
return t1
}
// 计算整数的二进制1的个数对应Java的Integer.bitCount
func bitsCount(n int) int {
count := 0
for n > 0 {
count += n & 1
n >>= 1
}
return count
}