private void DoBuyPhase(PlayerState currentPlayer)
{
currentPlayer.playPhase = 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");
}
Card boughtCard = this.PlayerGainCardFromSupply(cardType, currentPlayer, DeckPlacement.Discard, GainReason.Buy);
if (boughtCard == null)
{
return;
}
int embargoCount = this.pileEmbargoTokenCount[boughtCard];
for (int i = 0; i < embargoCount; ++i)
{
currentPlayer.GainCardFromSupply(Cards.Curse, this);
}
currentPlayer.turnCounters.RemoveCoins(boughtCard.CurrentCoinCost(currentPlayer));
currentPlayer.turnCounters.RemovePotions(boughtCard.potionCost);
currentPlayer.turnCounters.RemoveBuy();
if (boughtCard.canOverpay)
{
currentPlayer.RequestPlayerOverpayForCard(boughtCard, this);
}
if (currentPlayer.ownsCardWithSpecializedActionOnBuyWhileInPlay)
{
foreach (Card cardInPlay in currentPlayer.CardsInPlay)
{
gameLog.PushScope();
cardInPlay.DoSpecializedActionOnBuyWhileInPlay(currentPlayer, this, boughtCard);
gameLog.PopScope();
}
}
}
}