Exemplo n.º 1
0
		internal override void TrashedBy(Player player)
		{
			base.TrashedBy(player);

			// Need to reset any Gain triggers when we're trashed -- we can technically be gained from the Trash
			ResetTriggers(player._Game);
		}
Exemplo n.º 2
0
		public override void Play(Player player)
		{
			base.Play(player);

			Choice choice = new Choice("Trash a card. +<vp/> equal to half its cost in coins, rounded down.", this, player.Hand, player);
			ChoiceResult result = player.MakeChoice(choice);
			if (result.Cards.Count > 0)
			{
				Card trash = player.RetrieveCardFrom(DeckLocation.Hand, result.Cards[0]);
				Cost trashedCardCost = player._Game.ComputeCost(trash);
				player.Trash(trash);

				player.ReceiveBenefit(this, new CardBenefit() { VictoryPoints = trashedCardCost.Coin.Value / 2 });
			}

			IEnumerator<Player> enumerator = player._Game.GetPlayersStartingWithEnumerator(player);
			enumerator.MoveNext(); // skip active player
			while (enumerator.MoveNext())
			{
				Player otherPlayer = enumerator.Current;
				Choice choicePlayer = new Choice("Trash a card if you wish", this, otherPlayer.Hand, otherPlayer, false, 0, 1);
				ChoiceResult resultPlayer = otherPlayer.MakeChoice(choicePlayer);
				if (resultPlayer.Cards.Count > 0)
				{
					otherPlayer.Trash(otherPlayer.RetrieveCardFrom(DeckLocation.Hand, resultPlayer.Cards[0]));
				}
			}
		}
Exemplo n.º 3
0
		public void AddRange(Player player, IEnumerable<Card> cardCollection, DeckPosition deckPosition)
		{
			switch (deckPosition)
			{
				case DeckPosition.Top:
					_Cards.InsertRange(0, cardCollection.Reverse());
					break;
				case DeckPosition.Bottom:
					_Cards.AddRange(cardCollection);
					break;
			}
			this.Sort();

			if (cardCollection.Count() > 0)
			{
				if (_AsynchronousChanging)
				{
					if (_AsynchronousPileChangedEventArgs == null)
						_AsynchronousPileChangedEventArgs = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
					else
						_AsynchronousPileChangedEventArgs.AddedCards.AddRange(cardCollection);
				}
				else if (PileChanged != null)
				{
					lock (PileChanged)
					{
						PileChangedEventArgs pcea = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
						PileChanged(this, pcea);
					}
				}
			}
		}
Exemplo n.º 4
0
		public PlayerModeChangedEventArgs(Player player, PlayerMode oldPlayerMode)
		{
			CurrentPlayer = player;
			OldPlayerMode = oldPlayerMode;
			if (player != null)
				NewPlayerMode = player.PlayerMode;
		}
Exemplo n.º 5
0
		public PhaseChangedEventArgs(Player player, PhaseEnum oldPhase)
		{
			CurrentPlayer = player;
			OldPhase = oldPhase;
			if (player != null)
				NewPhase = player.Phase;
		}
Exemplo n.º 6
0
		public PhaseChangingEventArgs(Player player, PhaseEnum newPhase)
		{
			CurrentPlayer = player;
			if (player != null)
				CurrentPhase = player.Phase;
			NewPhase = newPhase;
		}
Exemplo n.º 7
0
		public override void Play(Player player)
		{
			base.Play(player);

			player.Gain(player._Game.Table.Silver, DeckLocation.Deck, DeckPosition.Top);

			// Perform attack on every player (including you)
			IEnumerator<Player> enumerator = player._Game.GetPlayersStartingWithEnumerator(player);
			enumerator.MoveNext();
			while (enumerator.MoveNext())
			{
				Player attackee = enumerator.Current;
				// Skip if the attack is blocked (Moat, Lighthouse, etc.)
				if (this.IsAttackBlocked[attackee])
					continue;

				if (attackee.Hand[Category.Victory].Count == 0)
				{
					attackee.ReturnHand(attackee.RevealHand());
				}
				else
				{
					Choice replaceChoice = new Choice("Choose a card to put back on your deck", this, attackee.Hand[Category.Victory], attackee);
					ChoiceResult replaceResult = attackee.MakeChoice(replaceChoice);
					if (replaceResult.Cards.Count > 0)
					{
						Card returnCard = attackee.RetrieveCardFrom(DeckLocation.Hand, replaceResult.Cards[0]);
						attackee.AddCardInto(DeckLocation.Revealed, returnCard);
						attackee.AddCardToDeck(attackee.RetrieveCardFrom(DeckLocation.Revealed, returnCard), DeckPosition.Top);
					}
				}
			}
		}
