public void applyCure(ToolBox.Tool tool, BodyPartType part) { // Skip if no tool set if (tool == ToolBox.Tool.None) { return; } // Test out the rule system bool fixesColor = false; bool success = RulesSystem.EvaluateCure(bodyParts, tool, part, bodyColor, ref heartbeat, out fixesColor); // Did color get fixed? if (fixesColor) { bodyColor = BodyPartColor.White; SetupColor(); } // Tell game controller if we did this wrong if (!success) { GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController"); GameController gameController = gameControllerObject.GetComponent(typeof(GameController)) as GameController; gameController.FailedCureAttempt(); painLevel = BodyPainLevel.Worse; lastOuch = Time.time; } sound.playBodyEffect(tool, success); }
public void playBodyEffect(ToolBox.Tool tool, bool correctTreatment) { //Debug.Log("Playing sound effect for touching body using tool: " + tool); AudioClip[] toolNoise; switch (tool) { case ToolBox.Tool.Injector: toolNoise = injectorApply; break; case ToolBox.Tool.Ointment: toolNoise = ointmentApply; break; case ToolBox.Tool.Tourniquet: toolNoise = tourniquetApply; break; case ToolBox.Tool.Pill: toolNoise = pillApply; break; default: toolNoise = pillApply; break; } playEffect(toolNoise); AudioClip[] bodyNoise; if (correctTreatment) { bodyNoise = bodyReactionGood; } else { bodyNoise = bodyReactionBad; } playEffect(bodyNoise); }
// For each rule solution, see if it applies to the given params. Removes the rule // solution on success, returning true. Else return false. private static bool EvaluateRuleSolutions(Rule rule, ToolBox.Tool playersTool, BodyPartType playersTargetBodyPart) { for (int i = 0; i < rule.ruleSolutions.Count; i++) { RuleSolution ruleSolution = rule.ruleSolutions[i]; if (ruleSolution.tool == playersTool) { bool isValidBodyPart = (ruleSolution.bodyPart == playersTargetBodyPart); if ((ruleSolution.isBodyPartSpecific == false) || (ruleSolution.isBodyPartSpecific && isValidBodyPart)) { rule.ruleSolutions.RemoveAt(i); return(true); } } } // Never matched return(false); }
// On hit, we talk to the owning parent void OnMouseDown() { // Debug.Log("The parent was clicked! Tag: " + tag + "Name: " + name ); switch (tag) { //Body parts: case "Body": //Tell the body that the current Tool has touched it BodyPartType part = BodyController.GetBodyPart(name); bod.applyCure(toolBox.selectedTool, part); break; case "Tool": ToolBox.Tool oldTool = toolBox.selectedTool; toolBox.selectTool(name); if (toolBox.selectedTool == oldTool) { //Debug.Log("Yes we just got the same thing."); return; } if (toolBox.selectedTool != ToolBox.Tool.None) { if (isToolSelected) { activeTool.transform.position = oldPoint; activeTool.GetComponent <Collider>().enabled = true; activeTool = null; } activeTool = GameObject.Find(name) as GameObject; activeTool.GetComponent <Collider>().enabled = false; oldPoint = activeTool.transform.position; sound.playToolPickupEffect(toolBox.selectedTool); isToolSelected = true; } else { if (isToolSelected) { isToolSelected = false; activeTool.transform.position = oldPoint; activeTool.GetComponent <Collider>().enabled = true; activeTool = null; } } break; case "Background": if (isToolSelected) { isToolSelected = false; activeTool.transform.position = oldPoint; activeTool.GetComponent <Collider>().enabled = true; activeTool = null; } toolBox.selectTool("None"); break; } // Communicate to owning script: }
// Eval a rule: given the current body state, the tool applied and to what body part, we apply our rules // Returns true if we did something right (even if the rule isn't resolved) and false on a mistake public static bool EvaluateCure(BodyPart[] bodyParts, ToolBox.Tool playersTool, BodyPartType playersTargetBodyPart, BodyPartColor bodyColor, ref int bodyHeartbeat, out bool fixesColor) { fixesColor = false; // Count number of each symptom we have int kSymptomCount = System.Enum.GetNames(typeof(Symptom)).Length; int[] symptomCount = new int[kSymptomCount]; // How many of each symptom do we have? for (int i = 1; i < kSymptomCount; i++) { symptomCount[i] = CountSymptom(bodyParts, (Symptom)i); } int lastGroupId = -1; bool groupDidFail = false; // For each rule, see which is applicable! foreach (Rule rule in rules) { bool ruleDoesApply = false; // What was the last rule's group and did it get applied but failed? If so, stop applying this group's rules.. if (lastGroupId != rule.GroupID) { groupDidFail = false; lastGroupId = rule.GroupID; } else if (groupDidFail) { continue; } // ExactCount: Checks if there is X number of Y symptoms on fixesBodyPartType. if (rule.ruleType == RuleType.ExactCount) { // Check count of this symptom, followed by if the symptom matches if (symptomCount [(int)rule.countSymptom] == rule.count && bodyParts [(int)rule.fixesBodyPartType].symptom == rule.countSymptom) { ruleDoesApply = true; } } // MinCount: Checks if there is 1 number of Y sumptom on fixesBodyPartType and at least X (inclusive) number overall. else if (rule.ruleType == RuleType.MinCount) { if (symptomCount [(int)rule.countSymptom] >= rule.count && bodyParts [(int)rule.fixesBodyPartType].symptom == rule.countSymptom) { ruleDoesApply = true; } } // ExactMatch: Rule is applied if the matching pattern (color, body part, symptom) i. else if (rule.ruleType == RuleType.ExactMatch) { // Does the target body part have this symptom? bool symptomMatches = (rule.exactSymptom == bodyParts [(int)rule.fixesBodyPartType].symptom); bool colorMatches = true; if (rule.exactColorIsSpecific && rule.exactColorNegate == false) { colorMatches = (rule.exactColor == bodyColor); } else if (rule.exactColorNegate) { colorMatches = (rule.exactColor != bodyColor); } if (symptomMatches && colorMatches) { ruleDoesApply = true; } } // ColorMatch: Check if there is a color match. Simple. else if (rule.ruleType == RuleType.ColorMatch) { ruleDoesApply = (bodyColor == rule.exactColor); } // Heartbeat: Check if heartbeat is below or above. else if (rule.ruleType == RuleType.Heartbeat) { if (rule.heartbeatGreater == true) { ruleDoesApply = (bodyHeartbeat > rule.heartbeatValue); } } // If rule applies... if (ruleDoesApply) { // Did it succeed? If so we're done! if (EvaluateRuleSolutions(rule, playersTool, playersTargetBodyPart)) { BodyPart fixedBodyPart = bodyParts [(int)rule.fixesBodyPartType]; fixedBodyPart.symptom = Symptom.None; fixesColor = (rule.fixesColor && rule.ruleSolutions.Count <= 0); // Color is fixed if all requirements met if (fixedBodyPart.BloodSpurt != null) { Object.Destroy(fixedBodyPart.BloodSpurt); fixedBodyPart.BloodSpurt = null; } if (fixedBodyPart.PainEffect != null) { Object.Destroy(fixedBodyPart.PainEffect); fixedBodyPart.PainEffect = null; } // Hack: if it's a heart rule that passes, we assume heartrate is fixed if (rule.ruleType == RuleType.Heartbeat) { bodyHeartbeat = BodyController.kTargetHeartbeat; } return(true); // No, so we can't apply any other rules in this group } else { groupDidFail = true; } } } // No success.. return(false); }
public RuleSolution(ToolBox.Tool t, BodyPartType b) { tool = t; isBodyPartSpecific = true; bodyPart = b; }
// Helper constructor public RuleSolution(ToolBox.Tool t) { tool = t; }
public void playToolPickupEffect(ToolBox.Tool tool) { //Debug.Log("Playing Sound effect for tool: " + tool); playEffect(toolPickup); }