/// <summary> /// 新房间 /// </summary> /// <param name="roomManager_">房主</param> /// <param name="config_">房间配置</param> public Room(IPlayerJoinRoom roomManager_, IRoomConfig config_) : this() { Id = Id + roomManager_.Id; Name = config_.Name; IsFull = config_.IsFull; Timelimit = config_.Timelimit; IsOpening = config_.IsOpening; SecretKey = config_.SecretKey; TicketPrice = config_.TicketPrice; InningGame = config_.InningGame; InningGame.IRoom = this; if (InningGame.IGameProject.PlayerCountLeast <= config_.PlayerCountTopLimit && config_.PlayerCountTopLimit <= InningGame.IGameProject.PlayerCountLimit) { PlayerCountTopLimit = config_.PlayerCountTopLimit; } else { PlayerCountTopLimit = InningGame.IGameProject.PlayerCountLimit; } if (PlayerCountTopLimit == 1) { IsFull = true; } RoomManager = roomManager_; Affiche = config_.Affiche; IsRandom = config_.IsRandom; Players.Add(roomManager_); InningGame.PlaySitDown(roomManager_); }
/// <summary> /// 玩家加入 /// </summary> /// <param name="player_">玩家</param> public bool AddPlayer(IPlayerJoinRoom player_) { if (Players.Exists(p => p.Id == player_.Id)) { return(true); } if (Players.Count >= PlayerCountTopLimit) { AddPlayerFailRoomFullEvent?.Invoke(player_, new PlayerEventArgs(player_)); return(false); } if (player_.Id != RoomManager.Id && TicketPrice > 0 && player_.Account < TicketPrice) { PlayCanNotPayTicketEvent?.Invoke(player_, new PlayerEventArgs(player_)); return(false); } if (player_.Id != RoomManager.Id) { if (!player_.DecutMoney(TicketPrice)) { return(false); } } if (!Players.Exists(p => p.Id == player_.Id)) { Players.Add(player_); try { InningGame.PlaySitDown(player_); } catch (Exception) { throw; } finally { CheckFull(); //AddPlayerSuccessEvent?.Invoke(this, new PlayerEventArgs(player_)); AddPlayer_SuccessEvent?.Invoke(this, new PlayerEventArgs(player_)); } } return(true); }
/// <summary> /// 玩家离开房间 /// </summary> /// <param name="player_">玩家</param> public void RemovePlayer(IPlayerJoinRoom player_) { ISeat seat = InningGame.GetSeatByPlayerId(player_.Id); if (seat != null) { seat.PlayLeave(); } var realPlayer = Players.Find(p => p.Id == player_.Id); Players.Remove(realPlayer); if (player_.Id == RoomManager.Id && Players.Count > 0) { ChanageManger(Players[0]); } RemovePlayer_SuccessEvent?.Invoke(this, new PlayerEventArgs(player_)); CheckFull(); InningGame.CheckSeatCountEnoughWhenRunning(); }