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);
    }
Example #2
0
 protected static void DrawBodyPart(int shownBodyView, int i, Rect rect, BodyPartColor bodyPartColor)
 {
     if ((styles.BodyPart[shownBodyView, i] != null) && (styles.BodyPart[shownBodyView, i].image != null))
     {
         if ((bodyPartColor & BodyPartColor.Green) == BodyPartColor.Green)
         {
             GUI.color = Color.green;
         }
         else if ((bodyPartColor & BodyPartColor.Red) == BodyPartColor.Red)
         {
             GUI.color = Color.red;
         }
         else
         {
             GUI.color = Color.gray;
         }
         GUI.DrawTexture(rect, styles.BodyPart[shownBodyView, i].image);
         GUI.color = Color.white;
     }
 }
 protected static void DrawBodyPart(int shownBodyView, int i, Rect rect, BodyPartColor bodyPartColor)
 {
     if ((styles.BodyPart[shownBodyView, i] != null) && (styles.BodyPart[shownBodyView, i].image != null))
     {
         if ((bodyPartColor & BodyPartColor.Green) == BodyPartColor.Green)
         {
             GUI.color = Color.green;
         }
         else if ((bodyPartColor & BodyPartColor.Red) == BodyPartColor.Red)
         {
             GUI.color = Color.red;
         }
         else
         {
             GUI.color = Color.gray;
         }
         GUI.DrawTexture(rect, styles.BodyPart[shownBodyView, i].image);
         GUI.color = Color.white;
     }
 }
    // 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);
    }
    /*** Symptoms Setup ***/

    void SetupSymptoms()
    {
        //Re-set the pain level:
        painLevel = BodyPainLevel.Bad;
        // 50% chance that the heartbeat is abnormal
        if (Random.Range(0, 2) == 0)
        {
            heartbeat = kTargetHeartbeat;
        }
        else
        {
            heartbeat = Random.Range(85, 121);
        }

        // 50% chance of abnormal color
        int colorCount = System.Enum.GetNames(typeof(BodyPartColor)).Length;

        if (Random.Range(0, 2) == 0)
        {
            bodyColor = BodyPartColor.White;
        }
        else
        {
            bodyColor = (BodyPartColor)Random.Range(1, colorCount);
        }

        // Initialize body parts with no symptom
        int bodyPartCount = System.Enum.GetNames(typeof(BodyPartType)).Length;

        bodyParts = new BodyPart[bodyPartCount];
        for (int i = 0; i < bodyPartCount; i++)
        {
            bodyParts[i] = new BodyPart();
            bodyParts[i].bodyPartType = (BodyPartType)i;
            bodyParts[i].symptom      = Symptom.None;
        }

        // List rof symptoms we randomly shuffle: we will apply these
        int            kSymptomCount = System.Enum.GetNames(typeof(Symptom)).Length;
        List <Symptom> symptoms      = new List <Symptom>();

        for (int i = 0; i < kSymptomCount; i++)
        {
            symptoms.Add((Symptom)i);
        }
        symptoms.Sort((a, b) => 1 - 2 * Random.Range(0, 1));

        // Shitty performance / approach
        while (symptoms.Count > 0)
        {
            // Pick random body part. If it's not yet assigned, assign it now
            int bodyPartIndex = Random.Range(0, bodyPartCount);
            if (bodyParts[bodyPartIndex].symptom == Symptom.None)
            {
                // Assign a random and unique symptom
                bodyParts[bodyPartIndex].symptom = symptoms[0];
                symptoms.RemoveAt(0);
            }
        }

        // Print out for debugging
        foreach (BodyPart bodyPart in bodyParts)
        {
            // Debug.Log("Body part " + bodyPart.bodyPartType + " has symptom: " + bodyPart.symptom);
        }
    }