public Player Sit(long accountId, int position) { var player = GetPlayer(accountId); if (player == null) { throw new PlayerNotFoundException(); } lock (_locker) { if (Sitting.Values.ToList().Exists(x => x != null && x.AccountId == accountId)) { throw new AlreadySitException(); } if (Sitting[position] == null) { Sitting.AddOrUpdate(position, player, (k, v) => v = player); } else { throw new AlreadySitException(); } return(player); } }
public void RemovePlayer(Player player, int reason) { lock (_locker) { if (_players.TryRemove(player.AccountId, out player)) { player.LeaveGame(); var lstConnection = _connectionHandler.GetConnections(player.AccountId); foreach (var connection in lstConnection) { _hubContext.Groups.Remove(connection, $"room_{Id}").Wait(); } _hubContext.Clients.Clients(lstConnection.ToList()).playerLeave(player.AccountId, reason, 0, 0); bool found = false; foreach (var s in Sitting) { if (s.Value != null && s.Value.AccountId == player.AccountId) { Player p = null; Sitting.AddOrUpdate(s.Key, p, (k, v) => v = p); _hubContext.Clients.Group($"room_{Id}").playerLeave(player.AccountId, reason, TotalPlayer, MaxPlayer); found = true; break; } } if (RoomType == RoomType.TWELVE) { if (player.AccountId == Banker) { Banker = -1; } } if (!found) { _hubContext.Clients.Group($"room_{Id}").ccu(TotalPlayer, MaxPlayer); } if (_players.Count == 0 && _currentState == State.WAITING) { this._deactive = true; this._timer.Change(-1, -1); _gameManager.DeactiveSession(this.Id); } else if (_players.Count == 0) { NextState(State.SHOW_RESULT, true); } } } }
public int AddPlayer(Player player) { long balance = this.MoneyType == MoneyType.GOLD ? player.Gold : player.Coin; if (balance < BetValue) { throw new NotEnoughMoneyException(); } lock (_locker) { if (this._deactive) { throw new RoomHasBeenDeactiveException(); } if (_players.Count == MaxPlayer) { throw new RoomFullException(); } player.RoomId = Id; player.SessionId = SessionId; _players.AddOrUpdate(player.AccountId, player, (k, v) => v = player); if (RoomType == RoomType.TWELVE & Banker == -1) { if (balance >= _logic.GetWinnerMulti(Gate.Even) * 2) { Banker = player.AccountId; } } this._alivePlayers.Enqueue(player.AccountId); foreach (var s in Sitting) { if (s.Value == null) { Sitting.AddOrUpdate(s.Key, player, (k, v) => v = player); return(s.Key); } } return(0); } }