// Use this for initialization void Start() { instance = this; storyState = new List <int>(init); // Process all rules, checking for similar rules. for (int i = 0; i < rules.Count; i++) { if (rules[i].hasBeenProcessed) { continue; } LoreProcessedRule processedRule = new LoreProcessedRule(rules[i], i); rules[i].hasBeenProcessed = true; for (int j = i + 1; j < rules.Count; j++) { if (rules[i].HasSameConsumedProperties(rules[j].ConsumedProperties)) { processedRule.AddRule(rules[j], j); rules[j].hasBeenProcessed = true; } } processedRules.Add(processedRule); } }
void OnEnable() { t = (LoreManager)target; GetTarget = new SerializedObject(t); rules = GetTarget.FindProperty("rules"); // Find the List in our script and create a refrence of it init = GetTarget.FindProperty("init"); }
int ProcesRuleOutcom(int outcome, List <int> storyState) { // add produced properties to the storystate. for (int i = 0; i < producedProperties[outcome].Count; i++) { LoreManager.LOOP_COUNTER++; storyState.Add(producedProperties[outcome][i]); } Debug.Log(producedStory[outcome]); LoreManager.GetInstance().UpdateStory(producedStory[outcome]); return(ruleNumber[outcome]); }
// Activate the rule. public int DoRule(List <int> storyState) { // Remove all consumed properties from the storystate. for (int i = 0; i < consumedProperties.Count; i++) { for (int j = 0; j < storyState.Count; j++) { LoreManager.LOOP_COUNTER++; storyState.Remove(consumedProperties[i]); } } // if only one rule if (!HasSimilarRules) { // Add produced properties to the storystate return(ProcesRuleOutcom(0, storyState)); } else //more than 1 with the same input { if (Random.Range(0, 100) >= LoreManager.GetInstance().GetUserChoicePercentage())//No user choice story continue { // Create a random number depending on how many different outcomes there are for this rule. int randomOutcome = (Random.Range(0, 99) / (int)RuleChance); if (randomOutcome >= producedProperties.Count || randomOutcome < 0) { Debug.Log("Something went wrong with randomOutcome in LoreProcessedRule"); } return(ProcesRuleOutcom(randomOutcome, storyState)); } else//User choice { CreateUserChoice(AmountOfRules, storyState); return(-1); } } }