// Buy 1 Card from the middle or from reserve. // Gold will be consumed automatically if required // Claim a noble if possible. If none is specified and you can afford one it will // be claimed automatically. public void Purchase(string id, Noble noble = null) { ThrowIfGameOver(); // Verify card is available or in reserve var fromReserve = CurrentPlayer.Reserve.Where(c => c.Id == id).SingleOrDefault(); var fromAvailable = Board.AvailableCards.Where(c => c.Id == id).SingleOrDefault(); var card = fromReserve ?? fromAvailable ?? throw new InvalidOperationException($"Card {id} could not be found."); // Verify card is affordable (inlcuding gold as needed) if (!Utilities.CanAfford(card.Cost, CurrentPlayer.TotalGems)) { throw new InvalidOperationException($"Cannot afford card id {id}."); } // Pay price (e.g. return tokens to bank as needed) foreach (var cost in card.Cost) { var diff = cost.Value - CurrentPlayer.Bonuses[cost.Key]; if (diff > 0) { var goldNeeded = diff - CurrentPlayer.Disks[cost.Key]; if (goldNeeded > 0) { CurrentPlayer.RemoveDisks(GemType.Gold, goldNeeded); Board.Bank.Return(GemType.Gold, goldNeeded); diff -= goldNeeded; } if (diff > 0) { CurrentPlayer.RemoveDisks(cost.Key, diff); Board.Bank.Return(cost.Key, diff); } } } // Move card from reserve or available to player's stack if (fromReserve != null) { CurrentPlayer.TransferFromReserve(card); } else { Board.TakeCard(card); CurrentPlayer.AddCard(fromAvailable); } ClaimNoble(noble); // Design bug: Claiming nobles is not part of the purchase action. Since it's possible for you // to be able to afford more than one when you're only allowed to take one, on your subsequent turn // you may claim another without an additional purchase. On that turn you may still have a choice, // so you need to be able specify a noble on any type of action. // Proposal: Many different actions require similar parameters. Make a general state object that // includes disk aquisitions, discards, noble selection, and a card selection id. The secret reservation // level is the only unique parameter. _passCount = 0; AdvanceGame(); }
IEnumerator DrawCard() { AudioSourceCard.Play(); CardHolder parent = tableaus[CurrentPlayerIdx]; LastDrawnCard = PopCard(parent.name != "Bottom"); yield return(CurrentPlayer.AddCard(LastDrawnCard, false)); OnDrawCard(); NumActions++; }
void AvailalbleCard_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (CurrentPlayer.State != PlayerState.Active) { return; } var control = sender as CardControl; CurrentPlayer.AddCard(control.Card); AvailableCard = null; DrawDecks(); }
private void PlayCard(PlayCardAction action) { var card = CurrentPlayer.RemoveCard(action.CardNumber); var risky = IsRisky(card); PutCard(card); if (risky) { WithRisk++; } CurrentPlayer.AddCard(Deck.PollCard()); }
IEnumerator GetCardFromGraveyardCR() { Interactable = false; if (graveyard.Count != 0) { CardHolder parent = tableaus[CurrentPlayerIdx]; Card card = graveyard.Pop(); card.FaceDown = CurrentPlayer != Me; ParticleSystem ps = Instantiate(ResurrectionPSPrefab, card.transform, false); ps.Play(); yield return(CurrentPlayer.AddCard(card, false)); } Interactable = true; }
/// <summary> /// Handles the double-click event for the discard pile. /// </summary> /// <param name="sender">The card clicked on the discard pile.</param> /// <param name="e"></param> private void AvailableCard_MouseDoubleClick(object sender, MouseButtonEventArgs e) { // Don't do anything if the current player isn't active. if (CurrentPlayer.State != PlayerState.Active) { return; } var control = sender as CardControl; // Add the available card to the player's hand. CurrentPlayer.AddCard(control.Card); AvailableCard = null; DrawDecks(); }
private void DropCard(DropCardAction action) { CurrentPlayer.RemoveCard(action.CardNumber); CurrentPlayer.AddCard(Deck.PollCard()); }
public static void EndOfRollOptions() { Tile tile = CurrentPlayer.Position; Property property = tile.GetComponent <Property>(); ChanceTile chance = tile.GetComponent <ChanceTile>(); //FreeParking parking = tile.GetComponent<FreeParking>(); SandLTile sAndL = tile.GetComponent <SandLTile>(); PaymentTile paymentTile = tile.GetComponent <PaymentTile>(); GoToJailTile goToJail = tile.GetComponent <GoToJailTile>(); if (property != null) { //check if the player stepped on an unowned/mortgaged/their own property if (property.Owner == null || property.Owner == CurrentPlayer || (property.Mortgaged && property.Owner != CurrentPlayer)) { MenuManager.SwitchToMenuWithInventory(MenuManager.EndOfTurnOptions); } else { PlayerMustPay(property.PaymentPrice()); } //display current property MenuManager.UpdateCardInfo(CurrentPlayer.Position.GetComponent <Property>()); } else if (chance != null || sAndL != null) { if (chance != null) { _activeCard = ChanceDeck.DrawCard(); } else if (sAndL != null) { if (UnityEngine.Random.Range(0f, 1f) < 0.5f) { _activeCard = new Snake(); } else { _activeCard = new Ladder(); } } //adds card to player's inventory CurrentPlayer.AddCard(ActiveCard); MenuManager.SwitchToMenuWithInventory(MenuManager.CardOptions); //pop up to show which card is drawn MenuManager.UpdateCardInfo(ActiveCard); } else if (paymentTile != null) { MenuManager.SwitchToMenuWithInventory(MenuManager.PaymentTileOptions); } else if (goToJail != null) // if on go to jail tile { //create new card, uses it, deletes it _activeCard = new CardMove("Go to Jail - Go directly to Jail - Do not pass Go, do not collect $200", EnumsForCards.cardMove.goToJail); CurrentPlayer.AddCard(ActiveCard); MenuManager.SwitchToMenuWithInventory(MenuManager.CardOptions); MenuManager.UpdateCardInfo(ActiveCard); ChanceDeck.DeleteLastCard(); } else { MenuManager.SwitchToMenuWithInventory(MenuManager.EndOfTurnOptions); } }