/// <summary>
    /// Launch the GameOver screen
    /// </summary>
    [CYFEventFunction] public void GameOver(DynValue deathText = null, string deathMusic = null)
    {
        PlayerCharacter.instance.HP = PlayerCharacter.instance.MaxHP;
        Transform rt = GameObject.Find("Player").GetComponent <Transform>();

        rt.position = new Vector3(rt.position.x, rt.position.y, -1000);
        string[] deathTable = null;

        if (deathText != null)
        {
            if (deathText.Type == DataType.Table)
            {
                deathTable = new string[deathText.Table.Length];
                for (int i = 0; i < deathText.Table.Length; i++)
                {
                    deathTable[i] = deathText.Table[i + 1].ToString();
                }
            }
            else if (deathText.Type == DataType.String)
            {
                deathTable = new string[] { deathText.String }
            }
            ;
            else
            {
                throw new CYFException("General.GameOver: deathText needs to be a table or a string.");
            }
        }

        GlobalControls.Music             = UnitaleUtil.GetCurrentOverworldAudio().clip;
        PlayerOverworld.instance.enabled = false;

        GameObject.FindObjectOfType <GameOverBehavior>().StartDeath(deathTable, deathMusic);
        appliedScript.Call("CYFEventNextCommand");
    }
Exemple #2
0
    /// <summary>
    /// Launch the GameOver screen
    /// </summary>
    [CYFEventFunction] public void GameOver(DynValue deathText = null, string deathMusic = null)
    {
        PlayerCharacter.instance.HP = PlayerCharacter.instance.MaxHP;
        Transform rt = GameObject.Find("Player").GetComponent <Transform>();

        rt.position = new Vector3(rt.position.x, rt.position.y, -1000);
        string[] deathTable = null;

        if (deathText != null)
        {
            deathTable = new string[deathText.Table.Length];
            for (int i = 0; i < deathText.Table.Length; i++)
            {
                deathTable[i] = deathText.Table[i + 1].ToString();
            }
        }

        GlobalControls.Music             = UnitaleUtil.GetCurrentOverworldAudio().clip;
        PlayerOverworld.instance.enabled = false;

        UnitaleUtil.WriteInLogAndDebugger(GameObject.FindObjectOfType <GameOverBehavior>().name);

        GameObject.FindObjectOfType <GameOverBehavior>().StartDeath(deathTable, deathMusic);
        appliedScript.Call("CYFEventNextCommand");
    }
