public IEnumerator CheckForPossibleTransitionAndDoIt(Action<bool> setIsRunningBool, float waitForSeconds, HPlayerModel model, params FactQuery[] queries) { if ((currStoryElement == null) || (currStoryElement.neighborStateID.Count == 0)) yield break; setIsRunningBool(true); foreach (uint nextStateID in currStoryElement.neighborStateID) { // take the next possible story state StoryElement se = StoryElement.GetByID(nextStateID); // and each criteria in it int criteriaCount = se.transitionToCriteria.Count; foreach(KeyValuePair<uint, StoryElement.CriteriaValue> c in se.transitionToCriteria) { // check HPlayerModel HPlayerModel.Trait t = HPlayerModel.Trait.TryGetTrait(c.Key); if (t != null) { if (c.Value.compareTo(c.Value.value, (int)model.GetNodeValue(t))) criteriaCount--; } else { // if criteria is not in a HPlayerModel // check against all queries foreach (FactQuery q in queries) { int value = 0; // try get the concept value from player/world/... facts FactQuery.Concept concept = (FactQuery.Concept)c.Key; //Debug.Log (concept); if (q.TryGetFactValue(concept, out value)) { // if it matches with the laws criteria, continue if (c.Value.compareTo(value, c.Value.value)) criteriaCount--; // query doesn't contain the corresponding fact value, move to next query else continue; } } } // return in 3 seconds and resume work yield return new WaitForSeconds(3); // if matching law with the most criteria was found if (criteriaCount == 0) { se.ApplyToGameplay(); Messenger.Broadcast("A slight change in the story is coming right up!"); StoryManager.currStoryElement = se; goto BreakForTimeX; // I'm going to hell for his. I just know it. Please forgive me! } } } BreakForTimeX: yield return new WaitForSeconds(waitForSeconds); setIsRunningBool(false); yield break; }
public IEnumerator CheckLawsWithFactQuery(HPlayerModel model, params FactQuery[] queries) { Messenger.Broadcast("I have to check with the laws what happened there."); // Sort list of laws by number of criteria desc. collection.OrderByDescending(l => l.criteria.Count()).ToList(); Debug.Log("Checking with " + collection.Count + " laws."); // for each law foreach(Law l in collection) { // and each criteria in it int criteriaCount = l.criteria.Count; foreach(KeyValuePair<uint, Law.CriteriaValue> c in l.criteria) { // check HPlayerModel HPlayerModel.Trait t = HPlayerModel.Trait.TryGetTrait(c.Key); if (t != null) { if (c.Value.compareTo(c.Value.value, (int)model.GetNodeValue(t))) criteriaCount--; } else { // if criteria is not in a HPlayerModel // check against all queries foreach (FactQuery q in queries) { int value = 0; // try get the concept value from player/world/... facts FactQuery.Concept concept = (FactQuery.Concept)c.Key; Debug.Log (concept); if (q.TryGetFactValue(concept, out value)) { // if it matches with the laws criteria, continue if (c.Value.compareTo(value, c.Value.value)) criteriaCount--; // query doesn't contain the corresponding fact value, move to next query else continue; } } } // return in 3 seconds and resume work yield return new WaitForSeconds(3); // if matching law with the most criteria was found if (criteriaCount == 0) { l.ApplyToGameplay(); Messenger.Broadcast("O.K. You broke the law."); yield break; } } } Messenger.Broadcast("O.K. You're clean. For now..."); }