//Gets valid card based on Player's stats, features and history public ActivityCard GetCard(int currentTurn, CardIntDictionary choiceHistory, PlayerStatIntDictionary playerStats, HashSet <BusinessFeatureTitle> purchasedFeatures) { ActivityCard result = null; //Check priority queue first if (priorityCards.Count > 0) { var queueCard = priorityCards.Dequeue(); if (queueCard.ValidateCard(currentTurn, purchasedFeatures, playerStats, choiceHistory)) { result = queueCard; } } else //otherwise find random valid card from list of all cards { //super duper excellent algorithm for getting random card.. HashSet <int> used = new HashSet <int>(); while (result == null && used.Count < deck.Count) { int index = Random.Range(0, deck.Count); if (!used.Contains(index)) { used.Add(index); if (deck[index].ValidateCard(currentTurn, purchasedFeatures, playerStats, choiceHistory)) { result = deck[index]; deck.RemoveAt(index); } } } //for(int i = 0; i < deck.Count; i++) //{ //} } if (result != null) { return(result); } else { //No cards returned.. Debug.Log("No valid cards were found", this); return(null); } }
public void FillHand(int currentTurn, CardIntDictionary choiceHistory, PlayerStatIntDictionary playerStats, HashSet <BusinessFeatureTitle> purchasedFeatures) { //Gets card asset from deck, instantiates new cards with that asset //Until hand is full while (handTransform.childCount < maxCardsInHand) { ActivityCard newCard = deck.GetCard(currentTurn, choiceHistory, playerStats, purchasedFeatures); if (newCard == null) { Debug.Log("No new cards found"); break; } //spawn coop or individual card GameObject c = newCard.cooperative ? Instantiate(coopCardPrefab, handTransform, false) : Instantiate(individualCardPrefab, handTransform, false); c.GetComponent <CardController>().cardData = newCard; c.GetComponent <CardController>().playerHandController = this; } //Set interactable status in all cards SetInteractableInCards(); }
//input: Dictionary representing player's stats private bool ValidateStatPrerequisites(PlayerStatIntDictionary playerStats) { //iterate over every prerequisite, check if it matches what is in input dict foreach (StatPrerequisite statPrerequisite in statPrerequisites) { if (statPrerequisite.statMustBeEqualOrGreater) { if (playerStats[statPrerequisite.stat] < statPrerequisite.targetValue) { return(false); } } else { if (playerStats[statPrerequisite.stat] >= statPrerequisite.targetValue) { return(false); } } } //no mismatches found, card's statprerequisites are met return(true); }
//returns whether all prerequisites are met public bool ValidateChoice(HashSet <BusinessFeatureTitle> purchasedFeatures, PlayerStatIntDictionary playerStats) { return(ValidateFeaturePrerequisites(purchasedFeatures) && ValidateStatPrerequisites(playerStats)); }
public bool CanBePurchased(PlayerStatIntDictionary playerStats) { return(playerStats[PlayerStat.capital] >= cost); }
//returns whether all prerequisites are met public bool ValidateCard(int currentTurn, HashSet <BusinessFeatureTitle> purchasedFeatures, PlayerStatIntDictionary playerStats, CardIntDictionary choiceHistory) { //not valid if player has played card before if (choiceHistory.ContainsKey(this)) { return(false); } //otherwise check all prerequisites return(ValidateTurn(currentTurn) && ValidateFeaturePrerequisites(purchasedFeatures) && ValidateStatPrerequisites(playerStats) && ValidateChoicePrerequisites(choiceHistory)); }