Exemple #1
0
        private void ParseSummaryRoomStateChange(SCGameRoomStateChange startRoomStateChange, HandHistory handHistory, long heroId)
        {
            var gameRoomInfo      = GetGameRoomInfo(startRoomStateChange, handHistory);
            var userGameInfos     = GetUserGameInfos(gameRoomInfo, handHistory);
            var gameResultInfo    = gameRoomInfo.GameResultInfo ?? throw new HandBuilderException(handHistory.HandId, "GameResultInfo has not been found.");
            var gamePotResultInfo = gameResultInfo.GamePotResultInfo ?? throw new HandBuilderException(handHistory.HandId, "GamePotResultInfo has not been found.");

            if (gameResultInfo.OriginalUserStacks == null || gameResultInfo.OriginalUserStacks.Length != userGameInfos.Length)
            {
                throw new HandBuilderException(handHistory.HandId, "OriginalUserStacks are empty or has wrong length.");
            }

            // update original stacks
            for (var seat = 0; seat < userGameInfos.Length; seat++)
            {
                if (!userGameInfos[seat].IsActive)
                {
                    continue;
                }

                var player = AddOrUpdatePlayer(userGameInfos[seat], seat + 1, handHistory, heroId);
                player.StartingStack = gameResultInfo.OriginalUserStacks[seat];
            }

            // parse win amounts
            for (var potResultNum = 0; potResultNum < gamePotResultInfo.Length; potResultNum++)
            {
                var userWinners = gamePotResultInfo[potResultNum].UserWiner;
                var userPots    = gamePotResultInfo[potResultNum].UserPots;

                if (userWinners.Length != userPots.Length)
                {
                    throw new HandBuilderException(handHistory.HandId, "UserWinners length isn't equal to UserPots length.");
                }

                for (var winnerNum = 0; winnerNum < userWinners.Length; winnerNum++)
                {
                    var userWinner = userWinners[winnerNum];

                    var winner = handHistory.Players[userWinner.ShowID];

                    if (winner == null)
                    {
                        throw new HandBuilderException(handHistory.HandId, $"UserWinner [{userWinner.ShowID}] has not been found in the player list.");
                    }

                    winner.Win += userPots[winnerNum];
                }
            }

            // parse community cards
            if (gameRoomInfo.CurrentCards != null && gameRoomInfo.CurrentCards.Length > 0)
            {
                handHistory.CommunityCards = BoardCards.FromCards(gameRoomInfo
                                                                  .CurrentCards
                                                                  .Select(c => Card.GetPMCardFromIntValue(c))
                                                                  .ToArray());
            }
        }
Exemple #2
0
        /// <summary>
        /// Parses hand action of the specified <see cref="SCGameRoomStateChange"/>
        /// </summary>
        /// <param name="startRoomStateChange">Room state change to parse</param>
        /// <param name="handHistory">Hand history</param>
        private void ParseActionsRoomStateChange(SCGameRoomStateChange startRoomStateChange, HandHistory handHistory, Dictionary <string, UserGameInfoNet> previousUserGameInfoDict, long heroId)
        {
            var gameRoomInfo  = GetGameRoomInfo(startRoomStateChange, handHistory);
            var userGameInfos = GetUserGameInfos(gameRoomInfo, handHistory);

            // first action time is hand time
            if (userGameInfos.Length > 0 && handHistory.DateOfHandUtc == DateTime.MinValue)
            {
                var actTime = userGameInfos.Max(x => x.ActTime);

                if (actTime != 0)
                {
                    handHistory.DateOfHandUtc = DateTimeHelper.UnixTimeToDateTime(actTime / 1000);
                }
            }

            for (var seat = 0; seat < userGameInfos.Length; seat++)
            {
                var userGameInfo = userGameInfos[seat];

                if (!userGameInfo.IsActive)
                {
                    continue;
                }

                if (userGameInfo.UserInfo == null)
                {
                    throw new HandBuilderException(handHistory.HandId, "UserGameInfo.UserInfo has not been found.");
                }

                // game dealer
                if (handHistory.DealerButtonPosition == 0 && userGameInfos[seat].GameDealer)
                {
                    handHistory.DealerButtonPosition = seat + 1;
                }

                userGameInfo.RoomGameState = gameRoomInfo.GameState;

                AddOrUpdatePlayer(userGameInfo, seat + 1, handHistory, heroId);

                previousUserGameInfoDict.TryGetValue(userGameInfo.UserInfo.ShowID, out UserGameInfoNet previousUserGameInfo);

                var handAction = ParseHandAction(userGameInfo, previousUserGameInfo, handHistory);

                if (handAction != null)
                {
                    handHistory.HandActions.Add(handAction);
                }

                if (previousUserGameInfo == null)
                {
                    previousUserGameInfoDict.Add(userGameInfo.UserInfo.ShowID, userGameInfo);
                    continue;
                }

                previousUserGameInfoDict[userGameInfo.UserInfo.ShowID] = userGameInfo;
            }
        }
