Example #1
0
		public void TestFireAllEvents()
		{
			if (Attacked != null)
				Attacked(this, new AttackedEventArgs(null, null));
			if (BenefitReceiving != null)
				BenefitReceiving(this, new BenefitReceivingEventArgs(null, null));
			if (BenefitsChanged != null)
				BenefitsChanged(this, new BenefitsChangedEventArgs(null));
			CardBuyEventArgs cbea = new CardBuyEventArgs(null, null);
			if (CardBought != null)
				CardBought(this, cbea);
			if (CardBuying != null)
				CardBuying(this, cbea);
			if (CardBuyFinished != null)
				CardBuyFinished(this, cbea);
			CardGainEventArgs cgea = new CardGainEventArgs(null, null, DeckLocation.Discard, DeckPosition.Automatic, false);
			if (CardGained != null)
				CardGained(this, cgea);
			if (CardGainedInto != null)
				CardGainedInto(this, cgea);
			if (CardGainFinished != null)
				CardGainFinished(this, cgea);
			if (CardGaining != null)
				CardGaining(this, cgea);
			if (CardPlayed != null)
				CardPlayed(this, new CardPlayedEventArgs(null, new Cards.Universal.Copper()));
			if (CardPlaying != null)
				CardPlaying(this, new CardPlayingEventArgs(null, new Cards.Universal.Copper(), null));
			if (CardReceived != null)
				CardReceived(this, new CardReceivedEventArgs(null, null, DeckLocation.Discard, DeckPosition.Automatic));
			if (CardsAddedToDeck != null)
				CardsAddedToDeck(this, new CardsAddedToDeckEventArgs(new Cards.Universal.Copper(), DeckPosition.Automatic));
			if (CardsAddedToHand != null)
				CardsAddedToHand(this, new CardsAddedToHandEventArgs(new Cards.Universal.Copper()));
			if (CardsDiscarded != null)
				CardsDiscarded(this, new CardsDiscardEventArgs(DeckLocation.Discard, new Cards.Universal.Copper()));
			if (CardsDiscarding != null)
				CardsDiscarding(this, new CardsDiscardEventArgs(DeckLocation.Discard, new Cards.Universal.Copper()));
			if (CardsDrawn != null)
				CardsDrawn(this, new CardsDrawnEventArgs(null, DeckPosition.Automatic, 0));
			if (CardsLost != null)
				CardsLost(this, new CardsLostEventArgs(null));
			if (CleanedUp != null)
				CleanedUp(this, new CleanedUpEventArgs(null, 0));
			if (CleaningUp != null)
			{
				CardMovementCollection cmc = new CardMovementCollection();
				CleaningUp(this, new CleaningUpEventArgs(null, 0, ref cmc));
			}
			if (PhaseChanged != null)
				PhaseChanged(this, new PhaseChangedEventArgs(null, PhaseEnum.Endgame));
			if (PhaseChanging != null)
				PhaseChanging(this, new PhaseChangingEventArgs(null, PhaseEnum.Endgame));
			if (Shuffling != null)
				Shuffling(this, new ShuffleEventArgs(null));
			if (Shuffled != null)
				Shuffled(this, new ShuffleEventArgs(null));
			if (Trashing != null)
				Trashing(this, new TrashEventArgs(null, null));
			if (Trashed != null)
				Trashed(this, new TrashEventArgs(null, null));
			if (TrashedFinished != null)
				TrashedFinished(this, new TrashEventArgs(null, null));
			if (TurnEnded != null)
				TurnEnded(this, new TurnEndedEventArgs(null));
			if (TurnStarted != null)
				TurnStarted(this, new TurnStartedEventArgs(null));
			if (TurnStarting != null)
				TurnStarting(this, new TurnStartingEventArgs(null));
		}
