整理场景协议组

This commit is contained in:
flswld
2023-04-02 19:32:31 +08:00
parent 29737319a3
commit d1e0d7bf5b
18 changed files with 391 additions and 365 deletions

View File

@@ -4,6 +4,7 @@ import (
"math"
"time"
"hk4e/common/constant"
"hk4e/gate/kcp"
"hk4e/gs/model"
"hk4e/pkg/logger"
@@ -144,3 +145,122 @@ func (g *Game) ServerAppidBindNotify(userId uint32, anticheatAppId string, joinH
player.SceneLoadState = model.SceneNone
g.SendMsg(cmd.PlayerEnterSceneNotify, userId, player.ClientSeq, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_SELF))
}
// WorldPlayerRTTNotify 世界里所有玩家的网络延迟广播
func (g *Game) WorldPlayerRTTNotify(world *World) {
worldPlayerRTTNotify := &proto.WorldPlayerRTTNotify{
PlayerRttList: make([]*proto.PlayerRTTInfo, 0),
}
for _, worldPlayer := range world.GetAllPlayer() {
playerRTTInfo := &proto.PlayerRTTInfo{Uid: worldPlayer.PlayerID, Rtt: worldPlayer.ClientRTT}
worldPlayerRTTNotify.PlayerRttList = append(worldPlayerRTTNotify.PlayerRttList, playerRTTInfo)
}
GAME.SendToWorldA(world, cmd.WorldPlayerRTTNotify, 0, worldPlayerRTTNotify)
}
// WorldPlayerLocationNotify 多人世界其他玩家的坐标位置广播
func (g *Game) WorldPlayerLocationNotify(world *World) {
worldPlayerLocationNotify := &proto.WorldPlayerLocationNotify{
PlayerWorldLocList: make([]*proto.PlayerWorldLocationInfo, 0),
}
for _, worldPlayer := range world.GetAllPlayer() {
playerWorldLocationInfo := &proto.PlayerWorldLocationInfo{
SceneId: worldPlayer.SceneId,
PlayerLoc: &proto.PlayerLocationInfo{
Uid: worldPlayer.PlayerID,
Pos: &proto.Vector{
X: float32(worldPlayer.Pos.X),
Y: float32(worldPlayer.Pos.Y),
Z: float32(worldPlayer.Pos.Z),
},
Rot: &proto.Vector{
X: float32(worldPlayer.Rot.X),
Y: float32(worldPlayer.Rot.Y),
Z: float32(worldPlayer.Rot.Z),
},
},
}
worldPlayerLocationNotify.PlayerWorldLocList = append(worldPlayerLocationNotify.PlayerWorldLocList, playerWorldLocationInfo)
}
GAME.SendToWorldA(world, cmd.WorldPlayerLocationNotify, 0, worldPlayerLocationNotify)
}
func (g *Game) ScenePlayerLocationNotify(world *World) {
for _, scene := range world.GetAllScene() {
scenePlayerLocationNotify := &proto.ScenePlayerLocationNotify{
SceneId: scene.id,
PlayerLocList: make([]*proto.PlayerLocationInfo, 0),
VehicleLocList: make([]*proto.VehicleLocationInfo, 0),
}
for _, scenePlayer := range scene.GetAllPlayer() {
// 玩家位置
playerLocationInfo := &proto.PlayerLocationInfo{
Uid: scenePlayer.PlayerID,
Pos: &proto.Vector{
X: float32(scenePlayer.Pos.X),
Y: float32(scenePlayer.Pos.Y),
Z: float32(scenePlayer.Pos.Z),
},
Rot: &proto.Vector{
X: float32(scenePlayer.Rot.X),
Y: float32(scenePlayer.Rot.Y),
Z: float32(scenePlayer.Rot.Z),
},
}
scenePlayerLocationNotify.PlayerLocList = append(scenePlayerLocationNotify.PlayerLocList, playerLocationInfo)
// 载具位置
for _, entityId := range scenePlayer.VehicleInfo.LastCreateEntityIdMap {
entity := scene.GetEntity(entityId)
// 确保实体类型是否为载具
if entity != nil && entity.GetEntityType() == constant.ENTITY_TYPE_GADGET && entity.gadgetEntity.gadgetVehicleEntity != nil {
vehicleLocationInfo := &proto.VehicleLocationInfo{
Rot: &proto.Vector{
X: float32(entity.rot.X),
Y: float32(entity.rot.Y),
Z: float32(entity.rot.Z),
},
EntityId: entity.id,
CurHp: entity.fightProp[constant.FIGHT_PROP_CUR_HP],
OwnerUid: entity.gadgetEntity.gadgetVehicleEntity.owner.PlayerID,
Pos: &proto.Vector{
X: float32(entity.pos.X),
Y: float32(entity.pos.Y),
Z: float32(entity.pos.Z),
},
UidList: make([]uint32, 0, len(entity.gadgetEntity.gadgetVehicleEntity.memberMap)),
GadgetId: entity.gadgetEntity.gadgetVehicleEntity.vehicleId,
MaxHp: entity.fightProp[constant.FIGHT_PROP_MAX_HP],
}
for _, p := range entity.gadgetEntity.gadgetVehicleEntity.memberMap {
vehicleLocationInfo.UidList = append(vehicleLocationInfo.UidList, p.PlayerID)
}
scenePlayerLocationNotify.VehicleLocList = append(scenePlayerLocationNotify.VehicleLocList, vehicleLocationInfo)
}
}
}
GAME.SendToWorldA(world, cmd.ScenePlayerLocationNotify, 0, scenePlayerLocationNotify)
}
}
func (g *Game) SceneTimeNotify(world *World) {
for _, scene := range world.GetAllScene() {
for _, player := range scene.GetAllPlayer() {
sceneTimeNotify := &proto.SceneTimeNotify{
SceneId: player.SceneId,
SceneTime: uint64(scene.GetSceneTime()),
}
GAME.SendMsg(cmd.SceneTimeNotify, player.PlayerID, 0, sceneTimeNotify)
}
}
}
func (g *Game) PlayerTimeNotify(world *World) {
for _, player := range world.GetAllPlayer() {
playerTimeNotify := &proto.PlayerTimeNotify{
IsPaused: player.Pause,
PlayerTime: uint64(player.TotalOnlineTime),
ServerTime: uint64(time.Now().UnixMilli()),
}
GAME.SendMsg(cmd.PlayerTimeNotify, player.PlayerID, 0, playerTimeNotify)
}
}