internal void Reset(bool keepCards = false)
        {
            ChipsContainer     = new ReplayerChipsContainer();
            StatInfoCollection = new ReactiveList <StatInfo>();

            if (Cards == null)
            {
                Cards = new ObservableCollection <ReplayerCardViewModel>();
                for (int i = 0; i < 4; i++)
                {
                    var card = new ReplayerCardViewModel();
                    card.CardToDisplay = ReplayerCardViewModel.DEFAULT_CARD_ID;
                    card.CardId        = ReplayerCardViewModel.DEFAULT_CARD_ID;
                    card.CanHideCards  = false;

                    Cards.Add(card);
                }
            }
            else if (!keepCards)
            {
                foreach (var card in Cards)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        card.CardToDisplay = ReplayerCardViewModel.DEFAULT_CARD_ID;
                        card.CardId        = ReplayerCardViewModel.DEFAULT_CARD_ID;
                        card.CanHideCards  = false;
                    }
                }
            }

            Name          = "Empty";
            IsFinished    = true;
            IsActive      = false;
            IsDealer      = false;
            IsWin         = false;
            Bank          = 0;
            OldBank       = 0;
            ActiveAmount  = 0;
            OldAmount     = 0;
            CurrentStreet = Street.Preflop;
            ActionString  = string.Empty;
        }
Example #2
0
        private void Update()
        {
            TableStateList.Clear();
            SetPlayersDefaults();

            TotalPotChipsContainer = new ReplayerChipsContainer();
            CommunityCards         = new List <ReplayerCardViewModel>();

            if (CurrentGame == null)
            {
                return;
            }

            SetCommunityCards(CurrentGame.CommunityCards);

            decimal anteAmount      = Math.Abs(CurrentGame.HandActions.Where(x => x.HandActionType == HandActionType.ANTE).Sum(x => x.Amount));
            decimal currentPotValue = anteAmount;
            decimal totalPotValue   = anteAmount;

            foreach (var action in CurrentGame.HandActions.Where(x => x.HandActionType != HandActionType.ANTE))
            {
                if (IsSkipAction(action))
                {
                    continue;
                }

                ReplayerTableState state = new ReplayerTableState();

                ReplayerTableState lastAction = TableStateList.LastOrDefault();

                if (lastAction != null && lastAction.CurrentStreet != action.Street && action.Street >= Street.Flop && action.Street <= Street.River)
                {
                    // if we are inside this "if" we create an extra state between two actions
                    totalPotValue         = currentPotValue;
                    state.TotalPotValue   = totalPotValue;
                    state.CurrentPotValue = currentPotValue;

                    state.IsStreetChangedAction = true;
                    state.ActivePlayer          = new ReplayerPlayerViewModel();
                    state.CurrentStreet         = action.Street;
                    TableStateList.Add(state);  // added new state between actions like flop/river
                    state.CurrentAction = action;

                    state = new ReplayerTableState();
                }

                state.CurrentAction = action;
                state.ActionAmount  = action.Amount;
                state.CurrentStreet = action.Street;

                ReplayerPlayerViewModel activePlayer = GetActivePlayerLastState(action);
                state.ActivePlayer = new ReplayerPlayerViewModel();
                ReplayerPlayerViewModel.Copy(activePlayer, state.ActivePlayer);

                state.UpdatePlayerState(action);

                if (state.ActivePlayer.IsWin)
                {
                    if (!TableStateList.Any(x => x.ActivePlayer != null && x.ActivePlayer.IsWin))
                    {
                        totalPotValue = currentPotValue;
                    }
                    totalPotValue -= state.ActionAmount;
                }
                else
                {
                    currentPotValue = currentPotValue - state.ActionAmount;
                }
                state.TotalPotValue   = totalPotValue;
                state.CurrentPotValue = currentPotValue;
                TableStateList.Add(state);
            }

            StateIndex = 0;
            SliderMax  = TableStateList.Count - 1;
        }