Exemple #3
0
    /// <summary>
    /// Launch the GameOver screen
    /// </summary>
    [CYFEventFunction] public void GameOver(DynValue deathText = null, string deathMusic = null)
    {
        PlayerCharacter.instance.HP = PlayerCharacter.instance.MaxHP;

        /*Transform rt = GameObject.Find("Player").GetComponent<Transform>();
         * rt.position = new Vector3(rt.position.x, rt.position.y, -1000);*/
        string[] deathTable = null;

        if (deathText != null && deathText.Type != DataType.Void)
        {
            switch (deathText.Type)
            {
            case DataType.Table: {
                deathTable = new string[deathText.Table.Length];
                for (int i = 0; i < deathText.Table.Length; i++)
                {
                    deathTable[i] = deathText.Table[i + 1].ToString();
                }
                break;
            }

            case DataType.String: deathTable = new[] { deathText.String }; break;

            default:              throw new CYFException("General.GameOver: deathText needs to be a table or a string.");
            }
        }

        PlayerOverworld.instance.enabled = false;

        // Stop the "kept audio" if it is playing
        if (PlayerOverworld.audioKept == UnitaleUtil.GetCurrentOverworldAudio())
        {
            PlayerOverworld.audioKept.Stop();
            PlayerOverworld.audioKept.clip = null;
            PlayerOverworld.audioKept.time = 0;
        }

        //Saves our most recent map and position to control where the player respawns
        string mapName = UnitaleUtil.MapCorrespondanceList.ContainsKey(SceneManager.GetActiveScene().name) ? UnitaleUtil.MapCorrespondanceList[SceneManager.GetActiveScene().name] : SceneManager.GetActiveScene().name;

        LuaScriptBinder.Set(null, "PlayerMap", DynValue.NewString(mapName));

        Transform tf = GameObject.Find("Player").transform;

        LuaScriptBinder.Set(null, "PlayerPosX", DynValue.NewNumber(tf.position.x));
        LuaScriptBinder.Set(null, "PlayerPosY", DynValue.NewNumber(tf.position.y));
        LuaScriptBinder.Set(null, "PlayerPosZ", DynValue.NewNumber(tf.position.z));

        Object.FindObjectOfType <GameOverBehavior>().StartDeath(deathTable, deathMusic);

        appliedScript.Call("CYFEventNextCommand");
    }
    /// <summary>
    /// Plays and adjust the volume of a chosen bgm.
    /// </summary>
    /// <param name="bgm">The name of the chosen BGM to play.</param>
    /// <param name="volume">The volume of the BGM. Clamped from 0 to 1.</param>
    [CYFEventFunction] public void PlayBGM(string bgm, float volume)
    {
        volume = Mathf.Clamp01(volume);
        if (AudioClipRegistry.GetMusic(bgm) == null)
        {
            throw new CYFException("General.PlayBGM: The given BGM doesn't exist. Please check if you've spelled it correctly.");
        }
        AudioSource audio = UnitaleUtil.GetCurrentOverworldAudio();

        audio.clip   = AudioClipRegistry.GetMusic(bgm);
        audio.volume = volume;
        audio.Play();
        appliedScript.Call("CYFEventNextCommand");
    }
    public static IEnumerator GetIntoDaMap(string call, object[] neededArgs)
    {
        if (GameObject.Find("Main Camera OW"))
        {
            GameObject.Find("Main Camera OW").GetComponent <EventManager>().readyToReLaunch = true;
            GameObject.Find("Main Camera OW").tag = "MainCamera";
        }

        //Clear any leftover Sprite and Text objects that are no longer connected to any scripts
        foreach (Transform child in GameObject.Find("Canvas Two").transform)
        {
            if (!child.name.EndsWith("Layer"))
            {
                GameObject.Destroy(child.gameObject);
            }
            else
            {
                foreach (Transform child2 in child)
                {
                    GameObject.Destroy(child2.gameObject);
                }
            }
        }

        yield return(0);

        Camera.main.transparencySortMode = TransparencySortMode.CustomAxis;
        Camera.main.transparencySortAxis = new Vector3(0.0f, 1.0f, 1000000.0f);

        try { PlayerOverworld.instance.backgroundSize = GameObject.Find("Background").GetComponent <RectTransform>().sizeDelta *GameObject.Find("Background").GetComponent <RectTransform>().localScale.x; }
        catch { UnitaleUtil.WriteInLogAndDebugger("RectifyCameraPosition: The 'Background' GameObject is missing."); }

        EventManager.instance.onceReload = false;
        //Permits to reload the current data if needed
        MapInfos mi = GameObject.Find("Background").GetComponent <MapInfos>();

        if (StaticInits.MODFOLDER != mi.modToLoad)
        {
            StaticInits.MODFOLDER   = mi.modToLoad;
            StaticInits.Initialized = false;
            StaticInits.InitAll();
            LuaScriptBinder.Set(null, "ModFolder", DynValue.NewString(StaticInits.MODFOLDER));
            if (call == "transitionoverworld")
            {
                EventManager.instance.ScriptLaunched = false;
                EventManager.instance.script         = null;
            }
        }

        AudioSource audio = UnitaleUtil.GetCurrentOverworldAudio();

        if (mi.isMusicKeptBetweenBattles)
        {
            Camera.main.GetComponent <AudioSource>().Stop();
            Camera.main.GetComponent <AudioSource>().clip = null;
        }
        else
        {
            PlayerOverworld.audioKept.Stop();
            PlayerOverworld.audioKept.clip = null;
        }

        //Starts the music if there's no music
        if (audio.clip == null)
        {
            if (mi.music != "none")
            {
                audio.clip = AudioClipRegistry.GetMusic(mi.music);
                audio.time = 0;
                audio.Play();
            }
            else
            {
                audio.Stop();
            }
        }
        else
        {
            //Get the file's name with this...thing?
            string test = audio.clip.name.Replace('\\', '/').Split(new string[] { "/Audio/" }, System.StringSplitOptions.RemoveEmptyEntries)[1].Split('.')[0];
            if (test != mi.music)
            {
                if (mi.music != "none")
                {
                    audio.clip = AudioClipRegistry.GetMusic(mi.music);
                    audio.time = 0;
                    audio.Play();
                }
                else
                {
                    audio.Stop();
                }
            }
        }

        GameObject.Find("utHeart").GetComponent <Image>().color = new Color(GameObject.Find("utHeart").GetComponent <Image>().color.r,
                                                                            GameObject.Find("utHeart").GetComponent <Image>().color.g,
                                                                            GameObject.Find("utHeart").GetComponent <Image>().color.b, 0);
        PlayerOverworld.instance.cameraShift = Vector2.zero;
        if (call == "tphandler")
        {
            GameObject.Find("Player").transform.parent.position = (Vector2)neededArgs[0];
            PlayerOverworld.instance.gameObject.GetComponent <CYFAnimator>().movementDirection = ((TPHandler)neededArgs[1]).direction;
            ((TPHandler)neededArgs[1]).activated = false;
            GameObject.Destroy(((TPHandler)neededArgs[1]).gameObject);
        }

        if (GameObject.Find("Don't show it again"))
        {
            GameObject.Destroy(GameObject.Find("Don't show it again"));
        }
        StaticInits.SendLoaded();
    }