Files
bl/logic/service/space/walk.go

77 lines
1.9 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/common/data/entity"
xml "blazing/common/data/xml/map"
"blazing/common/socket/handler"
"blazing/common/utils"
"blazing/modules/blazing/model"
)
// 获取星球
func GetPlanet(id uint32) *Space {
planet, ok := planetmap.Load(id)
if ok {
return planet
}
//如果不ok,说明星球未创建,那就新建星球
for _, v := range xml.MapConfig.Maps {
if v.ID == int(id) { //找到这个地图
t := NewSpace()
t.DefaultPos = model.Pos{X: uint32(v.X), Y: uint32(v.Y)}
t.ID = uint32(v.ID)
t.Name = v.Name
t.Positions = make(map[uint32]model.Pos)
for _, v := range v.Entries.Entries { //添加地图入口
t.Positions[uint32(v.FromMap)] = model.Pos{X: uint32(v.PosX), Y: uint32(v.PosY)}
}
planetmap.Store(id, t)
return t
}
}
return nil
}
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据
type InInfo struct {
Head handler.TomeeHeader `cmd:"2101" struc:"[0]pad"` //玩家登录
// Flag: 0为走1为飞行模式对应Java的@UInt long
Flag uint32
// Point: 直接给坐标xy
Point model.Pos `fieldDesc:"直接给坐标xy"`
// Reverse2: 暂定 占位字符2
Reverse2 string `struc:"[2]byte"`
}
func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
GetPlanet(mapid).Range(func(playerID uint32, player *entity.Player) bool {
player.SendPack(t.Head.Pack(o))
return true
})
}
// PeopleWalkOutboundInfo 对应Java的PeopleWalkOutboundInfo类实现OutboundMessage接口
type OutInfo struct {
// Flag: 0为走1为飞行模式
Flag uint32 `fieldDesc:"0为走1为飞行模式" codec:"uint"`
// UserID: 走动的人的米米号
UserID uint32 `fieldDesc:"走动的人的米米号" codec:"uint"`
// Point: 直接给坐标xy
Point model.Pos `fieldDesc:"直接给坐标xy"`
// Reserve2: 这个字段同C2S_People_Walk中的reserve2
Reserve2 string `struc:"[2]byte"`
}