调整场景相关协议组的顺序

This commit is contained in:
huangxiaolei
2022-12-08 15:21:54 +08:00
parent 7384fca483
commit b836c0f8db
9 changed files with 363 additions and 218 deletions

View File

@@ -122,6 +122,12 @@ func (t *TickManager) onTick10Second(now int64) {
sceneTimeNotify.SceneId = player.SceneId
sceneTimeNotify.SceneTime = uint64(scene.GetSceneTime())
GAME_MANAGER.SendMsg(cmd.SceneTimeNotify, player.PlayerID, player.ClientSeq, sceneTimeNotify)
// PacketPlayerTimeNotify
playerTimeNotify := new(proto.PlayerTimeNotify)
playerTimeNotify.IsPaused = player.Pause
playerTimeNotify.PlayerTime = uint64(player.TotalOnlineTime)
playerTimeNotify.ServerTime = uint64(time.Now().UnixMilli())
GAME_MANAGER.SendMsg(cmd.PlayerTimeNotify, player.PlayerID, player.ClientSeq, playerTimeNotify)
}
}
if !world.IsBigWorld() && (world.multiplayer || !world.owner.Pause) {

View File

@@ -21,7 +21,8 @@ func (g *GameManager) UnionCmdNotify(player *model.Player, payloadMsg pb.Message
// 只给附近aoi区域的玩家广播消息
surrPlayerList := make([]*model.Player, 0)
entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
//entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := world.GetSceneById(player.SceneId).GetEntityIdList()
for _, entityId := range entityIdList {
entity := scene.GetEntity(entityId)
if entity == nil {
@@ -101,7 +102,8 @@ func (g *GameManager) MassiveEntityElementOpBatchNotify(player *model.Player, pa
// 只给附近aoi区域的玩家广播消息
surrPlayerList := make([]*model.Player, 0)
entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
//entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := world.GetSceneById(player.SceneId).GetEntityIdList()
for _, entityId := range entityIdList {
entity := scene.GetEntity(entityId)
if entity == nil {
@@ -160,7 +162,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
// aoi
oldGid := world.aoiManager.GetGidByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
newGid := world.aoiManager.GetGidByPos(motionInfo.Pos.X, motionInfo.Pos.Y, motionInfo.Pos.Z)
if oldGid != newGid {
if false && oldGid != newGid {
// 跨越了格子
oldGridList := world.aoiManager.GetSurrGridListByGid(oldGid)
oldEntityIdMap := make(map[uint32]bool)
@@ -211,7 +213,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
}
}
// 发送已消失格子里的实体消失通知
g.RemoveSceneEntityNotifyToPlayer(player, delEntityIdList)
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_TYPE_REMOVE, delEntityIdList)
// 发送新出现格子里的实体出现通知
g.AddSceneEntityNotify(player, proto.VisionType_VISION_TYPE_BORN, addEntityIdList, false)
// 更新玩家的位置信息
@@ -224,7 +226,7 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
// 其他玩家
for _, uid := range delUidList {
otherPlayer := g.userManager.GetOnlineUser(uid)
g.RemoveSceneEntityNotifyToPlayer(otherPlayer, []uint32{playerActiveAvatarEntityId})
g.RemoveSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_TYPE_REMOVE, []uint32{playerActiveAvatarEntityId})
}
for _, uid := range addUidList {
otherPlayer := g.userManager.GetOnlineUser(uid)
@@ -357,7 +359,8 @@ func (g *GameManager) ClientAbilityInitFinishNotify(player *model.Player, payloa
// 只给附近aoi区域的玩家广播消息
surrPlayerList := make([]*model.Player, 0)
entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
//entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := world.GetSceneById(player.SceneId).GetEntityIdList()
for _, entityId := range entityIdList {
entity := scene.GetEntity(entityId)
if entity == nil {
@@ -423,7 +426,8 @@ func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg
// 只给附近aoi区域的玩家广播消息
surrPlayerList := make([]*model.Player, 0)
entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
//entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := world.GetSceneById(player.SceneId).GetEntityIdList()
for _, entityId := range entityIdList {
entity := scene.GetEntity(entityId)
if entity == nil {

View File

@@ -86,7 +86,7 @@ func (g *GameManager) TeleportPlayer(player *model.Player, sceneId uint32, pos *
oldScene := world.GetSceneById(oldSceneId)
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
playerTeamEntity := oldScene.GetPlayerTeamEntity(player.PlayerID)
g.RemoveSceneEntityNotifyBroadcast(oldScene, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]})
g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_TYPE_REMOVE, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]})
if jumpScene {
// PacketDelTeamEntityNotify
delTeamEntityNotify := g.PacketDelTeamEntityNotify(oldScene, player)

View File

@@ -1,6 +1,7 @@
package game
import (
"hk4e/pkg/object"
"time"
"hk4e/gs/constant"
@@ -40,13 +41,13 @@ func (g *GameManager) PlayerApplyEnterMpResultReq(player *model.Player, payloadM
applyUid := req.ApplyUid
isAgreed := req.IsAgreed
g.UserDealEnterWorld(player, applyUid, isAgreed)
// PacketPlayerApplyEnterMpResultRsp
playerApplyEnterMpResultRsp := new(proto.PlayerApplyEnterMpResultRsp)
playerApplyEnterMpResultRsp.ApplyUid = applyUid
playerApplyEnterMpResultRsp.IsAgreed = isAgreed
g.SendMsg(cmd.PlayerApplyEnterMpResultRsp, player.PlayerID, player.ClientSeq, playerApplyEnterMpResultRsp)
g.UserDealEnterWorld(player, applyUid, isAgreed)
}
func (g *GameManager) PlayerGetForceQuitBanInfoReq(player *model.Player, payloadMsg pb.Message) {
@@ -130,6 +131,50 @@ func (g *GameManager) SceneKickPlayerReq(player *model.Player, payloadMsg pb.Mes
g.SendMsg(cmd.SceneKickPlayerRsp, player.PlayerID, player.ClientSeq, sceneKickPlayerRsp)
}
func (g *GameManager) JoinPlayerSceneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user join player scene, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.JoinPlayerSceneReq)
hostPlayer := g.userManager.GetOnlineUser(req.TargetUid)
hostWorld := g.worldManager.GetWorldByID(hostPlayer.WorldId)
_, exist := hostWorld.waitEnterPlayerMap[player.PlayerID]
if !exist {
return
}
joinPlayerSceneRsp := new(proto.JoinPlayerSceneRsp)
joinPlayerSceneRsp.Retcode = int32(proto.Retcode_RETCODE_RET_JOIN_OTHER_WAIT)
g.SendMsg(cmd.JoinPlayerSceneRsp, player.PlayerID, player.ClientSeq, joinPlayerSceneRsp)
world := g.worldManager.GetWorldByID(player.WorldId)
g.UserWorldRemovePlayer(world, player)
g.SendMsg(cmd.LeaveWorldNotify, player.PlayerID, 0, new(proto.LeaveWorldNotify))
//g.LoginNotify(player.PlayerID, player, 0)
if hostPlayer.SceneLoadState == model.SceneEnterDone {
delete(hostWorld.waitEnterPlayerMap, player.PlayerID)
player.Pos = &model.Vector{
X: hostPlayer.Pos.X,
Y: hostPlayer.Pos.Y,
Z: hostPlayer.Pos.Z,
}
player.Rot = &model.Vector{
X: hostPlayer.Rot.X,
Y: hostPlayer.Rot.Y,
Z: hostPlayer.Rot.Z,
}
player.SceneId = hostPlayer.SceneId
g.UserWorldAddPlayer(hostWorld, player)
player.SceneLoadState = model.SceneNone
g.SendMsg(cmd.PlayerEnterSceneNotify, player.PlayerID, 0, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_TYPE_OTHER))
}
}
func (g *GameManager) UserApplyEnterWorld(player *model.Player, targetUid uint32) bool {
targetPlayer := g.userManager.GetOnlineUser(targetUid)
if targetPlayer == nil {
@@ -189,13 +234,25 @@ func (g *GameManager) UserDealEnterWorld(hostPlayer *model.Player, otherUid uint
if !agree {
return
}
world := g.worldManager.GetWorldByID(hostPlayer.WorldId)
world.waitEnterPlayerMap[otherPlayer.PlayerID] = time.Now().UnixMilli()
if world.multiplayer {
return
}
hostWorld := g.worldManager.GetWorldByID(hostPlayer.WorldId)
if hostWorld.multiplayer == false {
g.UserWorldRemovePlayer(hostWorld, hostPlayer)
world.ChangeToMP()
// PacketWorldDataNotify
worldDataNotify := new(proto.WorldDataNotify)
worldDataNotify.WorldPropMap = make(map[uint32]*proto.PropValue)
// 是否多人游戏
worldDataNotify.WorldPropMap[2] = &proto.PropValue{
Type: 2,
Val: object.ConvBoolToInt64(world.multiplayer),
Value: &proto.PropValue_Ival{Ival: object.ConvBoolToInt64(world.multiplayer)},
}
g.SendMsg(cmd.WorldDataNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, worldDataNotify)
hostWorld = g.worldManager.CreateWorld(hostPlayer, true)
g.UserWorldAddPlayer(hostWorld, hostPlayer)
hostPlayer.SceneLoadState = model.SceneNone
// PacketPlayerEnterSceneNotify
@@ -208,37 +265,18 @@ func (g *GameManager) UserDealEnterWorld(hostPlayer *model.Player, otherUid uint
hostPlayer.Pos,
)
g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify)
}
otherWorld := g.worldManager.GetWorldByID(otherPlayer.WorldId)
g.UserWorldRemovePlayer(otherWorld, otherPlayer)
// PacketGuestBeginEnterSceneNotify
guestBeginEnterSceneNotify := new(proto.GuestBeginEnterSceneNotify)
guestBeginEnterSceneNotify.SceneId = hostPlayer.SceneId
guestBeginEnterSceneNotify.Uid = otherPlayer.PlayerID
g.SendMsg(cmd.GuestBeginEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, guestBeginEnterSceneNotify)
otherPlayer.Pos = &model.Vector{
X: hostPlayer.Pos.X,
Y: hostPlayer.Pos.Y + 1,
Z: hostPlayer.Pos.Z,
}
otherPlayer.Rot = &model.Vector{
X: hostPlayer.Rot.X,
Y: hostPlayer.Rot.Y,
Z: hostPlayer.Rot.Z,
}
otherPlayer.SceneId = hostPlayer.SceneId
g.UserWorldAddPlayer(hostWorld, otherPlayer)
}
func (g *GameManager) JoinPlayerSceneReq(player *model.Player, payloadMsg pb.Message) {
joinPlayerSceneRsp := new(proto.JoinPlayerSceneRsp)
joinPlayerSceneRsp.Retcode = int32(proto.Retcode_RETCODE_RET_JOIN_OTHER_WAIT)
g.SendMsg(cmd.JoinPlayerSceneRsp, player.PlayerID, player.ClientSeq, joinPlayerSceneRsp)
g.SendMsg(cmd.LeaveWorldNotify, player.PlayerID, 0, new(proto.LeaveWorldNotify))
g.LoginNotify(player.PlayerID, player, 0)
player.SceneLoadState = model.SceneNone
g.SendMsg(cmd.PlayerEnterSceneNotify, player.PlayerID, 0, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_TYPE_OTHER))
// 仅仅把当前的场上角色的实体消失掉
scene := world.GetSceneById(hostPlayer.SceneId)
playerTeamEntity := scene.GetPlayerTeamEntity(hostPlayer.PlayerID)
activeAvatarId := hostPlayer.TeamConfig.GetActiveAvatarId()
g.RemoveSceneEntityNotifyToPlayer(hostPlayer, proto.VisionType_VISION_TYPE_MISS, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]})
}
func (g *GameManager) UserLeaveWorld(player *model.Player) bool {
@@ -282,8 +320,14 @@ func (g *GameManager) UserWorldRemovePlayer(world *World, player *model.Player)
}
}
// PacketDelTeamEntityNotify
scene := world.GetSceneById(player.SceneId)
// 仅仅把当前的场上角色的实体消失掉
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_TYPE_MISS, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]})
// PacketDelTeamEntityNotify
delTeamEntityNotify := g.PacketDelTeamEntityNotify(scene, player)
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerID, player.ClientSeq, delTeamEntityNotify)
@@ -295,7 +339,7 @@ func (g *GameManager) UserWorldRemovePlayer(world *World, player *model.Player)
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
g.RemoveSceneEntityNotifyBroadcast(scene, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]})
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_TYPE_REMOVE, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]})
}
world.RemovePlayer(player)
@@ -313,13 +357,17 @@ func (g *GameManager) UserWorldRemovePlayer(world *World, player *model.Player)
func (g *GameManager) UpdateWorldPlayerInfo(hostWorld *World, excludePlayer *model.Player) {
for _, worldPlayer := range hostWorld.playerMap {
if worldPlayer.PlayerID == excludePlayer.PlayerID || worldPlayer.SceneLoadState == model.SceneNone {
if worldPlayer.PlayerID == excludePlayer.PlayerID {
continue
}
scene := hostWorld.GetSceneById(worldPlayer.SceneId)
// PacketSceneTeamUpdateNotify
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(hostWorld)
g.SendMsg(cmd.SceneTeamUpdateNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneTeamUpdateNotify)
// PacketPlayerPreEnterMpNotify
playerPreEnterMpNotify := new(proto.PlayerPreEnterMpNotify)
playerPreEnterMpNotify.State = proto.PlayerPreEnterMpNotify_STATE_START
playerPreEnterMpNotify.Uid = excludePlayer.PlayerID
playerPreEnterMpNotify.Nickname = excludePlayer.NickName
g.SendMsg(cmd.PlayerPreEnterMpNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, playerPreEnterMpNotify)
// PacketWorldPlayerInfoNotify
worldPlayerInfoNotify := new(proto.WorldPlayerInfoNotify)
@@ -338,6 +386,12 @@ func (g *GameManager) UpdateWorldPlayerInfo(hostWorld *World, excludePlayer *mod
}
g.SendMsg(cmd.WorldPlayerInfoNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, worldPlayerInfoNotify)
// PacketSceneTimeNotify
sceneTimeNotify := new(proto.SceneTimeNotify)
sceneTimeNotify.SceneId = worldPlayer.SceneId
sceneTimeNotify.SceneTime = uint64(scene.GetSceneTime())
g.SendMsg(cmd.SceneTimeNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneTimeNotify)
// PacketScenePlayerInfoNotify
scenePlayerInfoNotify := new(proto.ScenePlayerInfoNotify)
for _, subWorldPlayer := range hostWorld.playerMap {
@@ -360,6 +414,10 @@ func (g *GameManager) UpdateWorldPlayerInfo(hostWorld *World, excludePlayer *mod
}
g.SendMsg(cmd.ScenePlayerInfoNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, scenePlayerInfoNotify)
// PacketSceneTeamUpdateNotify
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(hostWorld)
g.SendMsg(cmd.SceneTeamUpdateNotify, worldPlayer.PlayerID, worldPlayer.ClientSeq, sceneTeamUpdateNotify)
// PacketSyncTeamEntityNotify
syncTeamEntityNotify := new(proto.SyncTeamEntityNotify)
syncTeamEntityNotify.SceneId = worldPlayer.SceneId

View File

@@ -19,10 +19,11 @@ import (
func (g *GameManager) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user enter scene ready, uid: %v", player.PlayerID)
world := g.worldManager.GetWorldByID(player.WorldId)
// PacketEnterScenePeerNotify
enterScenePeerNotify := new(proto.EnterScenePeerNotify)
enterScenePeerNotify.DestSceneId = player.SceneId
world := g.worldManager.GetWorldByID(player.WorldId)
enterScenePeerNotify.PeerId = player.PeerId
enterScenePeerNotify.HostPeerId = world.owner.PeerId
enterScenePeerNotify.EnterSceneToken = player.EnterSceneToken
@@ -37,15 +38,17 @@ func (g *GameManager) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Mes
func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user scene init finish, uid: %v", player.PlayerID)
world := g.worldManager.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
// PacketServerTimeNotify
serverTimeNotify := new(proto.ServerTimeNotify)
serverTimeNotify.ServerTime = uint64(time.Now().UnixMilli())
g.SendMsg(cmd.ServerTimeNotify, player.PlayerID, player.ClientSeq, serverTimeNotify)
if world.IsPlayerFirstEnter(player) {
// PacketWorldPlayerInfoNotify
worldPlayerInfoNotify := new(proto.WorldPlayerInfoNotify)
world := g.worldManager.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
for _, worldPlayer := range world.playerMap {
onlinePlayerInfo := new(proto.OnlinePlayerInfo)
onlinePlayerInfo.Uid = worldPlayer.PlayerID
@@ -126,7 +129,7 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
}
playerEnterSceneInfoNotify.MpLevelEntityInfo = &proto.MPLevelEntityInfo{
EntityId: g.worldManager.GetWorldByID(player.WorldId).mpLevelEntityId,
AuthorityPeerId: g.worldManager.GetWorldByID(player.WorldId).owner.PeerId,
AuthorityPeerId: 1,
AbilityInfo: empty,
}
activeTeam := player.TeamConfig.GetActiveTeam()
@@ -151,6 +154,7 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
sceneAreaWeatherNotify.WeatherAreaId = 0
sceneAreaWeatherNotify.ClimateType = uint32(constant.ClimateTypeConst.CLIMATE_SUNNY)
g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerID, player.ClientSeq, sceneAreaWeatherNotify)
}
// PacketScenePlayerInfoNotify
scenePlayerInfoNotify := new(proto.ScenePlayerInfoNotify)
@@ -215,29 +219,67 @@ func (g *GameManager) SceneInitFinishReq(player *model.Player, payloadMsg pb.Mes
func (g *GameManager) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
logger.LOG.Debug("user enter scene done, uid: %v", player.PlayerID)
world := g.worldManager.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if world.multiplayer && world.IsPlayerFirstEnter(player) {
guestPostEnterSceneNotify := new(proto.GuestPostEnterSceneNotify)
guestPostEnterSceneNotify.SceneId = player.SceneId
guestPostEnterSceneNotify.Uid = player.PlayerID
g.SendMsg(cmd.GuestPostEnterSceneNotify, world.owner.PlayerID, world.owner.ClientSeq, guestPostEnterSceneNotify)
}
var visionType = proto.VisionType_VISION_TYPE_TRANSPORT
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
if world.IsPlayerFirstEnter(player) {
visionType = proto.VisionType_VISION_TYPE_BORN
}
g.AddSceneEntityNotify(player, visionType, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]}, true)
// 通过aoi获取场景中在自己周围格子里的全部实体id
//entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
entityIdList := world.GetSceneById(player.SceneId).GetEntityIdList()
if world.IsPlayerFirstEnter(player) {
visionType = proto.VisionType_VISION_TYPE_MEET
}
g.AddSceneEntityNotify(player, visionType, entityIdList, false)
// PacketSceneAreaWeatherNotify
sceneAreaWeatherNotify := new(proto.SceneAreaWeatherNotify)
sceneAreaWeatherNotify.WeatherAreaId = 0
sceneAreaWeatherNotify.ClimateType = uint32(constant.ClimateTypeConst.CLIMATE_SUNNY)
g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerID, player.ClientSeq, sceneAreaWeatherNotify)
// PacketEnterSceneDoneRsp
enterSceneDoneRsp := new(proto.EnterSceneDoneRsp)
enterSceneDoneRsp.EnterSceneToken = player.EnterSceneToken
g.SendMsg(cmd.EnterSceneDoneRsp, player.PlayerID, player.ClientSeq, enterSceneDoneRsp)
// PacketPlayerTimeNotify
playerTimeNotify := new(proto.PlayerTimeNotify)
playerTimeNotify.IsPaused = player.Pause
playerTimeNotify.PlayerTime = uint64(player.TotalOnlineTime)
playerTimeNotify.ServerTime = uint64(time.Now().UnixMilli())
g.SendMsg(cmd.PlayerTimeNotify, player.PlayerID, player.ClientSeq, playerTimeNotify)
player.SceneLoadState = model.SceneEnterDone
world := g.worldManager.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
world.PlayerEnter(player)
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
g.AddSceneEntityNotify(player, proto.VisionType_VISION_TYPE_BORN, []uint32{playerTeamEntity.avatarEntityMap[activeAvatarId]}, true)
for otherPlayerId := range world.waitEnterPlayerMap {
delete(world.waitEnterPlayerMap, otherPlayerId)
otherPlayer := g.userManager.GetOnlineUser(otherPlayerId)
otherPlayer.Pos = &model.Vector{
X: player.Pos.X,
Y: player.Pos.Y,
Z: player.Pos.Z,
}
otherPlayer.Rot = &model.Vector{
X: player.Rot.X,
Y: player.Rot.Y,
Z: player.Rot.Z,
}
otherPlayer.SceneId = player.SceneId
// 通过aoi获取场景中在自己周围格子里的全部实体id
entityIdList := world.aoiManager.GetEntityIdListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
g.AddSceneEntityNotify(player, proto.VisionType_VISION_TYPE_MEET, entityIdList, false)
g.UserWorldAddPlayer(world, otherPlayer)
otherPlayer.SceneLoadState = model.SceneNone
g.SendMsg(cmd.PlayerEnterSceneNotify, otherPlayer.PlayerID, 0, g.PacketPlayerEnterSceneNotifyLogin(otherPlayer, proto.EnterType_ENTER_TYPE_OTHER))
}
}
func (g *GameManager) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
@@ -368,21 +410,21 @@ func (g *GameManager) AddSceneEntityNotifyBroadcast(scene *Scene, visionType pro
}
}
func (g *GameManager) RemoveSceneEntityNotifyToPlayer(player *model.Player, entityIdList []uint32) {
func (g *GameManager) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType proto.VisionType, entityIdList []uint32) {
// PacketSceneEntityDisappearNotify
sceneEntityDisappearNotify := new(proto.SceneEntityDisappearNotify)
sceneEntityDisappearNotify.EntityList = entityIdList
sceneEntityDisappearNotify.DisappearType = proto.VisionType_VISION_TYPE_REMOVE
sceneEntityDisappearNotify.DisappearType = visionType
g.SendMsg(cmd.SceneEntityDisappearNotify, player.PlayerID, player.ClientSeq, sceneEntityDisappearNotify)
logger.LOG.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
player.PlayerID, sceneEntityDisappearNotify.DisappearType, len(sceneEntityDisappearNotify.EntityList))
}
func (g *GameManager) RemoveSceneEntityNotifyBroadcast(scene *Scene, entityIdList []uint32) {
func (g *GameManager) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.VisionType, entityIdList []uint32) {
// PacketSceneEntityDisappearNotify
sceneEntityDisappearNotify := new(proto.SceneEntityDisappearNotify)
sceneEntityDisappearNotify.EntityList = entityIdList
sceneEntityDisappearNotify.DisappearType = proto.VisionType_VISION_TYPE_REMOVE
sceneEntityDisappearNotify.DisappearType = visionType
for _, scenePlayer := range scene.playerMap {
g.SendMsg(cmd.SceneEntityDisappearNotify, scenePlayer.PlayerID, scenePlayer.ClientSeq, sceneEntityDisappearNotify)
logger.LOG.Debug("SceneEntityDisappearNotify, uid: %v, type: %v, len: %v",
@@ -410,9 +452,9 @@ func (g *GameManager) AddSceneEntityNotify(player *model.Player, visionType prot
logger.LOG.Error("get scene player is nil, world id: %v, scene id: %v", world.id, scene.id)
continue
}
if scenePlayer.SceneLoadState != model.SceneEnterDone {
continue
}
//if scenePlayer.SceneLoadState != model.SceneEnterDone {
// continue
//}
if entity.avatarEntity.avatarId != scenePlayer.TeamConfig.GetActiveAvatarId() {
continue
}
@@ -626,8 +668,7 @@ func (g *GameManager) PacketSceneEntityInfoGadget(scene *Scene, entityId uint32)
}
func (g *GameManager) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarId uint32) *proto.SceneAvatarInfo {
activeAvatarId := player.TeamConfig.GetActiveAvatarId()
activeAvatar := player.AvatarMap[activeAvatarId]
avatar := player.AvatarMap[avatarId]
playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID)
equipIdList := make([]uint32, 0)
weapon := player.AvatarMap[avatarId].EquipWeapon
@@ -643,7 +684,7 @@ func (g *GameManager) PacketSceneAvatarInfo(scene *Scene, player *model.Player,
EquipIdList: equipIdList,
SkillDepotId: player.AvatarMap[avatarId].SkillDepotId,
Weapon: &proto.SceneWeaponInfo{
EntityId: playerTeamEntity.weaponEntityMap[activeAvatar.EquipWeapon.WeaponId],
EntityId: playerTeamEntity.weaponEntityMap[avatar.EquipWeapon.WeaponId],
GadgetId: uint32(gdc.CONF.ItemDataMap[int32(weapon.ItemId)].GadgetId),
ItemId: weapon.ItemId,
Guid: weapon.Guid,

View File

@@ -222,7 +222,10 @@ func (g *GameManager) UpdateStamina(player *model.Player, staminaCost int32) {
// SetStamina 设置玩家的耐力
func (g *GameManager) SetStamina(player *model.Player, stamina uint32) {
prop := constant.PlayerPropertyConst.PROP_CUR_PERSIST_STAMINA
// 当前无变动不要频繁发包
if player.PropertiesMap[constant.PlayerPropertyConst.PROP_MAX_STAMINA] == player.PropertiesMap[constant.PlayerPropertyConst.PROP_CUR_PERSIST_STAMINA] {
return
}
// 设置玩家的耐力prop
player.PropertiesMap[prop] = stamina

View File

@@ -62,6 +62,8 @@ func (w *WorldManager) CreateWorld(owner *model.Player, multiplayer bool) *World
-2000, 2000, 1,
-5500, 6500, 120,
),
playerFirstEnterMap: make(map[uint32]int64),
waitEnterPlayerMap: make(map[uint32]int64),
}
if world.IsBigWorld() {
world.aoiManager = aoi.NewAoiManager(
@@ -104,6 +106,8 @@ type World struct {
mpLevelEntityId uint32
chatMsgList []*proto.ChatInfo
aoiManager *aoi.AoiManager // 当前世界地图的aoi管理器
playerFirstEnterMap map[uint32]int64
waitEnterPlayerMap map[uint32]int64
}
func (w *World) GetNextWorldEntityId(entityType uint16) uint32 {
@@ -123,6 +127,7 @@ func (w *World) RemovePlayer(player *model.Player) {
scene := w.sceneMap[player.SceneId]
scene.RemovePlayer(player)
delete(w.playerMap, player.PlayerID)
delete(w.playerFirstEnterMap, player.PlayerID)
}
func (w *World) CreateScene(sceneId uint32) *Scene {
@@ -161,6 +166,23 @@ func (w *World) IsBigWorld() bool {
return w.owner.PlayerID == 1
}
func (w *World) ChangeToMP() {
w.multiplayer = true
}
func (w *World) IsPlayerFirstEnter(player *model.Player) bool {
_, exist := w.playerFirstEnterMap[player.PlayerID]
if !exist {
return true
} else {
return false
}
}
func (w *World) PlayerEnter(player *model.Player) {
w.playerFirstEnterMap[player.PlayerID] = time.Now().UnixMilli()
}
type Scene struct {
id uint32
world *World
@@ -378,6 +400,14 @@ func (s *Scene) GetEntity(entityId uint32) *Entity {
return s.entityMap[entityId]
}
func (s *Scene) GetEntityIdList() []uint32 {
entityIdList := make([]uint32, 0)
for k := range s.entityMap {
entityIdList = append(entityIdList, k)
}
return entityIdList
}
// 伤害处理和转发
func (s *Scene) AddAttack(attack *Attack) {

View File

@@ -67,8 +67,8 @@ type Player struct {
CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间
StaminaInfo *StaminaInfo `bson:"-"` // 耐力临时数据
ClientSeq uint32 `bson:"-"` // 客户端发包请求的序号
CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry]
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry]
CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry] `bson:"-"`
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry] `bson:"-"`
}
func (p *Player) GetNextGameObjectGuid() uint64 {

View File

@@ -140,6 +140,9 @@ func (c *CmdProtoMap) registerAllMessage() {
c.registerMessage(PlayerQuitFromMpNotify, &proto.PlayerQuitFromMpNotify{}) // 退出多人游戏通知
c.registerMessage(JoinPlayerSceneReq, &proto.JoinPlayerSceneReq{}) // 进入他人世界请求
c.registerMessage(JoinPlayerSceneRsp, &proto.JoinPlayerSceneRsp{}) // 进入他人世界响应
c.registerMessage(GuestBeginEnterSceneNotify, &proto.GuestBeginEnterSceneNotify{}) // 他人开始进入世界通知
c.registerMessage(GuestPostEnterSceneNotify, &proto.GuestPostEnterSceneNotify{}) // 他人进入世界完成通知
c.registerMessage(PlayerPreEnterMpNotify, &proto.PlayerPreEnterMpNotify{}) // 他人正在进入世界通知
// 社交
c.registerMessage(SetPlayerBirthdayReq, &proto.SetPlayerBirthdayReq{}) // 设置生日请求