Ejemplo n.º 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));
		}
Ejemplo n.º 2
0
		private void CardGainFinish(Card card, DeckLocation location, DeckPosition position, Boolean isBought, Boolean isCancelled, Boolean isLostTrackOf)
		{
			if (CardGainFinished != null)
			{
				CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
				cgea.Cancelled = isCancelled;
				cgea.IsLostTrackOf = isLostTrackOf;
				CardGainFinished(this, cgea);
			}
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Tries to gain the specified card into the location and position of the deck specified
		/// </summary>
		/// <param name="card">The card to gain from the supply</param>
		/// <param name="location">The deck the card should go into</param>
		/// <param name="position">The position into the deck the card should go</param>
		/// <param name="isBought">Indicating whether or not the card was bought</param>
		/// <returns>True if the card was actually gained, False otherwise</returns>
		private Boolean Gain(Card card, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			if (card == null)
				return false;

			Boolean cancelled = false;
			Boolean lostTrackOf = false;
			if (CurrentTurn != null)
				CurrentTurn.Gained(card);

			CardGainInto(card, location, position, isBought, false, false);

			if (CardGained != null)
			{
				// This is a little bit wacky, but we're going to set up an event listener INSIDE this method that listens to both
				// the Discard Pile and the Draw Pile for changes.  We need to do this in order to capture any "Lost Track" updates
				// that might happen from one card covering up another card (e.g. this card being gained) and causing the game state
				// to "Lose Track" of the card being gained in this method.
				_LostTrackStack[card] = false;
				Pile.PileChangedEventHandler pceh = new Pile.PileChangedEventHandler(DiscardPile_PileChanged_CaptureLostTrack);
				this.DiscardPile.PileChanged += pceh;

				List<Object> handledBy = new List<Object>();
				CardGainEventArgs cgea = null;
				Boolean actionPerformed = false;
				do
				{
					actionPerformed = false;

					cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
					cgea.HandledBy.AddRange(handledBy);
					cgea.Cancelled = cancelled;
					cgea.IsLostTrackOf = lostTrackOf;
					CardGained(this, cgea);
					handledBy = cgea.HandledBy;
					cancelled |= cgea.Cancelled;
					lostTrackOf |= cgea.IsLostTrackOf || _LostTrackStack[card];
					location = cgea.Location;
					position = cgea.Position;

					IEnumerator<Player> enumerator = this._Game.GetPlayersStartingWithEnumerator(this);
					while (enumerator.MoveNext())
					{
						Boolean isAnyRequired = false;
						List<String> options = new List<String>();
						IEnumerable<Type> cardTypes = cgea.Actions.Keys;
						foreach (Type key in cardTypes)
						{
							if (enumerator.Current == cgea.Actions[key].Player)
							{
								options.Add(cgea.Actions[key].Text);
								isAnyRequired |= cgea.Actions[key].IsRequired;
							}
						}
						if (options.Count > 0)
						{
							Choice choice = new Choice(String.Format("{0} gained {1}", this == enumerator.Current ? "You" : this.ToString(), card), null, new CardCollection() { card }, options, this, cgea, false, isAnyRequired ? 1 : 0, 1);
							ChoiceResult result = enumerator.Current.MakeChoice(choice);

							if (result.Options.Count > 0)
							{
								options.Sort();
								cgea.Actions.First(kvp => kvp.Value.Text == result.Options[0]).Value.Method(enumerator.Current, ref cgea);
								actionPerformed = true;
							}

							if (enumerator.Current == this && (cgea.Location != location || cgea.Position != position))
								CardGainInto(card, cgea.Location, cgea.Position, cgea.Bought, cgea.Cancelled, cgea.IsLostTrackOf);

							cancelled |= cgea.Cancelled;
							lostTrackOf |= cgea.IsLostTrackOf || _LostTrackStack[card];
							location = cgea.Location;
							position = cgea.Position;
						}
					}
				} while (CardGained != null && actionPerformed);

				if (pceh != null)
					this.DiscardPile.PileChanged -= pceh;
				_LostTrackStack.Remove(card);
			}

			CardGainFinish(card, location, position, isBought, cancelled, lostTrackOf);

			return true;
		}
Ejemplo n.º 4
0
		private void CardGainInto(Card card, DeckLocation location, DeckPosition position, Boolean isBought, Boolean isCancelled, Boolean isLostTrackOf)
		{
			if (this.DiscardPile.Contains(card))
				this.RetrieveCardFrom(DeckLocation.Discard, card);
			card.Gaining(this, ref location, ref position);
			this.AddCardInto(location, card, position);
			card.Gained(this);

			if (CardGainedInto != null)
			{
				CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
				cgea.Cancelled = isCancelled;
				cgea.IsLostTrackOf = isLostTrackOf;
				CardGainedInto(this, cgea);
			}
		}
Ejemplo n.º 5
0
		private CardGainEventArgs CardGainCheckAllowed(Card card, DeckLocation location, DeckPosition position, Boolean isBought)
		{
			Boolean cancelled = false;
			CardGainEventArgs cgea = new CardGainEventArgs(_Game, card, location, position, isBought);

			if (CardGaining != null)
			{
				do
				{
					cgea = new CardGainEventArgs(_Game, card, location, position, isBought);
					cgea.Cancelled = cancelled;
					CardGaining(this, cgea);

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

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

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

					cancelled = cgea.Cancelled;
					location = cgea.Location;
					position = cgea.Position;
				} while (CardGaining != null && cgea.HandledBy.Count > 0);
			}
			return cgea;
		}