//开始游戏 并创建房间记录 返回房间ID private static void RoomStartGame(this MatchRoomComponent matchRoomComponent, long toyGameId, M2S_StartGame message) { try { //记录玩家信息 MatchRoom matchRoom = MatchRoomFactory.CreateRandomMatchRoom(toyGameId, matchRoomComponent.RandomRoomId(), message.MatchPlayerInfos, message.RoomConfig); matchRoomComponent.MatchRoomDic[matchRoom.RoomId] = matchRoom; for (int i = 0; i < message.MatchPlayerInfos.count; i++) { if (message.MatchPlayerInfos[i].IsAI) { continue;//如果是AI不记录 } matchRoomComponent.UserIdInRoomIdDic[message.MatchPlayerInfos[i].User.UserId] = matchRoom; } message.RoomType = RoomType.Match; Session toyGameSession = Game.Scene.GetComponent <NetInnerSessionComponent>().GetGameServerSession(toyGameId); message.RoomId = matchRoom.RoomId; toyGameSession.Send(message); } catch (Exception e) { Log.Error(e); throw; } }
//创建房间 public static MatchRoom CreateRoom(this MatchRoomComponent matchRoomComponent, RepeatedField <int> roomConfigLists, int friendsCircleId, long toyGameId, long userJewelNum, IResponse iResponse) { MatchRoom matchRoom = MatchRoomFactory.Create(roomConfigLists, toyGameId, matchRoomComponent.RandomRoomId(), friendsCircleId, userJewelNum, iResponse); if (matchRoom == null) { return(null);//为空表示创建房间失败 } matchRoomComponent.MatchRoomDic.Add(matchRoom.RoomId, matchRoom); matchRoomComponent.AddFriendsCircleRoom(matchRoom); return(matchRoom); }