void handleSubmit()
    {
        Debug.LogFormat("[Homestuck Flashes #{0}] Checking submission, {1}.", _moduleId, songArray [stageSongArray [currentSSAIndex]]);
        Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Submit.transform);
        Submit.AddInteractionPunch();

        if (!_lightsOn || _isSolved)
        {
            return;
        }

        if (currentSSAIndex == 0)
        {
            Debug.LogFormat("[Homestuck Flashes #{0}] Stage is complete.", _moduleId);
            if (stageNum == totalStageNum)
            {
                _isSolved = true;
                Module.HandlePass();
                StageInd.text = "DEFUSED";
                Debug.LogFormat("[Homestuck Flashes #{0}] Module is defused.", _moduleId);
            }
            else
            {
                int newStageNum = stageNum + 1;
                StageInd.text = "STAGE " + newStageNum.ToString() + " OF " + totalStageNum.ToString();
                generateStage();
            }
            stageNum++;
        }
        else
        {
            Debug.LogFormat("[Homestuck Flashes #{0}] The inputted answer is incorrect.", _moduleId);
            Module.HandleStrike();
        }
    }
    private KMSelectable.OnInteractHandler btnDown(int multi, bool minutes)
    {
        return(delegate
        {
            if (_isSolved)
            {
                return false;
            }

            Submit.AddInteractionPunch();
            Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Submit.transform);

            if (_handHeld != null)
            {
                StopCoroutine(_handHeld);
            }
            _handHeld = StartCoroutine(moveHands(multi, minutes));
            return false;
        });
    }
    private void submit()
    {
        if (_isSolved)
        {
            return;
        }

        Submit.AddInteractionPunch();
        Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Submit.transform);

        var isFirstHalf = Bomb.GetTime() > _bombTime / 2;

        Debug.LogFormat("[The Clock #{0}] Pressed Submit {1} half of the bomb’s time has elapsed. Expecting {2}.", _moduleId, isFirstHalf ? "before" : "after", isFirstHalf ? "add" : "subtract");

        if (_shownTime == (_initialTime + (isFirstHalf ? _addTime : totalMinutes - _addTime)) % totalMinutes)
        {
            // Correct! :)
            Debug.LogFormat("[The Clock #{0}] Module solved.", _moduleId);
            Module.HandlePass();
            _isSolved = true;
            StartCoroutine(transitionSecondHand());
        }
        else
        {
            // Wrong, dude
            _initialTime = Rnd.Range(0, totalMinutes);
            Debug.LogFormat("[The Clock #{0}] {1} submitted. Strike. New initial time: {2}", _moduleId, formatTime(_shownTime), formatTime(_initialTime));
            LogAnswer();
            _shownTime = _initialTime;
            Module.HandleStrike();
        }

        if (_handHeld != null)
        {
            StopCoroutine(_handHeld);
        }
        _handHeld = StartCoroutine(moveHands(0, false, secondsOnly: _isSolved));
    }
    void Start()
    {
        _moduleId = _moduleIdCounter++;
        _solved   = false;

        // Rule seed
        var rnd = RuleSeedable.GetRNG();

        Debug.LogFormat("[101 Dalmatians #{0}] Using rule seed: {1}", _moduleId, rnd.Seed);

        var skip = rnd.Next(0, 100);

        for (var i = 0; i < skip; i++)
        {
            rnd.NextDouble();
        }
        rnd.ShuffleFisherYates(Furspots);

        // Decide which fur pattern to show on the module and in what rotation.
        _solution = Rnd.Range(0, 101);
        Fur.material.mainTexture = Furspots[_solution];
        var moduleRotation = Rnd.Range(0, 360f);

        Fur.transform.localEulerAngles = new Vector3(0, moduleRotation, 0);
        _curDalmatianIndex             = Rnd.Range(0, 101);
        UpdateName();

        Debug.LogFormat(@"<101 Dalmatians #{0}> Name initially shown: {1}", _moduleId, _dalmatians[_curDalmatianIndex]);
        Debug.LogFormat(@"[101 Dalmatians #{0}] Solution: {1}", _moduleId, _dalmatians[_solution]);
        Debug.LogFormat(@"[101 Dalmatians #{0}] Showing fur pattern {1} rotated {2}° clockwise", _moduleId, Furspots[_solution].name.Substring(3), Math.Round(moduleRotation));

        LeftArrow.OnInteract  = delegate { _curDalmatianIndex = (_curDalmatianIndex + 100) % 101; UpdateName(); startLongPress(100); return(false); };
        RightArrow.OnInteract = delegate { _curDalmatianIndex = (_curDalmatianIndex + 1) % 101; UpdateName(); startLongPress(1); return(false); };

        LeftArrow.OnInteractEnded = RightArrow.OnInteractEnded = delegate
        {
            if (_longPress != null)
            {
                StopCoroutine(_longPress);
            }
        };

        Submit.OnInteract = delegate
        {
            Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, transform);
            Submit.AddInteractionPunch();

            if (_solved)
            {
                return(false);
            }
            if (_curDalmatianIndex == _solution)
            {
                Debug.LogFormat(@"[101 Dalmatians #{0}] You submitted {1}. Correct.", _moduleId, _dalmatians[_curDalmatianIndex]);
                Module.HandlePass();
                Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.CorrectChime, transform);
                LeftArrow.gameObject.SetActive(false);
                RightArrow.gameObject.SetActive(false);
                StartCoroutine(solveAnimationPart1());
                StartCoroutine(solveAnimationPart2());
                _solved = true;
            }
            else
            {
                Debug.LogFormat(@"[101 Dalmatians #{0}] You submitted {1}. Strike.", _moduleId, _dalmatians[_curDalmatianIndex]);
                Module.HandleStrike();
            }
            return(false);
        };
    }
    private void SubmitHandler()
    {
        Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Submit.transform);
        Submit.AddInteractionPunch();
        if (Barempty)
        {
            Barempty = false;
            BarControl.gameObject.transform.localScale = new Vector3(1, 1, 1);
            Debug.LogFormat("[Waste Management #{0}] Strike avoided, continue with next stage", _moduleId);
            return;
        }

        if (!_lightsOn || _isSolved)
        {
            return;
        }

        if (!Calculated && !ForcedSolve)
        {
            //once submit button is pressed for the first time, those rules will be in effect for the rest of the bomb, unless you get a strike on this module
            CurrentTime = Mathf.FloorToInt(Info.GetTime());
            Debug.LogFormat("[Waste Management #{0}] Submit button pressed, performing final adjustments", _moduleId);
            TimeAdjustments();
        }
        switch (Stage)
        {
        case 1:
        {
            if (!ForcedSolve)
            {
                CalculateProportions();
            }
            Debug.LogFormat("[Waste Management #{0}] Received {1} for paper recycling, expected {2}", _moduleId, PaperRecycle, PaperRecycleAns);
            Debug.LogFormat("[Waste Management #{0}] Received {1} for paper waste, expected {2}", _moduleId, PaperWaste, PaperWasteAns);
            if (PaperRecycle == PaperRecycleAns && PaperWaste == PaperWasteAns)
            {
                Debug.LogFormat("[Waste Management #{0}] Paper correct!", _moduleId);
                Audio.PlaySoundAtTransform("PaperSubmit", Submit.transform);
                Stage++;
                Input           = 0;
                Screen.text     = "Plastic";
                Screen.fontSize = 70;
            }
            else
            {
                Debug.LogFormat("[Waste Management #{0}] Paper incorrect, Strike.", _moduleId);
                Module.HandleStrike();
                Strike = true;
                Init();
            }

            break;
        }

        case 2:
        {
            Debug.LogFormat("[Waste Management #{0}] Received {1} for plastic recycling, expected {2}", _moduleId, PlasticRecycle, PlasticRecycleAns);
            Debug.LogFormat("[Waste Management #{0}] Received {1} for plastic waste, expected {2}", _moduleId, PlasticWaste, PlasticWasteAns);
            if (PlasticRecycle == PlasticRecycleAns && PlasticWaste == PlasticWasteAns)
            {
                Debug.LogFormat("[Waste Management #{0}] Plastic correct!", _moduleId);
                Audio.PlaySoundAtTransform("PlasticSubmit", Submit.transform);
                Stage++;
                Input           = 0;
                Screen.text     = "Metal";
                Screen.fontSize = 75;
            }
            else
            {
                Debug.LogFormat("[Waste Management #{0}] Plastic incorrect, Strike.", _moduleId);
                Module.HandleStrike();
                Strike = true;
                Init();
            }

            break;
        }

        case 3:
        {
            Debug.LogFormat("[Waste Management #{0}] Received {1} for metal recycling, expected {2}", _moduleId, MetalRecycle, MetalRecycleAns);
            Debug.LogFormat("[Waste Management #{0}] Received {1} for metal waste, expected {2}", _moduleId, MetalWaste, MetalWasteAns);
            if (MetalRecycle == MetalRecycleAns && MetalWaste == MetalWasteAns)
            {
                if (LeftoverRecycleAns > 0 || LeftoverWasteAns > 0)
                {
                    Debug.LogFormat("[Waste Management #{0}] Metal correct!", _moduleId);
                    Audio.PlaySoundAtTransform("MetalSubmit", Submit.transform);
                    Stage++;
                    Input           = 0;
                    Screen.text     = "Leftovers";
                    Screen.fontSize = 50;
                }
                else
                {
                    Debug.LogFormat("[Waste Management #{0}] Metal correct!", _moduleId);
                    Debug.LogFormat("[Waste Management #{0}] There are no leftovers", _moduleId);
                    Debug.LogFormat("[Waste Management #{0}] Module Passed.", _moduleId);
                    _isSolved = true;                             //module is solved
                    Module.HandlePass();
                    Audio.PlaySoundAtTransform("WasteManagementSolve", Submit.transform);
                    Input           = 0;
                    Screen.text     = "";
                    Screen.fontSize = 75;
                }
            }
            else
            {
                Debug.LogFormat("[Waste Management #{0}] Metal incorrect, Strike.", _moduleId);
                Strike = true;
                Module.HandleStrike();
                Init();
            }

            break;
        }

        default:
        {
            Debug.LogFormat("[Waste Management #{0}] Received {1} for leftover recycling, expected {2}", _moduleId, LeftoverRecycle, LeftoverRecycleAns);
            Debug.LogFormat("[Waste Management #{0}] Received {1} for leftover waste, expected {2}", _moduleId, LeftoverWaste, LeftoverWasteAns);
            if (LeftoverRecycle == LeftoverRecycleAns && LeftoverWaste == LeftoverWasteAns)
            {
                Debug.LogFormat("[Waste Management #{0}] Leftovers correct!", _moduleId);
                Debug.LogFormat("[Waste Management #{0}] Module Passed.", _moduleId);
                _isSolved = true;                         //module is solved
                Module.HandlePass();
                Audio.PlaySoundAtTransform("WasteManagementSolve", Submit.transform);
                Input           = 0;
                Screen.text     = string.Empty;
                Screen.fontSize = 75;
            }
            else
            {
                Debug.LogFormat("[Waste Management #{0}] Leftovers incorrect, Strike.", _moduleId);
                Strike = true;
                Module.HandleStrike();
                Init();
            }

            break;
        }
        }

        if (Stage < 1 || Stage >= 4)
        {
            return;
        }
        int random = UnityEngine.Random.Range(1, 21);         //5% chance of bar going blank

        if (random != 1)
        {
            return;
        }
        Barempty = true;
        BarControl.gameObject.transform.localScale = new Vector3(1, 1, 0);
        Debug.LogFormat("[Waste Management #{0}] Bar empty, submit expected or strike", _moduleId);
    }
