public static async Task GamerContinue(Gamer gamer) { try { Log.Info($"玩家{gamer.UserID}继续游戏"); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null) { return; } GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); OrderControllerComponent orderControllerComponent = room.GetComponent <OrderControllerComponent>(); gamer.ReadyTimeOut = 0; List <GamerInfo> Gamers = new List <GamerInfo>(); for (int i = 0; i < room.GetAll().Length; i++) { Gamer _gamer = room.GetAll()[i]; if (_gamer == null) { continue; } GamerInfo gamerInfo = new GamerInfo(); gamerInfo.UserID = _gamer.UserID; gamerInfo.SeatIndex = room.GetGamerSeat(_gamer.UserID); gamerInfo.IsReady = _gamer.IsReady; PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(gamerInfo.UserID); //判断金币是否不够 if (!room.IsFriendRoom) { if (playerBaseInfo.GoldNum < gameControllerComponent.RoomConfig.MinThreshold) { room.GamerBroadcast(_gamer, new Actor_GamerReadyTimeOut() { Message = "金币不足" }); room.Remove(_gamer.UserID); _gamer.Dispose(); if (room.Count == 0) { GameHelp.RoomDispose(room); return; } continue; } } PlayerInfo playerInfo = PlayerInfoFactory.Create(playerBaseInfo); gamerInfo.playerInfo = playerInfo; Gamers.Add(gamerInfo); } Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom() { RoomType = (int)gameControllerComponent.RoomConfig.Id, Gamers = Gamers }; if (room.IsFriendRoom) { actorGamerEnterRoom.RoomId = gameControllerComponent.RoomConfig.FriendRoomId; actorGamerEnterRoom.MasterUserId = gameControllerComponent.RoomConfig.MasterUserId; actorGamerEnterRoom.JuCount = gameControllerComponent.RoomConfig.JuCount; actorGamerEnterRoom.Multiples = gameControllerComponent.RoomConfig.Multiples; actorGamerEnterRoom.CurrentJuCount = room.CurrentJuCount; } room.Broadcast(actorGamerEnterRoom); // if (room.IsFriendRoom) // { await Actor_GamerReadyHandler.GamerReady(gamer, new Actor_GamerReady() { }); // } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
protected override async void Run(Session session, G2M_PlayerEnterRoom message, Action <M2G_PlayerEnterRoom> reply) { M2G_PlayerEnterRoom response = new M2G_PlayerEnterRoom(); //Log.Info("G2M_GamerEnterRoomHandler" + JsonHelper.ToJson(message)); try { RoomComponent roomCompnent = Game.Scene.GetComponent <RoomComponent>(); Gamer gamer = null; Room room = null; foreach (var _room in roomCompnent.rooms.Values) { room = _room; gamer = room.Get(message.UserId); if (gamer != null) { Log.Info("找到房间:" + _room.Id); break; } } //断线重连 if (gamer != null) { //在空闲房间内 if (room.State == RoomState.Idle) { response.Message = "已经进入房间"; response.Error = ErrorCode.ERR_Common; Log.Error("玩家多次进入空闲房间"); room.Remove(gamer.UserID); reply(response); return; } DeskComponent deskComponent = room.GetComponent <DeskComponent>(); //重新更新actor gamer.PlayerID = message.PlayerId; gamer.GetComponent <UnitGateComponent>().GateSessionActorId = message.SessionId; //短线重连 Actor_GamerReconnet reconnet = new Actor_GamerReconnet(); foreach (var _gamer in room.GetAll()) { if (_gamer == null) { Log.Error($"断线重连后玩家为空"); continue; } GamerData gamerData = new GamerData(); HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); if (handCardsComponent == null) { Log.Error($"{_gamer.UserID}断线重连后玩家的手牌为空,移除玩家"); continue; // room.Remove(_gamer.UserID); // //房间没人就释放 // if (room.seats.Count == 0) // { // roomCompnent.RemoveRoom(room); // room.Dispose(); // } // return; } List <MahjongInfo> handCards = handCardsComponent.GetAll(); gamerData.handCards = handCards; gamerData.faceCards = handCardsComponent.FaceCards; gamerData.playCards = handCardsComponent.PlayCards; //添加碰刚的uid foreach (var pengOrBar in handCardsComponent.PengOrBars) { //碰 if (pengOrBar.OperateType == OperateType.Peng) { gamerData.pengCards.Add(new MahjongInfo() { weight = (byte)pengOrBar.Weight }); gamerData.OperatedPengUserIds.Add(pengOrBar.UserId); } //杠 else { gamerData.gangCards.Add(new MahjongInfo() { weight = (byte)pengOrBar.Weight }); gamerData.OperatedGangUserIds.Add(pengOrBar.UserId); } } gamerData.IsBanker = handCardsComponent.IsBanker; gamerData.UserID = _gamer.UserID; gamerData.SeatIndex = room.GetGamerSeat(_gamer.UserID); gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(_gamer.UserID); gamerData.IsTrusteeship = gamer.IsTrusteeship; PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(_gamer.UserID); PlayerInfo playerInfo = PlayerInfoFactory.Create(playerBaseInfo); gamerData.playerInfo = playerInfo; reconnet.Gamers.Add(gamerData); } reconnet.RestCount = deskComponent.RestLibrary.Count; reconnet.RoomType = (int)room.GetComponent <GameControllerComponent>().RoomConfig.Id; if (room.IsFriendRoom) { GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); reconnet.RoomId = gameControllerComponent.RoomConfig.FriendRoomId; reconnet.MasterUserId = gameControllerComponent.RoomConfig.MasterUserId; reconnet.JuCount = gameControllerComponent.RoomConfig.JuCount; reconnet.Multiples = gameControllerComponent.RoomConfig.Multiples; reconnet.CurrentJuCount = room.CurrentJuCount; } room.GamerReconnect(gamer, reconnet); gamer.isOffline = false; gamer.RemoveComponent <TrusteeshipComponent>(); Log.Info($"玩家{message.UserId}断线重连"); gamer.StartTime = DateTime.Now; } else { Log.Info($"{message.UserId}进入房间"); gamer = await GamerFactory.Create(message.PlayerId, message.UserId); await gamer.AddComponent <MailBoxComponent>().AddLocation(); gamer.AddComponent <UnitGateComponent, long>(message.SessionId); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); //获得空闲的房间 Room idleRoom; if (message.RoomType == 3) { idleRoom = roomComponent.GetFriendRoomById(message.RoomId); if (idleRoom == null) { response.Error = ErrorCode.ERR_Common; response.Message = "房间号不存在"; reply(response); return; } if (idleRoom.Count == 4) { response.Error = ErrorCode.ERR_Common; response.Message = "房间人数已满"; reply(response); return; } } else { idleRoom = roomComponent.GetIdleRoomById(message.RoomType); if (idleRoom == null) { idleRoom = RoomFactory.Create(message.RoomType); roomComponent.Add(idleRoom); } } idleRoom.Add(gamer); await idleRoom.BroadGamerEnter(gamer.UserID); } response.GameId = gamer.Id; reply(response); if (message.RoomType == 3) { await Actor_GamerReadyHandler.GamerReady(gamer, new Actor_GamerReady() { }); } } catch (Exception e) { ReplyError(response, e, reply); } await Task.CompletedTask; }
/// <summary> /// 加入房间Actor /// </summary> /// <param name="self"></param> /// <param name="userId"></param> public static async Task BroadGamerEnter(this Room self, long userId) { List <GamerInfo> gamerInfos = new List <GamerInfo>(); long roomType = self.GetComponent <GameControllerComponent>().RoomConfig.Id; GamerInfo currentInfo = null; for (int i = 0; i < self.GetAll().Length; i++) { Gamer _gamer = self.GetAll()[i]; if (_gamer == null) { continue; } GamerInfo gamerInfo = new GamerInfo(); gamerInfo.UserID = _gamer.UserID; gamerInfo.SeatIndex = self.GetGamerSeat(_gamer.UserID); gamerInfo.IsReady = _gamer.IsReady; if (_gamer.playerBaseInfo == null) { _gamer.playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(gamerInfo.UserID); } PlayerInfo playerInfo = PlayerInfoFactory.Create(_gamer.playerBaseInfo); gamerInfo.playerInfo = playerInfo; if (gamerInfo.UserID == userId) { currentInfo = gamerInfo; } gamerInfos.Add(gamerInfo); } foreach (var _gamer in self.GetAll()) { if (_gamer == null || _gamer.isOffline) { continue; } //第一次进入 if (_gamer.UserID == userId) { Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom() { RoomType = (int)roomType, Gamers = gamerInfos, }; if (roomType == 3) { GameControllerComponent gameControllerComponent = self.GetComponent <GameControllerComponent>(); actorGamerEnterRoom.RoomId = gameControllerComponent.RoomConfig.FriendRoomId; actorGamerEnterRoom.MasterUserId = gameControllerComponent.RoomConfig.MasterUserId; actorGamerEnterRoom.JuCount = gameControllerComponent.RoomConfig.JuCount; actorGamerEnterRoom.Multiples = gameControllerComponent.RoomConfig.Multiples; actorGamerEnterRoom.CurrentJuCount = self.CurrentJuCount; } self.GamerBroadcast(_gamer, actorGamerEnterRoom); } //有人加入 else { Actor_GamerJionRoom actorGamerJionRoom = new Actor_GamerJionRoom() { Gamer = currentInfo }; self.GamerBroadcast(_gamer, actorGamerJionRoom); } } }