// Use this for initialization void Start() { // TODO figure out if local player List <NetworkPlayer> networkPlayers = NetworkManager.Instance.getPlayerList(); foreach (NetworkPlayer player in networkPlayers) { if (player.isLocalPlayer) { player.controller = this; localNetworkPlayer = player; } } sp = GameObject.Find("Sphere"); DontDestroyOnLoad(this); List <string> playerList = new List <string>(); //GameObject.Find("Sphere").SetActive(false); //name = gameobject.PersistentPlayerData.getCompanyName(); choiceHistory = new CardIntDictionary(); cardsPlayedLastTurn = new CardIntDictionary(); // assign unique player ID? }
//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); } }
//input: dictionary containing all Card+Choice pairs player has played currently private bool ValidateChoicePrerequisites(CardIntDictionary playerChoiceHistory) { //iterate over every prerequisite, validate that player has played the card and made the required choice foreach (ChoicePrerequisite prerequisite in choicePrerequisites) { //check if player has played card if (playerChoiceHistory.ContainsKey(prerequisite.card)) { //check if player has made the required choice if (playerChoiceHistory[prerequisite.card] != prerequisite.choiceIndex) { return(false); } } else { return(false); } } //No mismatches found, card's prerequisites are met return(true); }
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(); }
public bool ValidateItem(int playerNewsCounter, CardIntDictionary playerChoiceHistory) { return(playerNewsCounter >= newsCounterMinimum && ValidateChoicePrerequisites(playerChoiceHistory)); }
//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)); }