Esempio n. 1
0
        internal void DoPlayAction(Card currentCard, GameState gameState, int countTimes = 1)
        {
            if (!currentCard.isAction)
            {
                throw new Exception("Can't play a card that isn't a action");
            }

            this.cardsBeingPlayed.AddCardToTop(currentCard);

            Card cardToPlayAs = currentCard.CardToMimick(this, gameState);
            gameState.cardContextStack.PushCardContext(this, cardToPlayAs, CardContextReason.CardBeingPlayed);

            if (cardToPlayAs != null)
            {
                for (int i = 0; i < countTimes; ++i)
                {
                    this.gameLog.PlayedCard(this, currentCard);
                    this.gameLog.PushScope();

                    this.AddActions(cardToPlayAs.plusAction);
                    this.AddBuys(cardToPlayAs.plusBuy);
                    this.AddCoins(cardToPlayAs.plusCoin);
                    this.AddVictoryTokens(cardToPlayAs.plusVictoryToken);
                    this.DrawAdditionalCardsIntoHand(cardToPlayAs.plusCard, gameState);

                    if (cardToPlayAs.isAttack && cardToPlayAs.isAttackBeforeAction)
                    {
                        AttackOtherPlayers(gameState, cardToPlayAs.DoSpecializedAttack);
                    }

                    cardToPlayAs.DoSpecializedAction(gameState.players.CurrentPlayer, gameState);

                    if (cardToPlayAs.isAttack && !cardToPlayAs.attackDependsOnPlayerChoice && !cardToPlayAs.isAttackBeforeAction)
                    {
                        AttackOtherPlayers(gameState, cardToPlayAs.DoSpecializedAttack);
                    }

                    if (this.ownsCardWithSpecializedActionToCardWhileInPlay)
                    {
                        foreach(var cardInPlay in this.cardsInPlay)
                        {
                            if (cardInPlay.HasSpecializedActionToCardWhileInPlay)
                            {
                                gameState.cardContextStack.PushCardContext(this, cardInPlay, CardContextReason.CardReacting);
                                cardInPlay.DoSpecializedActionToCardWhileInPlay(this, gameState, cardToPlayAs);
                                gameState.cardContextStack.Pop();
                            }
                        }
                    }

                    this.gameLog.PopScope();
                }
            }

            gameState.cardContextStack.Pop();
            CardHasBeenPlayed(cardToPlayAs, countTimes);
        }