Example #2
0
		public Boolean Buy(Supply supply)
		{
			Card supplyCard = supply.TopCard;

			PlayerMode previousMode = this.PlayerMode;
			this.PlayerMode = Players.PlayerMode.Buying;
			Boolean cancelled = false;
			if (CardBuying != null)
			{
				CardBuyEventArgs cbea = new CardBuyEventArgs(_Game, supplyCard);
				CardBuying(this, cbea);
				cancelled = cbea.Cancelled;
			}
			if (!cancelled)
			{
				CurrentTurn.Bought(supplyCard);
				supplyCard.Bought(this);
				supply.Bought(this);

				if (CardBought != null)
				{
					CardBuyEventArgs cbea = null;
					List<Object> handledBy = new List<Object>();
					Boolean actionPerformed = false;
					do
					{
						actionPerformed = false;
						cbea = new CardBuyEventArgs(_Game, supplyCard);
						cbea.HandledBy.AddRange(handledBy);
						CardBought(this, cbea);
						handledBy = cbea.HandledBy;

						Boolean isAnyRequired = false;
						List<String> options = new List<String>();
						IEnumerable<Type> cardTypes = cbea.Actions.Keys;
						foreach (Type key in cardTypes)
						{
							options.Add(cbea.Actions[key].Text);
							isAnyRequired |= cbea.Actions[key].IsRequired;
						}

						if (options.Count > 0)
						{
							options.Sort();
							Choice choice = new Choice(String.Format("You bought {0}", supplyCard), null, new CardCollection() { supplyCard }, options, this, cbea, false, isAnyRequired ? 1 : 0, 1);
							ChoiceResult result = this.MakeChoice(choice);

							if (result.Options.Count > 0)
							{
								cbea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(this, ref cbea);
								actionPerformed = true;
							}
						}

					} while (CardBought != null && actionPerformed);
				}
			}

			if (CardBuyFinished != null)
			{
				CardBuyEventArgs cbea = new CardBuyEventArgs(_Game, supplyCard);
				cbea.Cancelled = cancelled;
				CardBuyFinished(this, cbea);
			}

			if (!cancelled)
			{
				this.Gain(supply, true);

				this.SpendCurrency(new Currency(_Game.ComputeCost(supplyCard)));
				this.Buys--;
			}

			this.PlayerMode = previousMode;
			return cancelled;
		}
		void player_CardBought(object sender, CardBuyEventArgs e)
		{
			// Already been cancelled -- don't need to process this one
			if (e.Cancelled)
				return;

			if (e.HandledBy.Contains(this) || e.Actions.ContainsKey(TypeClass.Talisman))
				return;

			if ((e.Card.Category & Category.Victory) != Category.Victory && e.Game.Table[e.Card].CurrentCost <= new Coin(4))
			{
				Player player = sender as Player;
				e.Actions[TypeClass.Talisman] = new Players.CardBuyAction(this.Owner, this, String.Format("Gain a copy of {0}", e.Card), player_GainFromTalisman, true);
			}
		}
		void player_CardBought(object sender, CardBuyEventArgs e)
		{
			if (e.HandledBy.Contains(this) || e.Actions.ContainsKey(TypeClass.Hoard) || 
				(e.Card.Category & Category.Victory) != Category.Victory || !e.Game.Table.Gold.CanGain())
				return;

			Player player = sender as Player;
			e.Actions[TypeClass.Hoard] = new Players.CardBuyAction(this.Owner, this, "gain a Gold", player_BuyWithHoard, true);
		}
		void player_CardBought(object sender, CardBuyEventArgs e)
		{
			// Already been cancelled or processed -- don't need to process this one
			if (e.Cancelled || e.HandledBy.Contains(this))
				return;

			e.HandledBy.Add(this);

			(sender as Player).ReceiveBenefit(this, new CardBenefit() { VictoryPoints = 1 });
		}
Example #6
0
		void player_CardBought(object sender, CardBuyEventArgs e)
		{
			// Already been cancelled or processed -- don't need to process this one
			if (e.Cancelled || e.HandledBy.Contains(this))
				return;

			e.HandledBy.Add(this);

			(sender as Player).AddToken(new CoinToken());
		}