Exemple #3
0
        private void ParseStartRoomStateChange(SCGameRoomStateChange startRoomStateChange, HandHistory handHistory)
        {
            var gameRoomInfo = GetGameRoomInfo(startRoomStateChange, handHistory);

            if (gameRoomInfo.IsTournament)
            {
                ParseTournamentStartRoomStateChange(startRoomStateChange, gameRoomInfo, handHistory);
                return;
            }

            ParseCashStartRoomStateChange(startRoomStateChange, gameRoomInfo, handHistory);
        }
Exemple #4
0
        private void ParseCashStartRoomStateChange(SCGameRoomStateChange startRoomStateChange, GameRoomInfo gameRoomInfo, HandHistory handHistory)
        {
            var gameRoomBaseInfo = gameRoomInfo.GameRoomBaseInfo ?? throw new HandBuilderException(handHistory.HandId, "GameRoomBaseInfo must be not empty.");

            handHistory.TableName       = startRoomStateChange.GameRoomInfo?.GameRoomBaseInfo?.RoomName;
            handHistory.GameDescription = new GameDescriptor(
                EnumPokerSites.PokerMaster,
                ParseGameType(gameRoomInfo),
                Limit.FromSmallBlindBigBlind(gameRoomBaseInfo.SmallBlinds, gameRoomBaseInfo.BigBlinds, Currency.YUAN, gameRoomBaseInfo.IsAnteRoom, gameRoomBaseInfo.Ante),
                ParseTableType(gameRoomInfo),
                SeatType.FromMaxPlayers(gameRoomBaseInfo.GameRoomUserMaxNums),
                null
                );

            handHistory.GameDescription.IsStraddle = gameRoomBaseInfo.Straddle;
            handHistory.GameDescription.Identifier = gameRoomBaseInfo.GameRoomId;
        }
Exemple #5
0
        private void ParseTournamentStartRoomStateChange(SCGameRoomStateChange startRoomStateChange, GameRoomInfo gameRoomInfo, HandHistory handHistory)
        {
            var gameRoomBaseInfo = gameRoomInfo.SNGGameRoomBaseInfo ?? throw new HandBuilderException(handHistory.HandId, "SNGGameRoomBaseInfo must be not empty.");

            handHistory.TableName       = startRoomStateChange.GameRoomInfo?.SNGGameRoomBaseInfo?.RoomName;
            handHistory.GameDescription = new GameDescriptor(
                PokerFormat.Tournament,
                EnumPokerSites.PokerMaster,
                ParseGameType(gameRoomInfo),
                Limit.FromSmallBlindBigBlind(gameRoomBaseInfo.SmallBlinds, gameRoomBaseInfo.BigBlinds, Currency.YUAN, true, gameRoomBaseInfo.Ante),
                ParseTableType(gameRoomInfo),
                SeatType.FromMaxPlayers(gameRoomBaseInfo.GameRoomUserMaxNums),
                ParseTournamentDescriptor(gameRoomInfo)
                )
            {
                Identifier = gameRoomBaseInfo.GameRoomId
            };
        }
Exemple #6
0
        public bool TryBuild(SCGameRoomStateChange gameRoomStateChange, long heroId, out HandHistory handHistory)
        {
            handHistory = null;

            if (gameRoomStateChange == null)
            {
                return(false);
            }

            if (!handsRoomStateChanges.TryGetValue(heroId, out Dictionary <long, List <SCGameRoomStateChange> > userGameRoomStateChanges))
            {
                userGameRoomStateChanges = new Dictionary <long, List <SCGameRoomStateChange> >();
                handsRoomStateChanges.Add(heroId, userGameRoomStateChanges);
            }

            if (!userGameRoomStateChanges.TryGetValue(gameRoomStateChange.GameNumber, out List <SCGameRoomStateChange> gameRoomStateChanges))
            {
                gameRoomStateChanges = new List <SCGameRoomStateChange>();
                userGameRoomStateChanges.Add(gameRoomStateChange.GameNumber, gameRoomStateChanges);
            }

            if (gameRoomStateChange.GameRoomInfo.GameState == GameRoomGameState.ROOM_GAME_STATE_SHOWCARD ||
                gameRoomStateChange.GameRoomInfo.GameState == GameRoomGameState.ROOM_GAME_STATE_GameWait ||
                gameRoomStateChange.GameRoomInfo.GameState == GameRoomGameState.ROOM_GAME_STATE_GamePrepare)
            {
                return(false);
            }

            gameRoomStateChanges.Add(gameRoomStateChange);

            if (gameRoomStateChange.GameRoomInfo.GameState == GameRoomGameState.ROOM_GAME_STATE_Result)
            {
                handHistory = BuildHand(gameRoomStateChange.GameNumber, gameRoomStateChanges, heroId);
            }

            return(handHistory != null);
        }
Exemple #7
0
 private static GameRoomInfo GetGameRoomInfo(SCGameRoomStateChange startRoomStateChange, HandHistory handHistory)
 {
     return(startRoomStateChange.GameRoomInfo ?? throw new HandBuilderException(handHistory.HandId, "GameRoomInfo must be not empty."));
 }