Exemple #1
0
    // Use this for initialization
    void Start()
    {
        float scalar = transform.lossyScale.x;// Account for scale factor for this module being smaller, check KTANE official discord in #modding

        foreach (Light onelight in lights)
        {
            onelight.range *= scalar;
        }
        animLight.range *= scalar;
        TileAnim.SetActive(false);
        Generate4x4Puzzle();
        for (int selidx = 0; selidx < tileSelectables.Length; selidx++)
        {
            int y = selidx;
            tileSelectables[selidx].OnInteract += delegate
            {
                tileSelectables[y].AddInteractionPunch();
                kMAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonRelease, transform);
                if (!solved)
                {
                    inputsOverall.Add(y);
                }
                return(false);
            };
        }
        bombInfo.OnBombExploded += delegate
        {
            if (solved || isGenerating)
            {
                return;
            }

            string debugMoves = "";
            foreach (int inIdx in inputsOverall)
            {
                debugMoves += debugCoordCol[inIdx % 4] + debugCoordRow[inIdx / 4 % 4] + " ";
            }
            debugMoves.Trim();
            Debug.LogFormat("[15 Mystic Lights #{0}]: The following moves used on the given board when the bomb blew were {1}", curmodid, debugMoves);
        };

        moduleSelf.OnActivate += delegate {
            if (TwitchPlaysActive)
            {
                StatusLight.SetActive(true);
            }
            else
            {
                StatusLight.SetActive(false);
            }
        };
        //StatusLight.SetActive(false);
    }
    IEnumerator PlaySolveAnim(int ycor, int xcor)
    {
        playingAnim = true;
        kMAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.WireSequenceMechanism, transform);
        Vector3 pointTL = AnimPointTL.transform.localPosition;
        Vector3 pointBR = AnimPointBR.transform.localPosition;
        Vector3 pointD  = AnimPointD.transform.localPosition;
        //Vector3 LastStatLightScale = new Vector3(StatusLight.transform.localScale.x, StatusLight.transform.localScale.y, StatusLight.transform.localScale.z);
        bool lgtSteSgl = (bool)GetFirstNonNullTileState();

        for (int idx = 0; idx < textMeshes.Length; idx++)
        {
            textMeshes[idx].gameObject.SetActive(false);
        }
        float localX = pointBR.x * xcor / 3f + pointTL.x * (3 - xcor) / 3f;
        float localY = pointBR.y * ycor / 3f + pointTL.y * (3 - ycor) / 3f;

        for (float x = 1; x >= 0; x -= Time.deltaTime)
        {
            float localZ = pointD.z * x;
            TileAnim.SetActive(true);
            StatusLight.SetActive(true);
            TileAnim.transform.localPosition    = new Vector3(localX, localY, localZ);
            StatusLight.transform.localPosition = new Vector3(localX, localY, localZ + .005f);

            AnimRenderer.material = lgtSteSgl ? materials[0] : materials[1];
            animLight.color       = lgtSteSgl ? Color.yellow : Color.blue;
            animLight.enabled     = true;
            yield return(null);
        }
        StatusLight.transform.localPosition = new Vector3(localX, localY, .005f);
        TileAnim.SetActive(false);
        int tileIndex = xcor + 4 * ycor;

        tiles[tileIndex].SetActive(true);
        meshRenderers[tileIndex].material = lgtSteSgl ? materials[0] : materials[1];
        lights[tileIndex].enabled         = true;
        lights[tileIndex].color           = lgtSteSgl ? Color.yellow : Color.blue;
        moduleSelf.HandlePass();
        yield return(null);
    }
    IEnumerator PlaySlidingAnim(int direction)
    {
        playingAnim = true;
        TileAnim.SetActive(true);
        int[] emptyTile = GetFirstNullTile();
        int   xIdx      = emptyTile[0];
        int   yIdx      = emptyTile[1];

        if (xIdx < lightStates.GetLength(0) && xIdx >= 0 && yIdx < lightStates.GetLength(1) && yIdx >= 0 && direction >= 0 && direction < 4)
        {
            if (!instantMysticLights)
            {
                float[] coordStart = new float[2] {
                    0, 0
                };
                float[] coordEnd = new float[2] {
                    0, 0
                };
                Vector3 pointTL = AnimPointTL.transform.localPosition;
                Vector3 pointBR = AnimPointBR.transform.localPosition;
                // The idea for this is to grab the specified point by using local coordinates to manipulate the position.
                for (int p = 0; p < 3; p++)
                {
                    // Grab end points of the animation
                    if (xIdx > p)
                    {
                        coordEnd[0] += pointBR.x;
                    }
                    else
                    {
                        coordEnd[0] += pointTL.x;
                    }
                    if (yIdx > p)
                    {
                        coordEnd[1] += pointBR.y;
                    }
                    else
                    {
                        coordEnd[1] += pointTL.y;
                    }
                    // Grab start points of the animation
                    if (direction % 2 == 0)     // If the direction involves the x-axis
                    {
                        if (direction / 2 <= 0) // If the direction is negative
                        {
                            if (p < xIdx - 1)
                            {
                                coordStart[0] += pointBR.x;
                            }
                            else
                            {
                                coordStart[0] += pointTL.x;
                            }
                        }
                        else// If the direction is positive
                        {
                            if (p < xIdx + 1)
                            {
                                coordStart[0] += pointBR.x;
                            }
                            else
                            {
                                coordStart[0] += pointTL.x;
                            }
                        }
                        if (p < yIdx)
                        {
                            coordStart[1] += pointBR.y;
                        }
                        else
                        {
                            coordStart[1] += pointTL.y;
                        }
                    }
                    else// if the direction involves the y-axis
                    {
                        if (direction / 2 > 0)// If the direction is negative
                        {
                            if (p < yIdx + 1)
                            {
                                coordStart[1] += pointBR.y;
                            }
                            else
                            {
                                coordStart[1] += pointTL.y;
                            }
                        }
                        else// If the direction is positive
                        {
                            if (p < yIdx - 1)
                            {
                                coordStart[1] += pointBR.y;
                            }
                            else
                            {
                                coordStart[1] += pointTL.y;
                            }
                        }
                        if (p < xIdx)
                        {
                            coordStart[0] += pointBR.x;
                        }
                        else
                        {
                            coordStart[0] += pointTL.x;
                        }
                    }
                }
                coordEnd[0]   /= 3f;
                coordEnd[1]   /= 3f;
                coordStart[0] /= 3f;
                coordStart[1] /= 3f;
                int xIntIdx = direction == 0 ? xIdx - 1 : direction == 2 ? xIdx + 1 : xIdx; // X coordinate of where the module was interacted
                int yIntIdx = direction == 1 ? yIdx - 1 : direction == 3 ? yIdx + 1 : yIdx; // Y coordinate of where the module was interacted
                                                                                            //print("Suggest last interaction was at (" + xIntIdx + "," + yIntIdx + ")");
                                                                                            // Update the light around the tile that was moved.
                if (yIdx + 1 < 4 && direction != 3)
                {
                    UpdateSpecificLight(xIdx, yIdx + 1);
                }
                if (yIdx - 1 >= 0 && direction != 1)
                {
                    UpdateSpecificLight(xIdx, yIdx - 1);
                }
                if (xIdx + 1 < 4 && direction != 2)
                {
                    UpdateSpecificLight(xIdx + 1, yIdx);
                }
                if (xIdx - 1 >= 0 && direction != 0)
                {
                    UpdateSpecificLight(xIdx - 1, yIdx);
                }
                for (float i = 0; i < 1f; i += Time.deltaTime * 4)
                {
                    float finalposX = coordStart[0] * i + coordEnd[0] * (1f - i);
                    float finalposY = coordStart[1] * i + coordEnd[1] * (1f - i);

                    /*
                     * for (int x = 0; x < animDelay/2; x++)
                     * {
                     *  if (x < i)
                     *  {
                     *      finalposX += coordStart[0];
                     *      finalposY += coordStart[1];
                     *  }
                     *  else
                     *  {
                     *      finalposX += coordEnd[0];
                     *      finalposY += coordEnd[1];
                     *  }
                     *
                     * }
                     * finalposX /= animDelay/2;
                     * finalposY /= animDelay/2;
                     */
                    TileAnim.transform.localPosition = new Vector3(finalposY, finalposX, 0.0f);
                    bool lgtSteSgl = (bool)lightStates[xIntIdx, yIntIdx];
                    AnimRenderer.material = lgtSteSgl ? materials[0] : materials[1];
                    animLight.color       = lgtSteSgl ? Color.yellow : Color.blue;
                    animLight.enabled     = true;
                    UpdateSpecificLight(xIdx, yIdx);
                    yield return(null);
                }
            }
            kMAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, transform);
        }
        TileAnim.SetActive(false);
        animLight.enabled = false;

        UpdateAllLights();
        if (isAllCorrect())
        {
            Debug.LogFormat("[15 Mystic Lights #{0}]: All the lights are in 1 color.", curmodid);
            if (hasExitedInitial)
            {
                int[] firstEmpty = GetFirstNullTile();
                StartCoroutine(PlaySolveAnim(firstEmpty[0], firstEmpty[1]));
                solved = true;
            }
            else
            {
                StartCoroutine(PlayTransitionAnim());
                hasExitedInitial = true;
            }
        }
        playingAnim = false;
        yield return(null);
    }
