// get the next valid destination for player public int obtainTheNextDestination(You player) { if (this.isConditional == false) { Debug.Log(this.defaultDestination); return(this.defaultDestination); } ProgressionStats currentPlayerProgression = player.yourProgression; ProgressionStats nextProgressionCondition; // go through the list of possible destination one by one, the first match is the next destination // NOTE: list of possible destination need to be in descending order of more requirement to less requirement Debug.Log("checking"); for (int i = 0; i < this.possibleDestinationList.Count; i++) { nextProgressionCondition = this.possibleDestinationList [i].Key; if (isValidDestination(currentPlayerProgression, nextProgressionCondition)) { return(this.possibleDestinationList [i].Value); } } return(defaultDestination); }
// Use this for initialization void Start() { if (isTesting) { yourProgression = new ProgressionStats(0, 0, 0); } // load the latest stats // Set to not destroyable }
public static bool isValidDestination(ProgressionStats playerProgressionStats, ProgressionStats progressionCondition) { if (playerProgressionStats.getAffectionLevel() < progressionCondition.getAffectionLevel()) { return(false); } // get the required node Dictionary <int, List <int> > playerCompletedNodes = playerProgressionStats.getCompletedNodes(); Dictionary <int, List <int> > requiredNodes = progressionCondition.getCompletedNodes(); Dictionary <int, List <int> > .KeyCollection requiredDays = requiredNodes.Keys; int numberOfDaysInRequirement = requiredDays.Count; bool hasAllRequiredNodes = true; foreach (int day in requiredDays) { // check if day exist in player progression stats if (!playerCompletedNodes.ContainsKey(day)) { hasAllRequiredNodes = false; break; } List <int> requiredNodesInDay = new List <int>(); List <int> playerAccumulatedNodesInDay = new List <int>(); //obtain the required dialogues component playerCompletedNodes.TryGetValue(day, out requiredNodesInDay); requiredNodes.TryGetValue(day, out playerAccumulatedNodesInDay); if (requiredNodesInDay.Count == 0) { continue; } // Solution to check sublist gotten from stackoverflow, using system.linq hasAllRequiredNodes = !requiredNodes.Except(playerCompletedNodes).Any(); if (!hasAllRequiredNodes) { break; } } Debug.Log("check returns: " + hasAllRequiredNodes); return(hasAllRequiredNodes); }