Example #6
0
    private void Initialization()
    {
        _clues = new List <Clue>();

        // Add the size indication
        var sizeSystem = Rnd.Range(0, 5);
        var primes     = new[] { 3, 5, 7 };
        var size       = Enumerable.Range(3, 5).SelectMany(width => Enumerable.Range(3, 5).Select(height => new { Width = width, Height = height }))
                         .Where(sz => sizeSystem != 0 || (primes.Contains(sz.Width) && primes.Contains(sz.Height)))
                         .PickRandom();
        Clue clue = null;

        switch (sizeSystem)
        {
        case 0: clue = new Clue((size.Width > size.Height ? "{0}" : size.Width < size.Height ? "({0})" : Rnd.Range(0, 2) == 0 ? "{0}" : "({0})").Fmt(size.Width * size.Height), false, false, 128); break;

        case 1: clue = new Clue("{0}×{1}".Fmt(size.Width, size.Height), false, false, 128, null, "{0}x{1}".Fmt(size.Width, size.Height)); break;

        case 2: clue = new Clue("{1} by {0}".Fmt(size.Width, size.Height), false, false, 128); break;

        case 3: clue = new Clue("{0}*{1}".Fmt(size.Width * size.Height, size.Height), false, false, 128); break;

        case 4: clue = new Clue("{0} : {1}".Fmt(size.Width * size.Height, size.Width), false, false, 128); break;
        }
        _clues.Add(clue);
        Debug.LogFormat(@"[Coordinates #{3}] Showing grid size {0}×{1} as {2}", size.Width, size.Height, clue.LoggingText, _moduleId);

        var coordCh = 'a';
        var grid    = new char[size.Width * size.Height];

        for (int i = 0; i < size.Width * size.Height; i++)
        {
            grid[i] = '.';
        }

        var coordinates = Enumerable.Range(0, size.Width * size.Height).ToList();

        coordinates.Shuffle();
        var illegalCoords = new List <int>();
        var num           = 0;

        // Generate 6 illegal coordinates
        for (; num < 6; num++)
        {
            illegalCoords.Add(coordinates[num]);
            clue = addClue(false, coordinates[num], size.Width, size.Height);
            Debug.LogFormat(@"[Coordinates #{3}] Showing illegal coordinate {0}={1} as {2}", coordCh, loggingCoords(coordinates[num], size.Width), clue.LoggingText, _moduleId);
            grid[coordinates[num]] = coordCh;
            coordCh++;
        }

        // Generate the correct coordinate twice with different coordinate systems
        clue = addClue(true, coordinates[num], size.Width, size.Height);
        Debug.LogFormat(@"[Coordinates #{0}] Showing correct coordinate *={1} as {2}", _moduleId, loggingCoords(coordinates[num], size.Width), clue.LoggingText);
        clue = addClue(true, coordinates[num], size.Width, size.Height, avoidSystem: clue.System);
        Debug.LogFormat(@"[Coordinates #{0}] Showing correct coordinate *={1} as {2}", _moduleId, loggingCoords(coordinates[num], size.Width), clue.LoggingText);
        grid[coordinates[num]] = '*';

        // Log the grid
        Debug.LogFormat("[Coordinates #{0}] Grid:\n{1}", _moduleId, Enumerable.Range(0, size.Height).Select(row =>
                                                                                                            (grid[size.Width * row] == '*' ? "" : " ") +
                                                                                                            Enumerable.Range(0, size.Width)
                                                                                                            .Select(col => new { Char = grid[col + size.Width * row], Col = col, Coord = col + size.Width * row })
                                                                                                            .Select(inf => inf.Char == '*' ? "[*]" : (inf.Char != '.' ? inf.Char : illegalCoords.Contains(inf.Coord) ? '#' : '.') + (inf.Col == size.Width - 1 || grid[inf.Col + 1 + size.Width * row] == '*' ? "" : " "))
                                                                                                            .JoinString())
                        .JoinString("\n"));

        _clues.Shuffle();

        _selectedIndex         = 0;
        _firstCorrectSubmitted = null;

        Left.OnInteract = delegate
        {
            Left.AddInteractionPunch(.5f);
            Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Left.transform);
            StartCoroutine(ButtonAnimation(Left));
            if (_clues == null)
            {
                return(false);
            }

            _selectedIndex = (_selectedIndex + _clues.Count - 1) % _clues.Count;
            UpdateDisplay(false);
            return(false);
        };

        Right.OnInteract = delegate
        {
            Right.AddInteractionPunch(.5f);
            Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Right.transform);
            StartCoroutine(ButtonAnimation(Right));
            if (_clues == null)
            {
                return(false);
            }

            _selectedIndex = (_selectedIndex + 1) % _clues.Count;
            UpdateDisplay(true);
            return(false);
        };

        Submit.OnInteract = delegate
        {
            Submit.AddInteractionPunch(1f);
            Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, Submit.transform);
            StartCoroutine(ButtonAnimation(Submit));
            if (_clues == null)
            {
                return(false);
            }

            if (_clues[_selectedIndex].IsCorrect && (_firstCorrectSubmitted == null || _firstCorrectSubmitted == _selectedIndex))
            {
                Debug.LogFormat("[Coordinates #{0}] Pressed submit button on {1}: first correct answer.", _moduleId, _clues[_selectedIndex].LoggingText);
                _firstCorrectSubmitted = _selectedIndex;
            }
            else if (_clues[_selectedIndex].IsCorrect)
            {
                Debug.LogFormat("[Coordinates #{0}] Pressed submit button on {1}: second correct answer. Module solved.", _moduleId, _clues[_selectedIndex].LoggingText);
                Module.HandlePass();
                _clues = null;
            }
            else
            {
                Debug.LogFormat("[Coordinates #{0}] Pressed submit button on wrong answer {1}.", _moduleId, _clues[_selectedIndex].LoggingText);
                Module.HandleStrike();
            }

            return(false);
        };

        UpdateDisplay(true);
    }