Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
2.4 kB
4
Indexable
Never
  private async Task UpdateDealtCardsForBaccaratRoundAsync(Result result)
        {
            try
            {
                var roundDealtCards = (await GameAccess.GetRoundCardsAsync(TableCode).ConfigureAwait(false))?.
                    FirstOrDefault(x => x.RoundId == CurrentRoundId) ??
                    new RoundDealtCards
                    {
                        RoundId = CurrentRoundId,
                        DealtCards = new List<PokerCard>()
                    };

                var playerCardList = GameCore.PlayerCards;
                var bankerCardList = GameCore.BankerCards;

                // Updating the dealt cards based on the game rules
                for (int i = 0; i < 6; i++)
                {
                    if (roundDealtCards.DealtCards.Count == i)
                    {
                        PokerCard? cardToAdd = null;

                        if (i == 0 && playerCardList.Count > 0 && playerCardList[0].IsValidCard)
                            cardToAdd = playerCardList[0];
                        else if (i == 1 && bankerCardList.Count > 0 && bankerCardList[0].IsValidCard)
                            cardToAdd = bankerCardList[0];
                        else if (i == 2 && playerCardList.Count > 1 && playerCardList[1].IsValidCard)
                            cardToAdd = playerCardList[1];
                        else if (i == 3 && bankerCardList.Count > 1 && bankerCardList[1].IsValidCard)
                            cardToAdd = bankerCardList[1];
                        else if (i >= 4 && (bankerCardList.Count > 2 || playerCardList.Count > 2) && result is BaccaratSingleCardResult baccaratResult)
                            cardToAdd = baccaratResult.Card;

                        if (cardToAdd != null)
                            roundDealtCards.DealtCards.Add(cardToAdd.Value);
                        else
                            break;
                    }
                }

                await GameAccess.SetRoundCardsAsync(new SetRoundDealtCardsModel
                {
                    TableCode = TableCode,
                    RoundId = CurrentRoundId,
                    DealtCards = roundDealtCards.DealtCards
                }).ConfigureAwait(false);
            }
            catch (Exception ex)
            { 
            }