From b836c0f8db9332b7142358527fb43df8c16d01cb Mon Sep 17 00:00:00 2001 From: huangxiaolei <1782360262@qq.com> Date: Thu, 8 Dec 2022 15:21:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=9C=BA=E6=99=AF=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8D=8F=E8=AE=AE=E7=BB=84=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/tick_manager.go | 6 + gs/game/user_combat.go | 18 +- gs/game/user_map.go | 2 +- gs/game/user_multiplayer.go | 158 +++++++++----- gs/game/user_scene.go | 307 +++++++++++++++------------ gs/game/user_stamina.go | 5 +- gs/game/world_manager.go | 50 ++++- gs/model/player.go | 32 +-- protocol/cmd/cmd_id_proto_obj_map.go | 3 + 9 files changed, 363 insertions(+), 218 deletions(-) diff --git a/gs/game/tick_manager.go b/gs/game/tick_manager.go index 76db3204..83496d21 100644 --- a/gs/game/tick_manager.go +++ b/gs/game/tick_manager.go @@ -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) { diff --git a/gs/game/user_combat.go b/gs/game/user_combat.go index e6df3850..7542e6d6 100644 --- a/gs/game/user_combat.go +++ b/gs/game/user_combat.go @@ -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 { diff --git a/gs/game/user_map.go b/gs/game/user_map.go index 825273cf..749b0aab 100644 --- a/gs/game/user_map.go +++ b/gs/game/user_map.go @@ -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) diff --git a/gs/game/user_multiplayer.go b/gs/game/user_multiplayer.go index c79b7813..019b1624 100644 --- a/gs/game/user_multiplayer.go +++ b/gs/game/user_multiplayer.go @@ -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,56 +234,49 @@ func (g *GameManager) UserDealEnterWorld(hostPlayer *model.Player, otherUid uint if !agree { return } - - hostWorld := g.worldManager.GetWorldByID(hostPlayer.WorldId) - if hostWorld.multiplayer == false { - g.UserWorldRemovePlayer(hostWorld, hostPlayer) - - hostWorld = g.worldManager.CreateWorld(hostPlayer, true) - g.UserWorldAddPlayer(hostWorld, hostPlayer) - hostPlayer.SceneLoadState = model.SceneNone - - // PacketPlayerEnterSceneNotify - hostPlayerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp( - hostPlayer, - hostPlayer, - proto.EnterType_ENTER_TYPE_GOTO, - uint32(constant.EnterReasonConst.HostFromSingleToMp), - hostPlayer.SceneId, - hostPlayer.Pos, - ) - g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify) + world := g.worldManager.GetWorldByID(hostPlayer.WorldId) + world.waitEnterPlayerMap[otherPlayer.PlayerID] = time.Now().UnixMilli() + if world.multiplayer { + return } - otherWorld := g.worldManager.GetWorldByID(otherPlayer.WorldId) - g.UserWorldRemovePlayer(otherWorld, otherPlayer) + world.ChangeToMP() - otherPlayer.Pos = &model.Vector{ - X: hostPlayer.Pos.X, - Y: hostPlayer.Pos.Y + 1, - Z: hostPlayer.Pos.Z, + // 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)}, } - otherPlayer.Rot = &model.Vector{ - X: hostPlayer.Rot.X, - Y: hostPlayer.Rot.Y, - Z: hostPlayer.Rot.Z, - } - otherPlayer.SceneId = hostPlayer.SceneId + g.SendMsg(cmd.WorldDataNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, worldDataNotify) - g.UserWorldAddPlayer(hostWorld, otherPlayer) -} + hostPlayer.SceneLoadState = model.SceneNone -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) + // PacketPlayerEnterSceneNotify + hostPlayerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp( + hostPlayer, + hostPlayer, + proto.EnterType_ENTER_TYPE_GOTO, + uint32(constant.EnterReasonConst.HostFromSingleToMp), + hostPlayer.SceneId, + hostPlayer.Pos, + ) + g.SendMsg(cmd.PlayerEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, hostPlayerEnterSceneNotify) - g.SendMsg(cmd.LeaveWorldNotify, player.PlayerID, 0, new(proto.LeaveWorldNotify)) + // PacketGuestBeginEnterSceneNotify + guestBeginEnterSceneNotify := new(proto.GuestBeginEnterSceneNotify) + guestBeginEnterSceneNotify.SceneId = hostPlayer.SceneId + guestBeginEnterSceneNotify.Uid = otherPlayer.PlayerID + g.SendMsg(cmd.GuestBeginEnterSceneNotify, hostPlayer.PlayerID, hostPlayer.ClientSeq, guestBeginEnterSceneNotify) - 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 diff --git a/gs/game/user_scene.go b/gs/game/user_scene.go index 04b9e088..94ef8a00 100644 --- a/gs/game/user_scene.go +++ b/gs/game/user_scene.go @@ -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,120 +38,123 @@ 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) - // 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 - onlinePlayerInfo.Nickname = worldPlayer.NickName - onlinePlayerInfo.PlayerLevel = worldPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_LEVEL] - onlinePlayerInfo.MpSettingType = proto.MpSettingType(worldPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_MP_SETTING_TYPE]) - onlinePlayerInfo.NameCardId = worldPlayer.NameCard - onlinePlayerInfo.Signature = worldPlayer.Signature - onlinePlayerInfo.ProfilePicture = &proto.ProfilePicture{AvatarId: worldPlayer.HeadImage} - onlinePlayerInfo.CurPlayerNumInWorld = uint32(len(world.playerMap)) - worldPlayerInfoNotify.PlayerInfoList = append(worldPlayerInfoNotify.PlayerInfoList, onlinePlayerInfo) - worldPlayerInfoNotify.PlayerUidList = append(worldPlayerInfoNotify.PlayerUidList, worldPlayer.PlayerID) - } - g.SendMsg(cmd.WorldPlayerInfoNotify, player.PlayerID, player.ClientSeq, worldPlayerInfoNotify) - - // PacketWorldDataNotify - worldDataNotify := new(proto.WorldDataNotify) - worldDataNotify.WorldPropMap = make(map[uint32]*proto.PropValue) - // 世界等级 - worldDataNotify.WorldPropMap[1] = &proto.PropValue{ - Type: 1, - Val: int64(world.worldLevel), - Value: &proto.PropValue_Ival{Ival: int64(world.worldLevel)}, - } - // 是否多人游戏 - 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, player.PlayerID, player.ClientSeq, worldDataNotify) - - // PacketPlayerWorldSceneInfoListNotify - playerWorldSceneInfoListNotify := new(proto.PlayerWorldSceneInfoListNotify) - playerWorldSceneInfoListNotify.InfoList = []*proto.PlayerWorldSceneInfo{ - {SceneId: 1, IsLocked: true, SceneTagIdList: []uint32{}}, - {SceneId: 3, IsLocked: false, SceneTagIdList: []uint32{102, 111, 112, 116, 118, 126, 135, 140, 142, 149, 1091, 1094, 1095, 1099, 1101, 1103, 1105, 1110, 1120, 1122, 1125, 1127, 1129, 1131, 1133, 1135, 1137, 1138, 1140, 1143, 1146, 1165, 1168}}, - {SceneId: 4, IsLocked: true, SceneTagIdList: []uint32{}}, - {SceneId: 5, IsLocked: false, SceneTagIdList: []uint32{121, 1031}}, - {SceneId: 6, IsLocked: false, SceneTagIdList: []uint32{144, 146, 1062, 1063}}, - {SceneId: 7, IsLocked: true, SceneTagIdList: []uint32{136, 137, 138, 148, 1034}}, - {SceneId: 9, IsLocked: true, SceneTagIdList: []uint32{1012, 1016, 1021, 1022, 1060, 1077}}, - } - g.SendMsg(cmd.PlayerWorldSceneInfoListNotify, player.PlayerID, player.ClientSeq, playerWorldSceneInfoListNotify) - - // SceneForceUnlockNotify - g.SendMsg(cmd.SceneForceUnlockNotify, player.PlayerID, player.ClientSeq, new(proto.SceneForceUnlockNotify)) - - // PacketHostPlayerNotify - hostPlayerNotify := new(proto.HostPlayerNotify) - hostPlayerNotify.HostUid = world.owner.PlayerID - hostPlayerNotify.HostPeerId = world.owner.PeerId - g.SendMsg(cmd.HostPlayerNotify, player.PlayerID, player.ClientSeq, hostPlayerNotify) - - // PacketSceneTimeNotify - sceneTimeNotify := new(proto.SceneTimeNotify) - sceneTimeNotify.SceneId = player.SceneId - sceneTimeNotify.SceneTime = uint64(scene.GetSceneTime()) - g.SendMsg(cmd.SceneTimeNotify, player.PlayerID, player.ClientSeq, sceneTimeNotify) - - // PacketPlayerGameTimeNotify - playerGameTimeNotify := new(proto.PlayerGameTimeNotify) - playerGameTimeNotify.GameTime = scene.gameTime - playerGameTimeNotify.Uid = player.PlayerID - g.SendMsg(cmd.PlayerGameTimeNotify, player.PlayerID, player.ClientSeq, playerGameTimeNotify) - - // PacketPlayerEnterSceneInfoNotify - empty := new(proto.AbilitySyncStateInfo) - playerEnterSceneInfoNotify := new(proto.PlayerEnterSceneInfoNotify) - activeAvatarId := player.TeamConfig.GetActiveAvatarId() - playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID) - playerEnterSceneInfoNotify.CurAvatarEntityId = playerTeamEntity.avatarEntityMap[activeAvatarId] - playerEnterSceneInfoNotify.EnterSceneToken = player.EnterSceneToken - playerEnterSceneInfoNotify.TeamEnterInfo = &proto.TeamEnterSceneInfo{ - TeamEntityId: playerTeamEntity.teamEntityId, - TeamAbilityInfo: empty, - AbilityControlBlock: new(proto.AbilityControlBlock), - } - playerEnterSceneInfoNotify.MpLevelEntityInfo = &proto.MPLevelEntityInfo{ - EntityId: g.worldManager.GetWorldByID(player.WorldId).mpLevelEntityId, - AuthorityPeerId: g.worldManager.GetWorldByID(player.WorldId).owner.PeerId, - AbilityInfo: empty, - } - activeTeam := player.TeamConfig.GetActiveTeam() - for _, avatarId := range activeTeam.AvatarIdList { - if avatarId == 0 { - break + if world.IsPlayerFirstEnter(player) { + // PacketWorldPlayerInfoNotify + worldPlayerInfoNotify := new(proto.WorldPlayerInfoNotify) + for _, worldPlayer := range world.playerMap { + onlinePlayerInfo := new(proto.OnlinePlayerInfo) + onlinePlayerInfo.Uid = worldPlayer.PlayerID + onlinePlayerInfo.Nickname = worldPlayer.NickName + onlinePlayerInfo.PlayerLevel = worldPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_LEVEL] + onlinePlayerInfo.MpSettingType = proto.MpSettingType(worldPlayer.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_MP_SETTING_TYPE]) + onlinePlayerInfo.NameCardId = worldPlayer.NameCard + onlinePlayerInfo.Signature = worldPlayer.Signature + onlinePlayerInfo.ProfilePicture = &proto.ProfilePicture{AvatarId: worldPlayer.HeadImage} + onlinePlayerInfo.CurPlayerNumInWorld = uint32(len(world.playerMap)) + worldPlayerInfoNotify.PlayerInfoList = append(worldPlayerInfoNotify.PlayerInfoList, onlinePlayerInfo) + worldPlayerInfoNotify.PlayerUidList = append(worldPlayerInfoNotify.PlayerUidList, worldPlayer.PlayerID) } - avatar := player.AvatarMap[avatarId] - avatarEnterSceneInfo := new(proto.AvatarEnterSceneInfo) - avatarEnterSceneInfo.AvatarGuid = avatar.Guid - avatarEnterSceneInfo.AvatarEntityId = playerTeamEntity.avatarEntityMap[avatarId] - avatarEnterSceneInfo.WeaponGuid = avatar.EquipWeapon.Guid - avatarEnterSceneInfo.WeaponEntityId = playerTeamEntity.weaponEntityMap[avatar.EquipWeapon.WeaponId] - avatarEnterSceneInfo.AvatarAbilityInfo = empty - avatarEnterSceneInfo.WeaponAbilityInfo = empty - playerEnterSceneInfoNotify.AvatarEnterInfo = append(playerEnterSceneInfoNotify.AvatarEnterInfo, avatarEnterSceneInfo) - } - g.SendMsg(cmd.PlayerEnterSceneInfoNotify, player.PlayerID, player.ClientSeq, playerEnterSceneInfoNotify) + g.SendMsg(cmd.WorldPlayerInfoNotify, player.PlayerID, player.ClientSeq, worldPlayerInfoNotify) - // PacketSceneAreaWeatherNotify - sceneAreaWeatherNotify := new(proto.SceneAreaWeatherNotify) - sceneAreaWeatherNotify.WeatherAreaId = 0 - sceneAreaWeatherNotify.ClimateType = uint32(constant.ClimateTypeConst.CLIMATE_SUNNY) - g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerID, player.ClientSeq, sceneAreaWeatherNotify) + // PacketWorldDataNotify + worldDataNotify := new(proto.WorldDataNotify) + worldDataNotify.WorldPropMap = make(map[uint32]*proto.PropValue) + // 世界等级 + worldDataNotify.WorldPropMap[1] = &proto.PropValue{ + Type: 1, + Val: int64(world.worldLevel), + Value: &proto.PropValue_Ival{Ival: int64(world.worldLevel)}, + } + // 是否多人游戏 + 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, player.PlayerID, player.ClientSeq, worldDataNotify) + + // PacketPlayerWorldSceneInfoListNotify + playerWorldSceneInfoListNotify := new(proto.PlayerWorldSceneInfoListNotify) + playerWorldSceneInfoListNotify.InfoList = []*proto.PlayerWorldSceneInfo{ + {SceneId: 1, IsLocked: true, SceneTagIdList: []uint32{}}, + {SceneId: 3, IsLocked: false, SceneTagIdList: []uint32{102, 111, 112, 116, 118, 126, 135, 140, 142, 149, 1091, 1094, 1095, 1099, 1101, 1103, 1105, 1110, 1120, 1122, 1125, 1127, 1129, 1131, 1133, 1135, 1137, 1138, 1140, 1143, 1146, 1165, 1168}}, + {SceneId: 4, IsLocked: true, SceneTagIdList: []uint32{}}, + {SceneId: 5, IsLocked: false, SceneTagIdList: []uint32{121, 1031}}, + {SceneId: 6, IsLocked: false, SceneTagIdList: []uint32{144, 146, 1062, 1063}}, + {SceneId: 7, IsLocked: true, SceneTagIdList: []uint32{136, 137, 138, 148, 1034}}, + {SceneId: 9, IsLocked: true, SceneTagIdList: []uint32{1012, 1016, 1021, 1022, 1060, 1077}}, + } + g.SendMsg(cmd.PlayerWorldSceneInfoListNotify, player.PlayerID, player.ClientSeq, playerWorldSceneInfoListNotify) + + // SceneForceUnlockNotify + g.SendMsg(cmd.SceneForceUnlockNotify, player.PlayerID, player.ClientSeq, new(proto.SceneForceUnlockNotify)) + + // PacketHostPlayerNotify + hostPlayerNotify := new(proto.HostPlayerNotify) + hostPlayerNotify.HostUid = world.owner.PlayerID + hostPlayerNotify.HostPeerId = world.owner.PeerId + g.SendMsg(cmd.HostPlayerNotify, player.PlayerID, player.ClientSeq, hostPlayerNotify) + + // PacketSceneTimeNotify + sceneTimeNotify := new(proto.SceneTimeNotify) + sceneTimeNotify.SceneId = player.SceneId + sceneTimeNotify.SceneTime = uint64(scene.GetSceneTime()) + g.SendMsg(cmd.SceneTimeNotify, player.PlayerID, player.ClientSeq, sceneTimeNotify) + + // PacketPlayerGameTimeNotify + playerGameTimeNotify := new(proto.PlayerGameTimeNotify) + playerGameTimeNotify.GameTime = scene.gameTime + playerGameTimeNotify.Uid = player.PlayerID + g.SendMsg(cmd.PlayerGameTimeNotify, player.PlayerID, player.ClientSeq, playerGameTimeNotify) + + // PacketPlayerEnterSceneInfoNotify + empty := new(proto.AbilitySyncStateInfo) + playerEnterSceneInfoNotify := new(proto.PlayerEnterSceneInfoNotify) + activeAvatarId := player.TeamConfig.GetActiveAvatarId() + playerTeamEntity := scene.GetPlayerTeamEntity(player.PlayerID) + playerEnterSceneInfoNotify.CurAvatarEntityId = playerTeamEntity.avatarEntityMap[activeAvatarId] + playerEnterSceneInfoNotify.EnterSceneToken = player.EnterSceneToken + playerEnterSceneInfoNotify.TeamEnterInfo = &proto.TeamEnterSceneInfo{ + TeamEntityId: playerTeamEntity.teamEntityId, + TeamAbilityInfo: empty, + AbilityControlBlock: new(proto.AbilityControlBlock), + } + playerEnterSceneInfoNotify.MpLevelEntityInfo = &proto.MPLevelEntityInfo{ + EntityId: g.worldManager.GetWorldByID(player.WorldId).mpLevelEntityId, + AuthorityPeerId: 1, + AbilityInfo: empty, + } + activeTeam := player.TeamConfig.GetActiveTeam() + for _, avatarId := range activeTeam.AvatarIdList { + if avatarId == 0 { + break + } + avatar := player.AvatarMap[avatarId] + avatarEnterSceneInfo := new(proto.AvatarEnterSceneInfo) + avatarEnterSceneInfo.AvatarGuid = avatar.Guid + avatarEnterSceneInfo.AvatarEntityId = playerTeamEntity.avatarEntityMap[avatarId] + avatarEnterSceneInfo.WeaponGuid = avatar.EquipWeapon.Guid + avatarEnterSceneInfo.WeaponEntityId = playerTeamEntity.weaponEntityMap[avatar.EquipWeapon.WeaponId] + avatarEnterSceneInfo.AvatarAbilityInfo = empty + avatarEnterSceneInfo.WeaponAbilityInfo = empty + playerEnterSceneInfoNotify.AvatarEnterInfo = append(playerEnterSceneInfoNotify.AvatarEnterInfo, avatarEnterSceneInfo) + } + g.SendMsg(cmd.PlayerEnterSceneInfoNotify, player.PlayerID, player.ClientSeq, playerEnterSceneInfoNotify) + + // PacketSceneAreaWeatherNotify + sceneAreaWeatherNotify := new(proto.SceneAreaWeatherNotify) + 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, diff --git a/gs/game/user_stamina.go b/gs/game/user_stamina.go index 1d2b540b..fc6fe70c 100644 --- a/gs/game/user_stamina.go +++ b/gs/game/user_stamina.go @@ -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 diff --git a/gs/game/world_manager.go b/gs/game/world_manager.go index 58aa72b6..9638f64b 100644 --- a/gs/game/world_manager.go +++ b/gs/game/world_manager.go @@ -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( @@ -94,16 +96,18 @@ func (w *WorldManager) InitBigWorld(owner *model.Player) { } type World struct { - id uint32 - owner *model.Player - playerMap map[uint32]*model.Player - sceneMap map[uint32]*Scene - entityIdCounter uint32 - worldLevel uint8 - multiplayer bool - mpLevelEntityId uint32 - chatMsgList []*proto.ChatInfo - aoiManager *aoi.AoiManager // 当前世界地图的aoi管理器 + id uint32 + owner *model.Player + playerMap map[uint32]*model.Player + sceneMap map[uint32]*Scene + entityIdCounter uint32 + worldLevel uint8 + multiplayer bool + 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) { diff --git a/gs/model/player.go b/gs/model/player.go index 500570c2..264aa3d7 100644 --- a/gs/model/player.go +++ b/gs/model/player.go @@ -53,22 +53,22 @@ type Player struct { ChatMsgMap map[uint32][]*ChatMsg `bson:"chatMsgMap"` // 聊天信息 IsGM uint8 `bson:"isGM"` // 管理员权限等级 // 在线数据 - EnterSceneToken uint32 `bson:"-"` // 玩家的世界进入令牌 - DbState int `bson:"-"` // 数据库存档状态 - WorldId uint32 `bson:"-"` // 所在的世界id - PeerId uint32 `bson:"-"` // 多人世界的玩家编号 - GameObjectGuidCounter uint64 `bson:"-"` // 游戏对象guid计数器 - ClientTime uint32 `bson:"-"` // 玩家客户端的本地时钟 - ClientRTT uint32 `bson:"-"` // 玩家客户端往返时延 - GameObjectGuidMap map[uint64]GameObject `bson:"-"` // 游戏对象guid映射表 - Online bool `bson:"-"` // 在线状态 - Pause bool `bson:"-"` // 暂停状态 - SceneLoadState int `bson:"-"` // 场景加载状态 - CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间 - StaminaInfo *StaminaInfo `bson:"-"` // 耐力临时数据 - ClientSeq uint32 `bson:"-"` // 客户端发包请求的序号 - CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry] - AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry] + EnterSceneToken uint32 `bson:"-"` // 玩家的世界进入令牌 + DbState int `bson:"-"` // 数据库存档状态 + WorldId uint32 `bson:"-"` // 所在的世界id + PeerId uint32 `bson:"-"` // 多人世界的玩家编号 + GameObjectGuidCounter uint64 `bson:"-"` // 游戏对象guid计数器 + ClientTime uint32 `bson:"-"` // 玩家客户端的本地时钟 + ClientRTT uint32 `bson:"-"` // 玩家客户端往返时延 + GameObjectGuidMap map[uint64]GameObject `bson:"-"` // 游戏对象guid映射表 + Online bool `bson:"-"` // 在线状态 + Pause bool `bson:"-"` // 暂停状态 + SceneLoadState int `bson:"-"` // 场景加载状态 + CoopApplyMap map[uint32]int64 `bson:"-"` // 敲门申请的玩家uid及时间 + StaminaInfo *StaminaInfo `bson:"-"` // 耐力临时数据 + ClientSeq uint32 `bson:"-"` // 客户端发包请求的序号 + CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry] `bson:"-"` + AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry] `bson:"-"` } func (p *Player) GetNextGameObjectGuid() uint64 { diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index 817bb758..0903a838 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -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{}) // 设置生日请求