Exemplo n.º 8
0
		internal Card Retrieve(Player player, Card card)
		{
			CardCollection cc = Retrieve(player, c => c == card);
			if (cc.Count == 0)
				throw new Exception(String.Format("Cannot find card {0}", card));
			return cc[0];
		}
Exemplo n.º 9
0
		public override void Play(Player player)
		{
			base.Play(player);

			CardBenefit benefit = new CardBenefit();
			benefit.Currency += new Coin(player.InPlay[Category.Treasure].Count);
			player.ReceiveBenefit(this, benefit);
		}
Exemplo n.º 10
0
		public BenefitsChangedEventArgs(Player player)
		{
			this.Player = player;
			this.Actions = player.Actions;
			this.Buys = player.Buys;
			// Make a copy of this so it can't be changed
			this.Currency = new Currency(player.Currency);
		}
Exemplo n.º 11
0
		internal void player_Action(Player player, ref CardsDiscardEventArgs e)
		{
			e.Cards.Remove(this.PhysicalCard);
			Card thisCard = null;
			if (player.InPlay.Contains(this.PhysicalCard))
				thisCard = player.RetrieveCardFrom(DeckLocation.InPlay, this.PhysicalCard);
			else
				thisCard = player.RetrieveCardFrom(DeckLocation.SetAside, this.PhysicalCard);
			player.AddCardToDeck(thisCard, DeckPosition.Top);
		}
Exemplo n.º 12
0
		public override void Play(Player player)
		{
			base.Play(player);
			player.BeginDrawing();
			while (player.Revealed[Category.Treasure].Count < 2 && player.CanDraw)
				player.Draw(DeckLocation.Revealed);

			player.EndDrawing();

			player.AddCardsToHand(player.RetrieveCardsFrom(DeckLocation.Revealed, c => (c.Category & Category.Treasure) == Category.Treasure));

			player.DiscardRevealed();
		}
Exemplo n.º 13
0
		private Choice(String text, Card cardSource, CardCollection cardTriggers, ChoiceType choiceType, Player playerSource, EventArgs eventArgs, Boolean isOrdered, Boolean isSpecific, int minimum, int maximum)
		{
			_Text = text;
			_CardSource = cardSource;
			_CardTriggers = cardTriggers;
			_ChoiceType = choiceType;
			_PlayerSource = playerSource;
			_EventArgs = eventArgs;
			_IsOrdered = isOrdered;
			_IsSpecific = isSpecific;
			_Minimum = minimum < 0 ? 0 : minimum;
			_Maximum = maximum < _Minimum ? _Minimum : maximum;
		}
Exemplo n.º 14
0
		public override void Play(Player player)
		{
			base.Play(player);

			Choice choiceCard = new Choice("Reveal a card from your hand to return up to 2 to the Supply.", this, player.Hand, player);
			ChoiceResult resultCard = player.MakeChoice(choiceCard);

			if (resultCard.Cards.Count > 0)
			{
				Card revealedCard = resultCard.Cards[0];
				player.AddCardInto(DeckLocation.Revealed, player.RetrieveCardFrom(DeckLocation.Hand, revealedCard));
				player.AddCardInto(DeckLocation.Hand, player.RetrieveCardFrom(DeckLocation.Revealed, revealedCard));

				Supply supply = player._Game.Table.FindSupplyPileByCard(revealedCard);
				if (supply != null)
				{
					List<String> options = new List<string>() { "0", "1" };
					if (player.Hand[revealedCard.CardType].Count > 1)
						options.Add("2");
					Choice choice = new Choice("How many would you like to return to the Supply?", this, new CardCollection() { revealedCard }, options, player);
					ChoiceResult result = player.MakeChoice(choice);

					int numberToReturn = int.Parse(result.Options[0]);
					if (numberToReturn > 0)
					{
						CardCollection cardsToReturn = player.RetrieveCardsFrom(DeckLocation.Hand, revealedCard.CardType, numberToReturn);
						player.Lose(cardsToReturn);
						supply.AddTo(cardsToReturn);
					}

					player._Game.SendMessage(player, this, supply, numberToReturn);
				}

				IEnumerator<Player> enumerator = player._Game.GetPlayersStartingWithEnumerator(player);
				enumerator.MoveNext();
				while (enumerator.MoveNext())
				{
					Player attackee = enumerator.Current;
					// Skip if the attack is blocked (Moat, Lighthouse, etc.)
					if (this.IsAttackBlocked[attackee])
						continue;

					if (supply != null && supply.CanGain() && supply.TopCard.Name == revealedCard.Name)
						attackee.Gain(supply);
				}
			}
		}
