Dominion.GameState.DoBuyPhase C# (CSharp) Method

DoBuyPhase() private method

private DoBuyPhase ( PlayerState currentPlayer ) : void
currentPlayer PlayerState
return void
        private void DoBuyPhase(PlayerState currentPlayer)
        {
            currentPlayer.EnterPhase(PlayPhase.Buy);
            while (currentPlayer.turnCounters.AvailableBuys > 0)
            {
                Card cardType = currentPlayer.actions.GetCardFromSupplyToBuy(this, CardAvailableForPurchaseForCurrentPlayer);
                if (cardType == null)
                {
                    return;
                }

                if (!CardAvailableForPurchaseForCurrentPlayer(cardType))
                {
                    throw new Exception("Tried to buy card that didn't meet criteria");
                }

                if (!this.CanGainCardFromSupply(cardType) && !cardType.isEvent)
                {
                    return;
                }

                currentPlayer.turnCounters.RemoveCoins(cardType.CurrentCoinCost(currentPlayer));
                currentPlayer.turnCounters.RemovePotions(cardType.potionCost);
                currentPlayer.turnCounters.RemoveBuy();

                if (cardType.isEvent)
                {
                    this.cardContextStack.PushCardContext(currentPlayer, cardType, CardContextReason.EventBeingResolved);
                    cardType.DoSpecializedAction(currentPlayer, this);
                    this.cardContextStack.Pop();
                }
                else
                {
                    Card boughtCard = this.PlayerGainCardFromSupply(cardType, currentPlayer, DeckPlacement.Discard, GainReason.Buy);
                    if (boughtCard == null)
                    {
                        throw new Exception("CanGainCardFromSupply said we could buy a card when we couldn't");
                    }

                    int embargoCount = this.pileEmbargoTokenCount[boughtCard];
                    for (int i = 0; i < embargoCount; ++i)
                    {
                        currentPlayer.GainCardFromSupply(Cards.Curse, this);
                    }
                }
            }
        }