diff --git a/gs/game/game.go b/gs/game/game.go index e7c0faf5..a1f2aafc 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -87,7 +87,9 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs r.ai = r.CreateRobot(uid, name, sign) WORLD_MANAGER.InitAiWorld(r.ai) COMMAND_MANAGER.SetSystem(r.ai) + COMMAND_MANAGER.gmCmd.GMUnlockAllPoint(r.ai.PlayerID, 3) USER_MANAGER.SetRemoteUserOnlineState(BigWorldAiUid, true, mainGsAppid) + aiWorld := WORLD_MANAGER.GetAiWorld() if r.IsMainGs() { // TODO 测试 for i := 1; i < 100; i++ { @@ -105,13 +107,52 @@ func NewGameManager(dao *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gs AvatarTeamGuidList: []uint64{dbAvatar.AvatarMap[avatarId].Guid}, CurAvatarGuid: dbAvatar.AvatarMap[avatarId].Guid, }) - pos := &model.Vector{ - X: 1800.0 + random.GetRandomFloat64(-100.0, 100.0), - Y: 195.0 + random.GetRandomFloat64(0.0, 5.0), - Z: -1500.0 + random.GetRandomFloat64(-100.0, 100.0), + r.JoinPlayerSceneReq(robot, &proto.JoinPlayerSceneReq{ + TargetUid: r.ai.PlayerID, + }) + r.EnterSceneReadyReq(robot, &proto.EnterSceneReadyReq{ + EnterSceneToken: aiWorld.GetEnterSceneToken(), + }) + r.SceneInitFinishReq(robot, &proto.SceneInitFinishReq{ + EnterSceneToken: aiWorld.GetEnterSceneToken(), + }) + r.EnterSceneDoneReq(robot, &proto.EnterSceneDoneReq{ + EnterSceneToken: aiWorld.GetEnterSceneToken(), + }) + r.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{ + EnterSceneToken: aiWorld.GetEnterSceneToken(), + }) + activeAvatarId := aiWorld.GetPlayerActiveAvatarId(robot) + entityMoveInfo := &proto.EntityMoveInfo{ + EntityId: aiWorld.GetPlayerWorldAvatarEntityId(robot, activeAvatarId), + MotionInfo: &proto.MotionInfo{ + Pos: &proto.Vector{ + X: float32(1800.0 + random.GetRandomFloat64(-100.0, 100.0)), + Y: float32(195.0 + random.GetRandomFloat64(0.0, 5.0)), + Z: float32(-1500.0 + random.GetRandomFloat64(-100.0, 100.0)), + }, + Rot: &proto.Vector{ + X: 0, + Y: float32(random.GetRandomFloat64(0.0, 360.0)), + Z: 0, + }, + State: proto.MotionState_MOTION_STANDBY, + }, + SceneTime: 0, + ReliableSeq: 0, } - robot.Pos = pos - r.UserWorldAddPlayer(WORLD_MANAGER.GetAiWorld(), robot) + combatData, err := pb.Marshal(entityMoveInfo) + if err != nil { + continue + } + r.CombatInvocationsNotify(robot, &proto.CombatInvocationsNotify{ + InvokeList: []*proto.CombatInvokeEntry{{ + CombatData: combatData, + ForwardType: proto.ForwardType_FORWARD_TO_ALL_EXCEPT_CUR, + ArgumentType: proto.CombatTypeArgument_ENTITY_MOVE, + }}, + }) + r.UnionCmdNotify(robot, &proto.UnionCmdNotify{}) } } r.run() @@ -145,8 +186,20 @@ func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player { robot := USER_MANAGER.GetOnlineUser(uid) robot.DbState = model.DbNormal g.SetPlayerBornDataReq(robot, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: name}) - robot.SceneLoadState = model.SceneEnterDone robot.Signature = sign + world := WORLD_MANAGER.GetWorldByID(robot.WorldId) + g.EnterSceneReadyReq(robot, &proto.EnterSceneReadyReq{ + EnterSceneToken: world.GetEnterSceneToken(), + }) + g.SceneInitFinishReq(robot, &proto.SceneInitFinishReq{ + EnterSceneToken: world.GetEnterSceneToken(), + }) + g.EnterSceneDoneReq(robot, &proto.EnterSceneDoneReq{ + EnterSceneToken: world.GetEnterSceneToken(), + }) + g.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{ + EnterSceneToken: world.GetEnterSceneToken(), + }) return robot } diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index df8868f4..279772e3 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -252,15 +252,12 @@ func (w *World) AddEnterSceneContext(ctx *EnterSceneContext) uint32 { return w.enterSceneToken } -func (w *World) GetLastEnterSceneContextBySceneIdAndUid(sceneId uint32, uid uint32) *EnterSceneContext { +func (w *World) GetLastEnterSceneContextByUid(uid uint32) *EnterSceneContext { for token := w.enterSceneToken; token >= 5000; token -= 100 { ctx, exist := w.enterSceneContextMap[token] if !exist { continue } - if ctx.OldSceneId != sceneId { - continue - } if ctx.Uid != uid { continue } @@ -269,6 +266,19 @@ func (w *World) GetLastEnterSceneContextBySceneIdAndUid(sceneId uint32, uid uint return nil } +func (w *World) RemoveAllEnterSceneContextByUid(uid uint32) { + for token := w.enterSceneToken; token >= 5000; token -= 100 { + ctx, exist := w.enterSceneContextMap[token] + if !exist { + continue + } + if ctx.Uid != uid { + continue + } + delete(w.enterSceneContextMap, token) + } +} + func (w *World) GetWorldLevel() uint8 { return w.worldLevel } @@ -309,7 +319,6 @@ func (w *World) GetPlayerPeerId(player *model.Player) uint32 { peerId = uint32(peerIdIndex) + 1 } } - // logger.Debug("get player peer id is: %v, uid: %v", peerId, player.PlayerID) return peerId } @@ -362,12 +371,6 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) { scene := w.GetSceneById(sceneId) scene.AddPlayer(player) w.InitPlayerTeamEntityId(player) - if WORLD_MANAGER.IsBigWorld(w) { - activeAvatarId := w.GetPlayerActiveAvatarId(player) - worldAvatar := w.GetPlayerWorldAvatar(player, activeAvatarId) - w.bigWorldAoi.AddObjectToGridByPos(int64(player.PlayerID), worldAvatar, - float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) - } } func (w *World) RemovePlayer(player *model.Player) { @@ -375,6 +378,7 @@ func (w *World) RemovePlayer(player *model.Player) { w.peerList = append(w.peerList[:peerId-1], w.peerList[peerId:]...) scene := w.sceneMap[player.SceneId] scene.RemovePlayer(player) + w.RemoveAllEnterSceneContextByUid(player.PlayerID) delete(w.playerMap, player.PlayerID) delete(w.playerFirstEnterMap, player.PlayerID) delete(w.multiplayerTeam.localTeamMap, player.PlayerID) @@ -382,8 +386,6 @@ func (w *World) RemovePlayer(player *model.Player) { delete(w.multiplayerTeam.localTeamEntityMap, player.PlayerID) if WORLD_MANAGER.IsBigWorld(w) { w.RemoveMultiplayerTeam(player) - w.bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerID), - float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) } else { if player.PlayerID != w.owner.PlayerID { w.UpdateMultiplayerTeam() @@ -658,7 +660,7 @@ func (w *World) copyLocalTeamToWorld(start int, end int, peerId uint32) { } } -// TODO 为了实现大世界无限人数写的 +// 为了实现大世界无限人数写的 // 现在看来把世界里所有人放进队伍里发给客户端超过8个客户端会崩溃 // 看来还是不能简单的走通用逻辑 需要对大世界场景队伍做特殊处理 欺骗客户端其他玩家仅仅以场景角色实体的形式出现 diff --git a/gs/game/lua_func.go b/gs/game/lua_func.go index b7127476..2a474b1c 100644 --- a/gs/game/lua_func.go +++ b/gs/game/lua_func.go @@ -101,6 +101,18 @@ func GetContextGroup(player *model.Player, ctx *lua.LTable, luaState *lua.LState return group } +func GetContextDbSceneGroup(player *model.Player, groupId uint32) *model.DbSceneGroup { + world := WORLD_MANAGER.GetWorldByID(player.WorldId) + if world == nil { + return nil + } + owner := world.GetOwner() + dbWorld := owner.GetDbWorld() + dbScene := dbWorld.GetSceneById(player.SceneId) + dbSceneGroup := dbScene.GetSceneGroupById(groupId) + return dbSceneGroup +} + // RegLuaScriptLibFunc 注册LUA侧ScriptLib调用的Golang方法 func RegLuaScriptLibFunc() { gdconf.RegScriptLibFunc("GetEntityType", GetEntityType) @@ -497,9 +509,11 @@ func GetGroupVariableValue(luaState *lua.LState) int { return 1 } name := luaState.ToString(2) - dbWorld := player.GetDbWorld() - dbScene := dbWorld.GetSceneById(player.SceneId) - dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupId)) + dbSceneGroup := GetContextDbSceneGroup(player, uint32(groupId)) + if dbSceneGroup == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } value := dbSceneGroup.GetVariableByName(name) luaState.Push(lua.LNumber(value)) return 1 @@ -518,9 +532,11 @@ func GetGroupVariableValueByGroup(luaState *lua.LState) int { } name := luaState.ToString(2) groupId := luaState.ToInt(3) - dbWorld := player.GetDbWorld() - dbScene := dbWorld.GetSceneById(player.SceneId) - dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupId)) + dbSceneGroup := GetContextDbSceneGroup(player, uint32(groupId)) + if dbSceneGroup == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } value := dbSceneGroup.GetVariableByName(name) luaState.Push(lua.LNumber(value)) return 1 @@ -544,9 +560,11 @@ func SetGroupVariableValue(luaState *lua.LState) int { } name := luaState.ToString(2) value := luaState.ToInt(3) - dbWorld := player.GetDbWorld() - dbScene := dbWorld.GetSceneById(player.SceneId) - dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupId)) + dbSceneGroup := GetContextDbSceneGroup(player, uint32(groupId)) + if dbSceneGroup == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } dbSceneGroup.SetVariable(name, int32(value)) luaState.Push(lua.LNumber(0)) return 1 @@ -566,9 +584,11 @@ func SetGroupVariableValueByGroup(luaState *lua.LState) int { name := luaState.ToString(2) value := luaState.ToInt(3) groupId := luaState.ToInt(4) - dbWorld := player.GetDbWorld() - dbScene := dbWorld.GetSceneById(player.SceneId) - dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupId)) + dbSceneGroup := GetContextDbSceneGroup(player, uint32(groupId)) + if dbSceneGroup == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } dbSceneGroup.SetVariable(name, int32(value)) luaState.Push(lua.LNumber(0)) return 1 @@ -592,9 +612,11 @@ func ChangeGroupVariableValue(luaState *lua.LState) int { } name := luaState.ToString(2) change := luaState.ToInt(3) - dbWorld := player.GetDbWorld() - dbScene := dbWorld.GetSceneById(player.SceneId) - dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupId)) + dbSceneGroup := GetContextDbSceneGroup(player, uint32(groupId)) + if dbSceneGroup == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } value := dbSceneGroup.GetVariableByName(name) dbSceneGroup.SetVariable(name, value+int32(change)) luaState.Push(lua.LNumber(0)) @@ -615,9 +637,11 @@ func ChangeGroupVariableValueByGroup(luaState *lua.LState) int { name := luaState.ToString(2) change := luaState.ToInt(3) groupId := luaState.ToInt(4) - dbWorld := player.GetDbWorld() - dbScene := dbWorld.GetSceneById(player.SceneId) - dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupId)) + dbSceneGroup := GetContextDbSceneGroup(player, uint32(groupId)) + if dbSceneGroup == nil { + luaState.Push(lua.LNumber(-1)) + return 1 + } value := dbSceneGroup.GetVariableByName(name) dbSceneGroup.SetVariable(name, value+int32(change)) luaState.Push(lua.LNumber(0)) diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index e01d0694..72ed83ac 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -363,6 +363,10 @@ func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene * // 通知老格子里的其它玩家 自己消失 for otherPlayerId := range oldOtherWorldAvatarMap { otherPlayer := USER_MANAGER.GetOnlineUser(uint32(otherPlayerId)) + if otherPlayer == nil { + logger.Error("get player is nil, target uid: %v, uid: %v", otherPlayerId, player.PlayerID) + continue + } g.RemoveSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MISS, []uint32{activeWorldAvatar.GetAvatarEntityId()}) } } @@ -381,6 +385,10 @@ func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene * // 通知新格子里的其他玩家 自己出现 for otherPlayerId := range newOtherWorldAvatarMap { otherPlayer := USER_MANAGER.GetOnlineUser(uint32(otherPlayerId)) + if otherPlayer == nil { + logger.Error("get player is nil, target uid: %v, uid: %v", otherPlayerId, player.PlayerID) + continue + } sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, player, world.GetPlayerActiveAvatarId(player)) g.AddSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MEET, []*proto.SceneEntityInfo{sceneEntityInfoAvatar}) } diff --git a/gs/game/player_multiplayer.go b/gs/game/player_multiplayer.go index d7bccd5c..13c13a96 100644 --- a/gs/game/player_multiplayer.go +++ b/gs/game/player_multiplayer.go @@ -415,6 +415,10 @@ func (g *Game) UserWorldRemovePlayer(world *World, player *model.Player) { } world.RemovePlayer(player) + if WORLD_MANAGER.IsBigWorld(world) { + bigWorldAoi := world.GetBigWorldAoi() + bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerID), float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) + } player.WorldId = 0 if world.GetOwner().PlayerID == player.PlayerID { // 房主离开销毁世界 diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 37783a95..26149dd7 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -266,7 +266,7 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) { activeAvatarId := world.GetPlayerActiveAvatarId(player) activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId) - if WORLD_MANAGER.IsBigWorld(world) && !world.IsPlayerFirstEnter(player) { + if WORLD_MANAGER.IsBigWorld(world) { bigWorldAoi := world.GetBigWorldAoi() bigWorldAoi.AddObjectToGridByPos(int64(player.PlayerID), activeWorldAvatar, float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z)) } @@ -679,7 +679,6 @@ func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*g func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) { group := scene.GetGroupById(uint32(groupConfig.Id)) if group != nil { - logger.Error("group already exist, groupId: %v, uid: %v", groupConfig.Id, player.PlayerID) return } initSuiteId := groupConfig.GroupInitConfig.Suite diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 2804fb96..3607e53e 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -22,7 +22,13 @@ func (g *Game) SceneTransToPointReq(player *model.Player, payloadMsg pb.Message) g.SendError(cmd.SceneTransToPointRsp, player, &proto.SceneTransToPointRsp{}, proto.Retcode_RET_IN_TRANSFER) return } - dbWorld := player.GetDbWorld() + world := WORLD_MANAGER.GetWorldByID(player.WorldId) + if world == nil { + g.SendError(cmd.SceneTransToPointRsp, player, &proto.SceneTransToPointRsp{}) + return + } + owner := world.GetOwner() + dbWorld := owner.GetDbWorld() dbScene := dbWorld.GetSceneById(req.SceneId) if dbScene == nil { g.SendError(cmd.SceneTransToPointRsp, player, &proto.SceneTransToPointRsp{}, proto.Retcode_RET_POINT_NOT_UNLOCKED) @@ -60,7 +66,13 @@ func (g *Game) SceneTransToPointReq(player *model.Player, payloadMsg pb.Message) func (g *Game) UnlockTransPointReq(player *model.Player, payloadMsg pb.Message) { req := payloadMsg.(*proto.UnlockTransPointReq) - dbWorld := player.GetDbWorld() + world := WORLD_MANAGER.GetWorldByID(player.WorldId) + if world == nil { + g.SendError(cmd.UnlockTransPointRsp, player, &proto.UnlockTransPointRsp{}) + return + } + owner := world.GetOwner() + dbWorld := owner.GetDbWorld() dbScene := dbWorld.GetSceneById(req.SceneId) if dbScene == nil { g.SendError(cmd.UnlockTransPointRsp, player, &proto.UnlockTransPointRsp{}, proto.Retcode_RET_POINT_NOT_UNLOCKED) @@ -86,7 +98,13 @@ func (g *Game) UnlockTransPointReq(player *model.Player, payloadMsg pb.Message) func (g *Game) GetScenePointReq(player *model.Player, payloadMsg pb.Message) { req := payloadMsg.(*proto.GetScenePointReq) - dbWorld := player.GetDbWorld() + world := WORLD_MANAGER.GetWorldByID(player.WorldId) + if world == nil { + g.SendError(cmd.GetScenePointRsp, player, &proto.GetScenePointRsp{}) + return + } + owner := world.GetOwner() + dbWorld := owner.GetDbWorld() dbScene := dbWorld.GetSceneById(req.SceneId) if dbScene == nil { g.SendError(cmd.GetScenePointRsp, player, &proto.GetScenePointRsp{}) @@ -280,18 +298,18 @@ func (g *Game) PlayerQuitDungeonReq(player *model.Player, payloadMsg pb.Message) logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID) return } - ctx := world.GetLastEnterSceneContextBySceneIdAndUid(3, player.PlayerID) + ctx := world.GetLastEnterSceneContextByUid(player.PlayerID) if ctx == nil { return } - pointDataConfig := gdconf.GetScenePointBySceneIdAndPointId(3, int32(ctx.OldDungeonPointId)) + pointDataConfig := gdconf.GetScenePointBySceneIdAndPointId(int32(ctx.OldSceneId), int32(ctx.OldDungeonPointId)) if pointDataConfig == nil { return } g.TeleportPlayer( player, proto.EnterReason_ENTER_REASON_DUNGEON_QUIT, - 3, + ctx.OldSceneId, &model.Vector{X: pointDataConfig.TranPos.X, Y: pointDataConfig.TranPos.Y, Z: pointDataConfig.TranPos.Z}, &model.Vector{X: pointDataConfig.TranRot.X, Y: pointDataConfig.TranRot.Y, Z: pointDataConfig.TranRot.Z}, 0,