Exemple #4
0
    IEnumerator PlaySolveAnim(int ycor, int xcor)
    {
        playingAnim = true;
        kMAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.WireSequenceMechanism, transform);
        Vector3 pointTL = AnimPointTL.transform.localPosition;
        Vector3 pointBR = AnimPointBR.transform.localPosition;
        Vector3 pointD  = AnimPointD.transform.localPosition;
        //Vector3 LastStatLightScale = new Vector3(StatusLight.transform.localScale.x, StatusLight.transform.localScale.y, StatusLight.transform.localScale.z);
        bool lgtSteSgl = (bool)GetFirstNonNullTileState();

        for (int idx = 0; idx < textMeshes.Length; idx++)
        {
            textMeshes[idx].gameObject.SetActive(false);
        }
        for (int x = animDelay * 2; x >= 0; x--)
        {
            float localX = 0;
            float localY = 0;
            float localZ = 0;
            for (int p = 0; p < 3; p++)
            {
                // Grab end points of the animation
                if (xcor > p)
                {
                    localX += pointBR.x;
                }
                else
                {
                    localX += pointTL.x;
                }
                if (ycor > p)
                {
                    localY += pointBR.y;
                }
                else
                {
                    localY += pointTL.y;
                }
            }
            for (int y = 0; y < x; y++)
            {
                localZ += pointD.z;
            }
            localZ /= animDelay * 2;
            localX /= 3;
            localY /= 3;
            TileAnim.SetActive(true);
            StatusLight.SetActive(true);
            TileAnim.transform.localPosition    = new Vector3(localX, localY, localZ);
            StatusLight.transform.localPosition = new Vector3(localX, localY, localZ + .005f);

            AnimRenderer.material = lgtSteSgl ? materials[0] : materials[1];
            animLight.color       = lgtSteSgl ? Color.yellow : Color.blue;
            animLight.enabled     = true;
            yield return(new WaitForSeconds(0));
        }
        TileAnim.SetActive(false);
        int tileIndex = xcor + 4 * ycor;

        tiles[tileIndex].SetActive(true);
        meshRenderers[tileIndex].material = lgtSteSgl ? materials[0] : materials[1];
        lights[tileIndex].enabled         = true;
        lights[tileIndex].color           = lgtSteSgl ? Color.yellow : Color.blue;
        moduleSelf.HandlePass();
        yield return(null);
    }