Exemplo n.º 15
0
		public override void Play(Player player)
		{
			base.Play(player);
			player.Draw(3, DeckLocation.Revealed);

			IEnumerator<Player> enumerator = player._Game.GetPlayersStartingWithEnumerator(player);
			enumerator.MoveNext(); // Gets us... which we don't care about here.
			enumerator.MoveNext(); // Get the player to our left

			Player leftPlayer = enumerator.Current;
			Choice choice = new Choice(String.Format("Choose a card of {0}'s to discard", player), this, player.Revealed, player);
			ChoiceResult result = leftPlayer.MakeChoice(choice);
			// Discard the chosen card
			if (result.Cards.Count > 0)
				player.Discard(DeckLocation.Revealed, result.Cards[0]);
			player.AddCardsToHand(DeckLocation.Revealed);
		}
Exemplo n.º 16
0
		public override void Play(Player player)
		{
			base.Play(player);
			if (player.Hand[Cards.Universal.TypeClass.Estate].Count > 0)
			{
				Choice choice = Choice.CreateYesNoChoice("You may discard an Estate card for +<coin>4</coin>.  Do you want to discard?", this, player);
				ChoiceResult result = player.MakeChoice(choice);
				if (result.Options.Contains("Yes"))
				{
					player.Discard(DeckLocation.Hand, Cards.Universal.TypeClass.Estate, 1);

					CardBenefit benefit = new CardBenefit();
					benefit.Currency.Coin += 4;
					player.ReceiveBenefit(this, benefit);

					return;
				}
			}

			player.Gain(player._Game.Table.Estate);
		}
Exemplo n.º 17
0
		public PlayerChoiceMessage(Player player, ChoiceResult choiceResult)
			: this(null, player, choiceResult)
		{
		}
Exemplo n.º 18
0
		/// <summary>
		/// Fires off the Attack event, so any listeners can pick it up.
		/// </summary>
		/// <param name="player">The attacking player</param>
		/// <param name="attackingCard">The card that triggered the Attack event</param>
		/// <returns>"true" if the Attack can proceed (wasn't blocked).  "false" if the Attack was blocked.</returns>
		/// <summary>
		public Boolean AttackedBy(Player attacker, Card attackingCard)
		{
			if (Attacked != null)
			{
				AttackedEventArgs aea = null;
				Boolean cancelled = false;
				do
				{
					aea = new AttackedEventArgs(attacker, attackingCard);
					aea.Cancelled |= cancelled;
					Attacked(this, aea);

					CardCollection cards = new CardCollection(aea.Revealable.Values.Select(s => s.Card));
					if (cards.Count > 0)
					{
						cards.Sort();
						Choice choice = new Choice("Reveal a card?", null, attackingCard, cards, this, true, aea);
						ChoiceResult result = this.MakeChoice(choice);

						if (result.Cards.Count > 0)
							aea.Revealable[result.Cards[0].CardType].Method(this, ref aea);
						else
							break;
					}

					cancelled |= aea.Cancelled;

				} while (Attacked != null && aea.HandledBy.Count > 0);

				if (aea != null)
					cancelled |= aea.Cancelled;

				return !cancelled;
			}
			return true;
		}
Exemplo n.º 19
0
		internal void SetupDeckAs(Player player)
		{
			CardCollection cards = new CardCollection(this.RetrieveCardsFrom(DeckLocation.Hand).Union(this.RetrieveCardsFrom(DeckLocation.Deck)));
			foreach (Card sourceCard in player.Hand)
			{
				Card myFoundCard = cards.First(c => c.CardType == sourceCard.CardType);
				cards.Remove(myFoundCard);
				this.AddCardInto(DeckLocation.Hand, myFoundCard);
			}
			this.AddCardsInto(DeckLocation.Deck, cards);
		}
Exemplo n.º 20
0
		internal double SumAll(Player fromPlayer, Predicate<Card> filterPredicate, Func<Card, double> sumSelector, Boolean onlyObtainable, Boolean onlyCurrentlyDrawable)
		{
			double sum = 0;
			sum += this.DiscardPile.LookThrough(filterPredicate).Sum(sumSelector);
			sum += this.DrawPile.LookThrough(filterPredicate).Sum(sumSelector);

			if (!onlyCurrentlyDrawable)
			{
				sum += this.Hand[filterPredicate].Sum(sumSelector);
				sum += this.Private[filterPredicate].Sum(sumSelector);
				sum += this.Revealed[filterPredicate].Sum(sumSelector);
				sum += this.InPlay[filterPredicate].Sum(sumSelector);
				sum += this.SetAside[filterPredicate].Sum(sumSelector);

				foreach (Type deckType in this.PlayerMats.Keys)
				{
					// Don't count cards on mats that you can't obtain cards from
					if (onlyObtainable && !this.PlayerMats[deckType].IsObtainable)
						continue;
					sum += this.PlayerMats[deckType].LookThrough(filterPredicate).Sum(sumSelector);
				}
			}
			return sum;
		}
