Dominion.PlayerState.RequestPlayerOverpayForCard C# (CSharp) Method

RequestPlayerOverpayForCard() private method

private RequestPlayerOverpayForCard ( Dominion.Card boughtCard, GameState gameState ) : void
boughtCard Dominion.Card
gameState GameState
return void
        internal void RequestPlayerOverpayForCard(Card boughtCard, GameState gameState)
        {
            int overPayAmount = this.actions.GetCoinAmountToOverpayForCard(gameState, boughtCard);
            if (this.AvailableCoins < overPayAmount)
            {
                throw new Exception("Player requested to overpay by more than he can afford");
            }
            if (overPayAmount > 0)
            {
                this.gameLog.PlayerOverpaidForCard(boughtCard, overPayAmount);
                this.gameLog.PushScope();
                this.AddCoins(-overPayAmount);
                boughtCard.OverpayOnPurchase(this, gameState, overPayAmount);
                this.gameLog.PopScope();
            }
        }

Usage Example

Ejemplo n.º 1
0
        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();
                    }
                }
            }
        }
PlayerState