Example #1
0
    internal void Rules()
    {
        RandomFaultRule = Random.Range(0, 9);
        fault           = Random.Range(0, 2);
        //The faulty button cannot be the same color as the correct button
        //FaultRule 2 also states that the correct button has to be the one that matches the backing's color
        while (colFault.Equals(ColButton) || colFault.Equals(ColBacking))
        {
            colFault = Random.Range(0, 9);
        }

        //This determines which button is the faulty button, based on the rules.
        //While "fault" is always randomized, it doesn't necessarily mean the faulty button itself is always randomized.
        //This is why some values are fault, while others are actual integers, or the opposite of fault.
        var values = new[]
        {
            fault, fault, 0, 1, fault, (fault + 1) % 2, 0, 1, fault, 1, 0
        };

        //FaultRule 1 is excluded due to the OnInteract rule
        //FaultRule 2 is included as it overrides FaultRule 1
        if (RandomFaultRule != 0 || (ColButton == ColBacking))
        {
            //FaultRule 2 is determined by rather or not the button is the same color as the backing
            //This means it cannot be randomized based on the rule itself, at least not easily.
            if (ColButton == ColBacking)
            {
                RandomFaultRule = 1;
            }
            //Since FaultRule 2 is in the middle of the random function, increase the RandomFaultRule by 1 to match the manual
            //FaultRule 1 does not need to be increased
            else
            {
                RandomFaultRule++;
            }
            Module.ButtonA.OnInteract += delegate { Module.HandlePressButton(Module.ButtonA); return(false); };
            Module.ButtonB.OnInteract += delegate { Module.HandlePressButton(Module.ButtonB); return(false); };
        }
        else
        {
            //FaultRule 1 should be the only rule that reaches this else statement
            if (fault == 0)
            {
                Module.ButtonB.OnInteract += delegate() { Module.HandlePressButton(Module.ButtonB); return(false); }
            }
            ;
            else
            {
                Module.ButtonA.OnInteract += delegate() { Module.HandlePressButton(Module.ButtonA); return(false); }
            };
        }

        //Check each rule until something returns true
        //This is mostly used for FaultRule 9, 10 and 11, since they're not randomized
        while (!CheckRules())
        {
            RandomFaultRule++;
        }
        //Determine which button is faulty. 0 is left, 1 is right
        fault = values[RandomFaultRule];

        //Grab the correct button and text so that Backgrounds.cs can apply their correct colors
        Module.correctMesh     = FaultyMesh[(fault + 1) % 2];
        Module.correctTextMesh = FaultyTextMesh[(fault + 1) % 2];
        Module.DebugLog("Fake Button is on the {0}", fault.Equals(0) ? "left" : "right");
        FaultyMesh[fault].material.color = Backgrounds.color[colFault];

        Module.DebugLog("Fake Button was determined by rule {0}", RandomFaultRule + 1);
        Module.DebugLog("Backing is {0}, Button is {1}, Fake Button is {2}", Backgrounds.colorList[ColBacking], Backgrounds.colorList[ColButton], Backgrounds.colorList[colFault]);
        ReadableText(colFault, FaultyTextMesh[fault]);
    }