Exemplo n.º 21
0
		internal double SumAll(Player fromPlayer, Predicate<Card> filterPredicate, Func<Card, double> sumSelector)
		{
			return SumAll(fromPlayer, filterPredicate, sumSelector, true, false);
		}
Exemplo n.º 22
0
		internal int CountAll(Player fromPlayer, Predicate<Card> predicate, Boolean onlyObtainable, Boolean onlyCurrentlyDrawable)
		{
			int count = 0;
			count += this.DiscardPile.LookThrough(predicate).Count;
			count += this.DrawPile.LookThrough(predicate).Count;

			if (!onlyCurrentlyDrawable)
			{
				count += this.Hand[predicate].Count;
				count += this.Private[predicate].Count;
				count += this.Revealed[predicate].Count;
				count += this.InPlay[predicate].Count;
				count += this.SetAside[predicate].Count;

				foreach (Type deckType in this.PlayerMats.Keys)
				{
					// Don't count cards on mats that you can't obtain cards from
					if (onlyObtainable && !this.PlayerMats[deckType].IsObtainable)
						continue;
					count += this.PlayerMats[deckType].LookThrough(predicate).Count;
				}
			}
			return count;
		}
Exemplo n.º 23
0
		internal int CountAll(Player fromPlayer, Predicate<Card> predicate)
		{
			return CountAll(fromPlayer, predicate, true, false);
		}
Exemplo n.º 24
0
		internal void player_DiscardHand(Player player, ref CardsDiscardEventArgs e)
		{
			CardMovementCollection cardsToMove = (CardMovementCollection)e.Data;

			// Discard Hand
			this.AddCardsInto(DeckLocation.Discard,
				this.RetrieveCardsFrom(DeckLocation.Hand, c =>
					cardsToMove[c].CurrentLocation == DeckLocation.Hand && cardsToMove[c].Destination == DeckLocation.Discard));

			e.HandledBy.Add(this);
		}
Exemplo n.º 25
0
		public void Receive(Player fromPlayer, Card card, DeckLocation location, DeckPosition position)
		{
			if (CurrentTurn != null)
				CurrentTurn.Received(card);
			this.AddCardInto(location, card, position);
			card.ReceivedBy(this);

			if (CardReceived != null)
			{
				CardReceivedEventArgs crea = new CardReceivedEventArgs(fromPlayer, card, location, position);
				CardReceived(this, crea);
			}
		}
		public void TearDown()
		{
			this.IsActive = false;
			this.Player = null;
		}
Exemplo n.º 27
0
		public override void Play(Player player)
		{
			base.Play(player);

			CardCollection newCards = player.Draw(4, DeckLocation.Revealed);

			player.AddCardsToHand(player.RetrieveCardsFrom(DeckLocation.Revealed,
				c => c.CardType == Universal.TypeClass.Copper || c.CardType == Alchemy.TypeClass.Potion));

			Choice replaceChoice = new Choice("Choose order of cards to put back on your deck", this, player.Revealed, player, true, player.Revealed.Count, player.Revealed.Count);
			ChoiceResult replaceResult = player.MakeChoice(replaceChoice);
			player.RetrieveCardsFrom(DeckLocation.Revealed, replaceResult.Cards);
			player.AddCardsToDeck(replaceResult.Cards, DeckPosition.Top);
		}
Exemplo n.º 28
0
		/// <summary>
		/// Fires off the TokenAction event, so any listeners can pick it up.
		/// </summary>
		/// <param name="actor">The acting player (the one playing the card)</param>
		/// <param name="actingCard">The card that triggered the TokenAction event</param>
		/// <returns>"true" if the TokenAction can proceed (wasn't blocked).  "false" if the TokenAction was blocked.</returns>
		public Boolean TokenActOn(Player actor, Card actingCard)
		{
			if (TokenActedOn != null)
			{
				TokenActionEventArgs taea = new TokenActionEventArgs(actor, this, actingCard);
				TokenActedOn(this, taea);
				return !taea.Cancelled;
			}
			return true;
		}
Exemplo n.º 29
0
		public PlayerChoiceMessage(AutoResetEvent returnEvent, Player player, ChoiceResult choiceResult)
			: base(returnEvent)
		{
			Player = player;
			ChoiceResult = choiceResult;
		}
Exemplo n.º 30
0
		public override void Play(Player player)
		{
			base.Play(player);
			SupplyCollection gainableSupplies = player._Game.Table.Supplies.FindAll(
				supply => supply.CanGain() && 
					((supply.Category & Cards.Category.Action) == Cards.Category.Action) && 
					supply.CurrentCost <= new Coin(5));
			Choice choice = new Choice("You may gain an Action card costing up to <coin>5</coin>", this, gainableSupplies, player, true);
			ChoiceResult result = player.MakeChoice(choice);
			if (result.Supply != null)
				player.Gain(result.Supply);
		}