//// Everybody can check their permissions //private void ListPermissions(Command command) //{ // try // { // List<string> flags = new List<string>(CurrentPlayer.Character.Data.Permissions.ToString().Split(',')); // BaseScript.TriggerEvent("Chat.Message", "", "#AAAAAA", $"Permissions: {String.Join(", ", flags)}"); // } // catch (Exception ex) // { // Log.Error($"ListPermissions error: {ex.Message}"); // } //} private void JailCharacter(Command command) { try { if (command.Args.Count >= 2) { int targetServerId = command.Args.GetInt32(0); if (!playerList.Any(p => p.ServerId == targetServerId)) { BaseScript.TriggerEvent("Chat.Message", "", "#AAAAAA", "That player ID could not be found!"); return; } int jailTime = command.Args.GetInt32(1); string description = command.Args.Count >= 3 ? command.Args.ToString().Substring(command.Args.Get(0).Length + 1 + command.Args.Get(1).Length + 1) : ""; BaseScript.TriggerServerEvent("Police.ImprisonCharacter", targetServerId, jailTime, description); } else { BaseScript.TriggerEvent("Chat.Message", "", "#AAAAAA", "Invalid parameters provided; you need to provide at least two numeric arguments."); } } catch (Exception ex) { Log.Error($"JailCharacter error: {ex.Message}"); } }
private async Task RunTimerAsync() { CommandContainer !.ManuelFinish = true; CommandContainer.IsExecuting = true; _timer.Enabled = false; if (_basicData.MultiPlayer == true) { if (_basicData.Client == true) { _mainGame !.Check !.IsEnabled = true; //maybe needs to be after you checked. or it could get hosed. return; //has to wait for host. } if (_mainGame !.PlayerList.Any(Items => Items.PlayerCategory == EnumPlayerCategory.Computer)) { await _mainGame.FinishAsync(); return; } await _mainGame.Network !.SendAllAsync("callnextnumber"); await _mainGame.CallNextNumberAsync(); return; } await _mainGame !.FinishAsync(); }
protected override async Task ProtectedAfterRollingAsync() { SingleInfo !.Score += _model !.Cup !.DiceList.Sum(Items => Items.Value); if (SaveRoot !.IsFaceOff == true) { if (PlayerList.Any(Items => Items.IsFaceOff == true && Items.Score == 0)) { WhoTurn = await PlayerList !.CalculateWhoTurnAsync(); await StartNewTurnAsync(); return; } await ExtendedFaceOffAsync(); return; } SingleInfo.NumberOfRolls++; if (SingleInfo.Score > 21) { await UIPlatform.ShowMessageAsync($"{SingleInfo.NickName} is out for going over 21"); await EndTurnAsync(); return; } await ContinueTurnAsync(); //if they get 21, they are responsible for ending turn. }
internal async Task ClientResultsAsync(int wins) { WhoTurn = wins; SingleInfo = PlayerList !.GetWhoPlayer(); if (SingleInfo.TileList.Count == 0) { throw new BasicBlankException("You must have tiles if you won"); } if (SingleInfo.CardUsed == 0) { throw new BasicBlankException("Don't know what card was used for the word for the player"); } await _gameboard.ShowWordAsync(SingleInfo.CardUsed); if (_gameboard.CardsRemaining() == 0 || _test.ImmediatelyEndGame == true) { await GameOverAsync(); return; } if (SaveRoot !.ShortGame == true && PlayerList.Any(Items => Items.CardsWon >= 5)) { await GameOverAsync(); return; } if (SaveRoot.Level == EnumLevel.Easy && PlayerList.Any(Items => Items.CardsWon >= SaveRoot.CardsToBeginWith)) { await GameOverAsync(); return; } await NextOneAsync(); }
public async Task MakeMoveAsync(int space) { if (space < 127) { if (SingleInfo !.CanSendMessage(BasicData !) == true) { await Network !.SendAllAsync("space", space); } } await GameBoard1 !.MakeMoveAsync(space, this); if (GameBoard1.WillMissNextTurn(this) == true) { SingleInfo !.MissNextTurn = true; if (SingleInfo.PlayerCategory == EnumPlayerCategory.Self) { await UIPlatform.ShowMessageAsync("Miss next turn for falling in a pit"); } if (PlayerList.Any(Items => Items.MissNextTurn == true) == false) { throw new BasicBlankException("Did fall. Find out what happened"); } } if (space < 127) { await EndTurnAsync(); //decided to end turn automatically now. } }
public void Deal() { var dealerBlackJack = false; dealARoundOfCards(); dealARoundOfCards(); //check if the dealer has blackjack. if (Dealer.Hand.CurrentScore == 21) { dealerBlackJack = true; } //check if any players have blackjack foreach (var player in PlayerList) { if (player.ActiveHand.CurrentScore == 21) { //if both the dealer and the player have blackjack, then PUSH. if (dealerBlackJack) { player.ActiveHand.Push(); } //Otherwise, the player wins 1.5x his original bet else { player.ActiveHand.Blackjack(); //TODO: Need an onPotchange event to denote the house giving the extra half adjustPlayerBankRoll(player, player.ActiveHand.CurrentBet.Amount * 2.5); } } else //player does not have blackjack, but the dealer does. The player loses. { if (dealerBlackJack) { //give dealer blackjack Dealer.Hand.Blackjack(); //player loses player.ActiveHand.Lost(); } } } var moreToPlay = PlayerList.Any(i => i.CurrentHands.Any(x => x.Result == Result.Undetermined)); if (!moreToPlay) { onGameEnd?.Invoke(this, null); } }
public CustomBasicList <int> GetNumberList() { CustomBasicList <int> output = new CustomBasicList <int>(); for (int x = 0; x <= 6; x++) { if (PlayerList.Any(y => y.NumberChosen == x) == false) { output.Add(x); } } return(output); }
private void AddComputer(DeckRegularDict <RegularSimpleCard> thisCol) { if (PlayerList.Any(items => items.PlayerCategory == EnumPlayerCategory.Computer) == false) { return; } thisCol.ForEach(thisCard => { if (SaveRoot !.ComputerList.ObjectExist(thisCard.Deck) == false) { SaveRoot.ComputerList.Add(thisCard); } }); }
private void RemoveComputer(DeckRegularDict <RegularSimpleCard> ThisCol) { if (PlayerList.Any(items => items.PlayerCategory == EnumPlayerCategory.Computer) == false) { return; } ThisCol.ForEach(thisCard => { if (SaveRoot !.ComputerList.ObjectExist(thisCard.Deck) == true) { SaveRoot.ComputerList.RemoveObjectByDeck(thisCard.Deck); } }); }
private void TxtPlayerToBuy_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { //TODO: There must be a better way. Each keystroke we are iterating through the list.. SelectedPlayer = PlayerList.FirstOrDefault(x => x.Name == txtPlayerToBuy.SelectedItem?.ToString()); if (PlayerList.Any(x => x.Name == SelectedPlayer?.Name)) { chkValidPlayer.IsChecked = true; chkValidPlayer.Visibility = Visibility.Visible; } else { SetVisibility(); } }
public async Task ProcessTieAsync() { SingleInfo !.PossibleTie = true; if (PlayerList.Any(items => items.PossibleTie == false)) { WhoTurn = await PlayerList !.CalculateWhoTurnAsync(); SaveRoot !.GameStatus = EnumGameStatus.PossibleTie; SingleInfo = PlayerList.GetWhoPlayer(); PrepStartTurn(); await ContinueTurnAsync(); return; } await ShowTieAsync(); //hopefully this simple. }
public void OnClientLoaded(Player player) { if (PlayerList.Any(x => x.Value == null)) { PlayerList[PlayerList.First(x => x.Value == null).Key] = new CPlayer(player.Handle); } else { PlayerList.Add(PlayerList.Count, new CPlayer(player.Handle)); } var pId = PlayerList.First(x => x.Value.Handle.Value == player.Handle.Value).Key; PlayerList[pId].ExecuteGlobalMutation("setVersion", buildVersion); PlayerList[pId].ExecuteModuleMutation("loading", "toggleLoading", true); }
private void WinProcesses() { if (PlayerList.Any(items => items.ObjectCount == 0)) { SingleInfo = PlayerList.Single(items => items.ObjectCount == 0); return; } int lefts; int minPoints = 500; int tilesLeft = 1111; int whoWon = 0; int currents; CustomBasicList <int> tieList = new CustomBasicList <int>(); PlayerList !.ForEach(thisPlayer => { lefts = thisPlayer.ObjectCount; currents = thisPlayer.Score; if (currents < minPoints) { tilesLeft = 1111; whoWon = thisPlayer.Id; } else if (currents == minPoints && lefts < tilesLeft) { tilesLeft = lefts; tieList = new CustomBasicList <int> { thisPlayer.Id }; whoWon = thisPlayer.Id; } else if (currents == minPoints && lefts == tilesLeft) { tieList.Add(thisPlayer.Id); } }); if (tieList.Count <= 1) { WhoTurn = whoWon; SingleInfo = PlayerList.GetWhoPlayer(); return; } whoWon = tieList.GetRandomItem(); WhoTurn = whoWon; SingleInfo = PlayerList.GetWhoPlayer(); }
private void JoinUnjoinActivity() { if (PlayerList.Count < maxNumberOfPlayers) { foreach (var gamePad in InputManager.Xbox360GamePads) { if (gamePad.ButtonPushed(Xbox360GamePad.Button.Start)) { // See if this is connected with no player: // Or if input device did not die this level var canJoin = PlayerList.Any(item => item.InputDevice == gamePad) == false && deadPlayerInputDevices.Contains(gamePad) == false; if (canJoin) { JoinPlayer(gamePad); } } else if (gamePad.ButtonPushed(Xbox360GamePad.Button.Back) && this.IsPaused && PlayerList.Count > 1) { DropPlayer(PlayerList.First(item => item.InputDevice == gamePad)); } else if (gamePad.IsConnected == false && PlayerList.Any(item => item.InputDevice == gamePad)) { // player disconnected, so pause and drop the player: DropPlayer(PlayerList.First(item => item.InputDevice == gamePad)); } } var keyboard = InputManager.Keyboard; if (keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.Insert)) { var canJoin = PlayerList.Any(item => item.InputDevice == keyboard) == false && deadPlayerInputDevices.Contains(keyboard) == false; if (canJoin) { JoinPlayer(keyboard); } } else if (keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.Delete) && this.IsPaused && PlayerList.Count > 1) { DropPlayer(PlayerList.First(item => item.InputDevice == keyboard)); } } }
public void FinishHand(Player player) { var nextHand = player.CurrentHands.FirstOrDefault(i => i.State == State.NotYetPlayed); //move to the next player if there are no more unresolved hands. if (nextHand == null) { player.IsActive = false; //if there are hands that have not busted or blackjacked var nextPlayer = PlayerList.FirstOrDefault(i => i.CurrentHands.Any(x => x.State == State.NotYetPlayed)); var everythingIsbusted = !PlayerList.Any(i => i.CurrentHands.Any(x => x.Result != Result.Bust)); //If all hands have busted, end the game and don't play for the dealer if (everythingIsbusted) { //do nothing onGameEnd?.Invoke(this, null); } else if (nextPlayer == null) { onShowAllCards(this, null); while (!Dealer.Hand.CheckIsBust() && Dealer.Hand.CurrentScore <= 16) { giveDealerACard(); } calculateScore(); onGameEnd(this, null); } else { //move to the next player nextPlayer.IsActive = true; nextPlayer.CurrentHands[0].State = State.Playing; } } else { nextHand.State = State.Playing; } }
private async Task FinalAnalAsync() { _command.ManuelFinish = true; if (BasicData !.MultiPlayer == false) { throw new BasicBlankException("Single player cannot figure out the turns"); } if (PlayerList.Any(items => items.TookTurn == false)) { SingleInfo = PlayerList !.GetSelf(); if (SingleInfo.TookTurn == false) { throw new BasicBlankException($"I think the player {SingleInfo.NickName} should have taken your turn before going through the last step"); } Check !.IsEnabled = true; //waiting for others to show they took their turns return; } if (PlayerList.Any(Items => Items.TimeToGetWord == 0)) { throw new BasicBlankException("Must have taken longer than 0 to get a word"); } if (PlayerList.All(Items => Items.TimeToGetWord == -1)) { await UIPlatform.ShowMessageAsync("Nobody found any words. Therefore; going to the next one"); await NextOneAsync(); return; } if (BasicData.Client == true) { Check !.IsEnabled = true; return; //has to wait for host. } SingleInfo = PlayerList.Where(items => items.TimeToGetWord > -1).OrderBy (Items => Items.TimeToGetWord).Take(1).Single(); WhoTurn = SingleInfo.Id; await Network !.SendAllAsync("whowon", WhoTurn); await ClientResultsAsync(WhoTurn); }
/// <summary> /// Update the player list. /// </summary> public async void UpdatePlayers() { SetColumnTitle(1, $"PLAYERS ~1~ OF 2-12", NetworkGetNumConnectedPlayers()); PlayerList list = new PlayerList(); foreach (Player p in list) { if (playerRows.Any(Row => Row.Player == p)) { UpdatePlayer(p, p.ServerId, "JOINED", "SNAIL", PlayerIcon.FREEMODE_RANK, HudColor.HUD_COLOUR_FREEMODE, HudColor.HUD_COLOUR_GREEN); } else { AddPlayer(p, p.ServerId, "JOINED", "SNAIL", PlayerIcon.FREEMODE_RANK, HudColor.HUD_COLOUR_FREEMODE, HudColor.HUD_COLOUR_GREEN); } } await BaseScript.Delay(0); List <PlayerRow> tmp_delete_rows_list = new List <PlayerRow>(); foreach (PlayerRow pr in playerRows) { if (!(list.Any(P => P == pr.Player))) { tmp_delete_rows_list.Add(pr); } } await BaseScript.Delay(0); if (tmp_delete_rows_list.Count > 0) { foreach (PlayerRow pr in tmp_delete_rows_list) { DeletePlayer(pr.RowIndex); } } }
private int GetPlayersSeatNumber(Player player, PlayerList players, int tableSize) { if (players.Count > tableSize) { throw new ArgumentException(String.Format("GetPlayersSeatNumber: players amount can't be higher than table size"), "tableSize"); } bool anyZeroSeat = players.Any(x => x.SeatNumber == 0); int maxSeat = players.Max(x => x.SeatNumber); /* There shouldn't be players with Seat Number equals to 0 */ if (!anyZeroSeat && (maxSeat <= tableSize)) { return(player.SeatNumber - 1); } /* In case we have Seat Number equals to 0 */ else if (anyZeroSeat && maxSeat < tableSize) { return(player.SeatNumber); } return(players.OrderBy(x => x.SeatNumber).ToList().IndexOf(player)); }
private static async Task BriefingTimer() { await Delay(1000); var inGameList = new PlayerList().Where(p => Sync.Data.Has(User.GetPlayerServerId(p), "InGame")).ToList(); if (inGameList.Any()) { if (Sync.Data.Has(-1, "BriefingTimer") && (int)Sync.Data.Get(-1, "BriefingTimer") > 0) { Sync.Data.Set(-1, "BriefingTimer", (int)Sync.Data.Get(-1, "BriefingTimer") - 1); foreach (var p in inGameList) { p.TriggerEvent("TTT:UpdateBriefingInfo", (int)Sync.Data.Get(-1, "BriefingTimer")); } if ((int)Sync.Data.Get(-1, "BriefingTimer") < 1) { int traitor1 = -1; int traitor2 = -1; int traitor3 = -1; int traitor4 = -1; int detective1 = -1; int detective2 = -1; var rand = new Random(); traitor1 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); if (inGameList.Count > 7 && inGameList.Count <= 10) { traitor2 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); //detective1 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); } else if (inGameList.Count > 10 && inGameList.Count <= 16) { traitor2 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); traitor3 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); //detective1 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); } else if (inGameList.Count > 16) { traitor2 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); traitor3 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); traitor4 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); //detective1 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); //detective2 = User.GetPlayerServerId(inGameList[rand.Next(inGameList.Count)]); } Sync.Data.Set(-1, "GameTimer", MapManager.MapData.PlayTime); Sync.Data.Reset(-1, "BriefingTimer"); foreach (var p in inGameList) { p.TriggerEvent("TTT:StartGame", traitor1, traitor2, traitor3, traitor4, detective1, detective2, MapManager.MapData.PlayTime, (int)Sync.Data.Get(-1, "CameraType")); } } } } else if (Sync.Data.Has(-1, "BriefingTimer")) { Sync.Data.Reset(-1, "BriefingTimer"); } }
private static async Task LobbyTimer() { await Delay(1000); var lobbyList = new PlayerList().Where(p => Sync.Data.Has(User.GetPlayerServerId(p), "Lobby")).ToList(); if (lobbyList.Any()) { if (Sync.Data.Has(-1, "StartTimer") && (int)Sync.Data.Get(-1, "StartTimer") > 0) { Sync.Data.Set(-1, "StartTimer", (int)Sync.Data.Get(-1, "StartTimer") - 1); int voteCam1 = 0; int voteCam2 = 0; foreach (var player in new PlayerList()) { if (!Sync.Data.Has(User.GetPlayerServerId(player), "CameraType")) { continue; } if ((int)Sync.Data.Get(User.GetPlayerServerId(player), "CameraType") == 0) { voteCam1++; } else { voteCam2++; } } foreach (var p in lobbyList) { p.TriggerEvent("TTT:UpdateLobbyInfo", (int)Sync.Data.Get(-1, "StartTimer"), voteCam1, voteCam2, lobbyList.Count); } if ((int)Sync.Data.Get(-1, "StartTimer") > 15) { if (lobbyList.Count / 2 <= voteCam1 + voteCam2) { Sync.Data.Set(-1, "StartTimer", 10); } } if ((int)Sync.Data.Get(-1, "StartTimer") < 1) { Sync.Data.Reset(-1, "StartTimer"); Sync.Data.Set(-1, "CameraType", voteCam1 > voteCam2 ? 0 : 1); if (await MapManager.LoadMap(MapManager.GetMap(), lobbyList)) { var weatherList = new List <string> { "EXTRASUNNY", "CLEAR", "CLOUDS", "SMOG", "FOGGY", "OVERCAST", "CLEARING", "XMAS" }; var rand = new Random(); string weatherMap = weatherList[rand.Next(weatherList.Count)]; int hourMap = rand.Next(23); Sync.Data.Set(-1, "BriefingTimer", MapManager.MapData.Briefing); foreach (var p in lobbyList) { Sync.Data.Set(User.GetPlayerServerId(p), "InGame", true); p.TriggerEvent("TTT:StartBriefing", MapManager.MapData.Name, MapManager.MapData.Briefing, MapManager.MapData.CenterX, MapManager.MapData.CenterY, MapManager.MapData.CenterZ, MapManager.MapData.MaxRadius, MapManager.MapData.CanSwim, MapManager.MapData.EnableScope, weatherMap, hourMap); } } else { MapManager.SetMap(MapManager.MapList.First()); StopGame(lobbyList, PlayerTypes.Unknown); } foreach (var player in new PlayerList()) { Sync.Data.Reset(User.GetPlayerServerId(player), "CameraType"); Sync.Data.Reset(User.GetPlayerServerId(player), "Lobby"); } } } } else if (Sync.Data.Has(-1, "StartTimer")) { Sync.Data.Reset(-1, "StartTimer"); } }
private static async Task GameTimer() { await Delay(1000); var inGameList = new PlayerList().Where(p => Sync.Data.Has(User.GetPlayerServerId(p), "InGame")).ToList(); if (inGameList.Any()) { if (Sync.Data.Has(-1, "GameTimer") && (int)Sync.Data.Get(-1, "GameTimer") > 0) { if (MapManager.MapData.PlayTime == (int)Sync.Data.Get(-1, "GameTimer")) { await Delay(5000); } Sync.Data.Set(-1, "GameTimer", (int)Sync.Data.Get(-1, "GameTimer") - 1); int innocentAliveCount = 0; int traitorAliveCount = 0; foreach (var p in inGameList) { p.TriggerEvent("TTT:UpdateGameInfo", (int)Sync.Data.Get(-1, "GameTimer")); var playerId = User.GetPlayerServerId(p); if (!Sync.Data.Has(playerId, "playerType")) { continue; } if ((int)Sync.Data.Get(playerId, "playerType") == PlayerTypes.Innocent || (int)Sync.Data.Get(playerId, "playerType") == PlayerTypes.Detective) { if (!Sync.Data.Has(playerId, "isDead")) { innocentAliveCount++; } } else if ((int)Sync.Data.Get(playerId, "playerType") == PlayerTypes.Traitor) { if (!Sync.Data.Has(playerId, "isDead")) { traitorAliveCount++; } } } if (traitorAliveCount == 0) { StopGame(inGameList, PlayerTypes.Innocent); } else if (innocentAliveCount == 0) { StopGame(inGameList, PlayerTypes.Traitor); } else if ((int)Sync.Data.Get(-1, "GameTimer") < 1) { StopGame(inGameList, PlayerTypes.Innocent); } } } else if (Sync.Data.Has(-1, "GameTimer")) { Sync.Data.Reset(-1, "GameTimer"); } }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); int lastLineRead = -1; // We start on line index 5 as first 5 lines are table and limit info. const int playerListStart = 5; for (int lineNumber = playerListStart; lineNumber < handLines.Length; lineNumber++) { string line = handLines[lineNumber]; char lastChar = line[line.Length - 1]; // leave the loop if we spot a summary/hand start of line if (line.StartsWith("** ")) { break; } // players can also seat at the table after the seat info, post a big blind and be immediately involved in the hand const int seatNumberStartIndex = 5; int playerNameStartIndex = line.IndexOf(':', seatNumberStartIndex) + 2; // seat info expected in format: // Seat 4: thaiJhonny ( $1,404 USD ) if (playerNameStartIndex > 1 && lastChar == ')' && line.StartsWith("Seat ")) { int seatNumber = FastInt.Parse(line, seatNumberStartIndex); // we need to find the ( before the number. players can have ( in their name so we need to go backwards and skip the last one int openParenIndex = line.LastIndexOf('('); string playerName = line.Substring(playerNameStartIndex, openParenIndex - playerNameStartIndex - 1); decimal stack = ParseDecimal(line, openParenIndex + 3); playerList.Add(new Player(playerName, stack, seatNumber)); } // post blind // kpark1996 posts big blind [$1 USD]. else if (lastChar == '.') { // they don't have a known seatNumber int seatNumber = -1; decimal stack = 999999.00m; // we make the stacksize very high so bettings can never result in a "negative stack" int nameEndIndex = line.IndexOf(" posts ", StringComparison.Ordinal); if (nameEndIndex == -1) { continue; } string playerName = line.Substring(0, nameEndIndex); // only add if the player is unknown if (!playerList.Any(p => p.PlayerName.Equals(playerName))) { playerList.Add(new Player(playerName, stack, seatNumber)); } } } // Looking for the showdown info which looks like this // Player1 checks // Player2 shows [ 8h, 5h, Ad, 3d ]high card Ace. // Player1 shows [ 9h, Qd, Qs, 6d ]three of a kind, Queens. // Player1 wins $72 USD from the main pot with three of a kind, Queens. for (int lineNumber = handLines.Length - 1; lineNumber > 0; lineNumber--) { //jimmyhoo: shows [7h 6h] (a full house, Sevens full of Jacks) //EASSA: mucks hand //jimmyhoo collected $562 from pot string line = handLines[lineNumber]; //Skip when player mucks and collects //EASSA: mucks hand char lastChar = line[line.Length - 1]; if (lastChar != '.') { break; } if (!line.Contains(" show")) { continue; } int lastSquareBracket = line.LastIndexOf(']'); if (lastSquareBracket == -1) { continue; } int firstSquareBracket = line.LastIndexOf('[', lastSquareBracket); // can show single cards: // Zaza5573: shows [Qc] if (line[firstSquareBracket + 3] == ']') { continue; } int nameEndIndex = GetNameEndIndex(line);// line.IndexOf(' '); string playerName = line.Remove(nameEndIndex); string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); int lastLineRead = -1; // We start on line index 5 as first 5 lines are table and limit info. const int playerListStart = 5; for (int lineNumber = playerListStart; lineNumber < handLines.Length; lineNumber++) { string line = handLines[lineNumber]; char lastChar = line[line.Length - 1]; // leave the loop if we spot a summary/hand start of line if (line.StartsWith("** ")) { break; } // players can also seat at the table after the seat info, post a big blind and be immediately involved in the hand const int seatNumberStartIndex = 5; int playerNameStartIndex = line.IndexOf(':', seatNumberStartIndex) + 2; // seat info expected in format: // Seat 4: thaiJhonny ( $1,404 USD ) if (playerNameStartIndex > 1 && lastChar == ')' && line.StartsWith("Seat ")) { int seatNumber = FastInt.Parse(line, seatNumberStartIndex); // we need to find the ( before the number. players can have ( in their name so we need to go backwards and skip the last one int openParenIndex = line.LastIndexOf('('); string playerName = line.Substring(playerNameStartIndex, openParenIndex - playerNameStartIndex - 1); decimal stack = ParseDecimal(line, openParenIndex + 3); playerList.Add(new Player(playerName, stack, seatNumber)); } // post blind // kpark1996 posts big blind [$1 USD]. else if (lastChar == '.') { // they don't have a known seatNumber int seatNumber = -1; decimal stack = 999999.00m; // we make the stacksize very high so bettings can never result in a "negative stack" int nameEndIndex = line.IndexOf(" posts ", StringComparison.Ordinal); if (nameEndIndex == -1) { continue; } string playerName = line.Substring(0, nameEndIndex); // only add if the player is unknown if (!playerList.Any(p => p.PlayerName.Equals(playerName))) { playerList.Add(new Player(playerName, stack, seatNumber)); } } } // Looking for the showdown info which looks like this // Player1 checks // Player2 shows [ 8h, 5h, Ad, 3d ]high card Ace. // Player1 shows [ 9h, Qd, Qs, 6d ]three of a kind, Queens. // Player1 wins $72 USD from the main pot with three of a kind, Queens. for (int lineNumber = handLines.Length - 1; lineNumber > 0; lineNumber--) { //jimmyhoo: shows [7h 6h] (a full house, Sevens full of Jacks) //EASSA: mucks hand //jimmyhoo collected $562 from pot string line = handLines[lineNumber]; //Skip when player mucks and collects //EASSA: mucks hand char lastChar = line[line.Length - 1]; if (lastChar != '.') { break; } if (!line.Contains(" show")) { continue; } int lastSquareBracket = line.LastIndexOf(']'); if (lastSquareBracket == -1) { continue; } int firstSquareBracket = line.LastIndexOf('[', lastSquareBracket); // can show single cards: // Zaza5573: shows [Qc] if (line[firstSquareBracket + 3] == ']') { continue; } int nameEndIndex = GetNameEndIndex(line);// line.IndexOf(' '); string playerName = line.Remove(nameEndIndex); string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } return(playerList); }
private void RefreshPlayerMenus() { IUser[] users = Game.GetActiveUsers(); if (users == null || users.Length == 0) { return; } foreach (var u in users) { var menus = PlayerMenuList.Where(m => m.Player != null && m.Player.User != null && m.Player.User.Name == u.Name).ToList(); if (menus.Count > 1) { DebugLogger.DebugOnlyDialogLog("PLAYER " + u.Name + " HAD MORE THAN ONE MENU. DELETING THE OTHER MENUS"); menus[1].Player = null; menus[1].Menu.SetText(string.Empty); menus[1].Ready = false; } } if (PlayerList.Count == users.Length) { return; } try { int initialPlayercount = PlayerList.Count; if (PlayerList.Count < users.Length) { var availableMenus = PlayerMenuList.Where(m => m.Player == null || m.Player.User == null).ToList(); for (int i = 0; i < users.Length; i++) { IUser currentUser = null; currentUser = users[i]; if (currentUser == null) { continue; } if (currentUser.IsSpectator) { continue; } if (PlayerList.Any(p => p.User.Name.Equals(currentUser.Name))) { continue; } if (currentUser.GetPlayer() == null) { DebugLogger.DebugOnlyDialogLog("SPAWNING BODY FOR PLAYER " + currentUser.Name, CameraPosition); var positionToSpawn = Game.GetSingleObjectByCustomId("StartSpawnPoint").GetWorldPosition(); var p = Game.CreatePlayer(positionToSpawn); p.SetTeam(PlayerTeam.Team3); p.SetUser(currentUser); p.SetProfile(currentUser.GetProfile()); p.SetWorldPosition(positionToSpawn); } var player = new TPlayer(currentUser); if (availableMenus.Count == 0) { DebugLogger.DebugOnlyDialogLog("NO AVAILABLE MENUS FOR PLAYER " + player.Name); return; } TPlayerMenu menu = null; menu = availableMenus.FirstOrDefault(); availableMenus.RemoveAt(availableMenus.IndexOf(menu)); if (menu == null) { return; } try { var playerFound = false; if (!string.IsNullOrEmpty(OtherData)) { // try to look for player in OtherData var playerList = OtherData.Split(';'); for (int p = 0; p < playerList.Length; p++) { string[] plData = playerList[p].Split(':'); if (plData.Length == 11) { List <string> list = new List <string>(plData); list.RemoveAt(3); plData = list.ToArray(); } string name = FormatName(player.Name); if (name == plData[0]) { menu.SetPlayer(player); player.Level = Math.Min(Convert.ToInt32(plData[1]), LevelList.Count - 1); player.CurrentExp = Convert.ToInt32(plData[2]); for (int u = 0; u < menu.Equipment.Count; u++) { menu.Equipment[u] = Convert.ToInt32(plData[3 + u]); } menu.ValidateEquipment(); menu.Change = true; menu.Update(); playerFound = true; DebugLogger.DebugOnlyDialogLog("PLAYER FOUND IN MEMORY DATA. WELCOME BACK!" + player.Name); break; } } } if (!playerFound) { DebugLogger.DebugOnlyDialogLog("ASSIGNING MENU TO PLAYER " + player.Name); if (ShowDebugMessages && !string.IsNullOrEmpty(OtherData)) { DebugLogger.DebugOnlyDialogLog("THEY ARE A NEW PLAYER! WELCOME " + player.Name + "!"); } menu.SetPlayer(player); menu.Change = true; menu.Update(); } } catch (Exception e) { DebugLogger.DebugOnlyDialogLog(e.Message); DebugLogger.DebugOnlyDialogLog(e.StackTrace); DebugLogger.DebugOnlyDialogLog("COULDN'T INSTANTIATE PLAYER " + player.Name); } PlayerList.Add(player); } } if (PlayerList.Count > users.Length) { DebugLogger.DebugOnlyDialogLog("More players in PlayersList than active users"); for (int i = PlayerMenuList.Count - 1; i >= 0; i--) { TPlayer player = null; try { player = PlayerList.ElementAtOrDefault(i); } catch (Exception) { DebugLogger.DebugOnlyDialogLog("PlayerList.ElementAtOrDefault(i) was out of range, i:" + (i).ToString(), CameraPosition); } if (player == null) { continue; } TPlayerMenu menu = null; try { menu = PlayerMenuList.Where(m => m.Player != null && m.Player.Name != null && m.Player.Name.Equals(player.Name)).FirstOrDefault(); } catch (Exception e) { DebugLogger.DebugOnlyDialogLog("PlayerMenuList.Where(m => m.Player.Name.Equals(m.Player)).FirstOrDefault()" + (i).ToString(), CameraPosition); DebugLogger.DebugOnlyDialogLog(e.Message + (i).ToString(), CameraPosition); DebugLogger.DebugOnlyDialogLog(e.StackTrace + (i).ToString(), CameraPosition); } if (menu == null) { DebugLogger.DebugOnlyDialogLog("MENU FOR PLAYER " + player.Name + " WAS NULL. IF HE LEFT HIS PROGRESS WILL NOT BE SAVED!!"); continue; } if (!users.Any(u => u.Name != null && u.Name.Equals(player.User.Name)) && GameState != -3 && GameState != -4) { DebugLogger.DebugOnlyDialogLog("REMOVING MENU FOR: " + player.User.Name + ". LEVEL " + player.Level + ". USER HAS LEFT THE MATCH"); var playersInMemoryCountBefore = OtherData.Split(';').Length; var leavingPlayerData = menu.Save(saveOnlyIfActive: false); OtherData += leavingPlayerData; var playersInMemoryCountAfter = OtherData.Split(';').Length; menu.Dispose(); PlayerList.Remove(player); if (player.Body != null) { player.Body.Remove(); DebugLogger.DebugOnlyDialogLog("REMOVED BODY FOR PLAYER " + player.User.Name); } else { DebugLogger.DebugOnlyDialogLog("COULDN'T REMOVE BODY FOR PLAYER " + player.User.Name); } DebugLogger.DebugOnlyDialogLog("REMOVED MENU FOR: " + player.User.Name + "SUCCESFULLY. DATA ADDED TO MEMORY PLAYERS"); DebugLogger.DebugOnlyDialogLog(playersInMemoryCountBefore + " LOADED IN MEMORY BEFORE AND " + playersInMemoryCountAfter + " AFTER. " + PlayerList.Count + " IN MATCH"); DebugLogger.DebugOnlyDialogLog("SAVED DATA FOR LEAVING PLAYER " + leavingPlayerData); } } } // ONLY LOAD DATA ONCE PER GAME if (OtherData == string.Empty) { LoadData(); } } catch (Exception e) { DebugLogger.DebugOnlyDialogLog(e.StackTrace, CameraPosition); DebugLogger.DebugOnlyDialogLog(e.Source, CameraPosition); } }
public static bool PlayerExists(uint id) { return(PlayerList.Any(x => x.NetId == id)); }