Esempio n. 1
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");
    }
Esempio n. 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)
        {
            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");
    }
Esempio n. 3
0
    private void inUpdateControlCommand(string command)
    {
        string[] cmds = command.Split(':');
        string[] args = new string[0];
        if (cmds.Length == 2)
        {
            args    = cmds[1].Split(',');
            cmds[1] = args[0];
        }
        switch (cmds[0].ToLower())
        {
        case "w":
            letterTimer = timePerLetter - (singleFrameTiming * ParseUtil.getInt(cmds[1]));
            break;

        case "waitall":
            timePerLetter = singleFrameTiming * ParseUtil.getInt(cmds[1]);
            break;

        case "voice":
            if (cmds[1].ToLower() == "default")
            {
                letterSound.clip = SpriteFontRegistry.Get(SpriteFontRegistry.UI_DEFAULT_NAME).Sound;
            }
            else
            {
                letterSound.clip = AudioClipRegistry.GetVoice(cmds[1].ToLower());
            }
            break;

        case "font":
            letterSound.clip = SpriteFontRegistry.Get(cmds[1].ToLower()).Sound;
            break;

        case "novoice":
            letterSound.clip = null;
            break;

        case "next":
            autoSkip = true;
            break;

        case "func":
            if (caller == null)
            {
                UnitaleUtil.displayLuaError("???", "Func called but no script to reference. This is the engine's fault, not yours.");
            }
            if (args.Length > 1)
            {
                caller.Call(args[0], DynValue.NewString(args[1]));
            }
            else
            {
                caller.Call(cmds[1]);
            }
            break;
        }
    }
Esempio n. 4
0
    // Use this for initialization
    void Start()
    {
        FindObjectOfType <Fading>().BeginFade(-1);

        tmMain       = GameObject.Find("TextManager Main").GetComponent <TextManager>();
        tmChoice     = GameObject.Find("TextManager Choice").GetComponent <TextManager>();
        tmInfo       = GameObject.Find("TextManager Info").GetComponent <TextManager>();
        tmBigTalk    = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>();
        tmGold       = GameObject.Find("TextManager Gold").GetComponent <TextManager>();
        tmItem       = GameObject.Find("TextManager Item").GetComponent <TextManager>();
        tmInfoParent = tmInfo.transform.parent.parent.gameObject;
        tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });
        utHeart = GameObject.Find("utHeart");
        EnableBigText(false);

        if (scriptName == null)
        {
            UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()");
            return;
        }

        script = new ScriptWrapper()
        {
            scriptname = scriptName
        };
        string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName);

        if (scriptText == null)
        {
            UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()");
            return;
        }


        script.DoString(scriptText);
        script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>())));
        script.script.Globals["Interrupt"]    = ((Action <DynValue, string>)Interrupt);
        script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite;
        script.script.Globals["CreateLayer"]  = (Action <string, string, bool>)SpriteUtil.CreateLayer;
        script.script.Globals["CreateText"]   = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText;
        script.Call("Start");

        tmMain.SetCaller(script);
        tmChoice.SetCaller(script);
        tmInfo.SetCaller(script);
        tmBigTalk.SetCaller(script);

        tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) });
        tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9]    Buy\n    Sell\n    Talk\n    Exit", false, true) });
        tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) });
        tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) });
        tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });

        Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String);
        Camera.main.GetComponent <AudioSource>().Play();
    }
Esempio n. 5
0
    //I know, there's WAY too much parameters in here, but I don't have the choice right now.
    //If I find a way to get the Table's text from DynValues, I'll gladly reduce the number of
    //parameters of this, but right now, even if it is very painful to enter directly 6 or 10 parameters,
    //I don't find a proper way to do this. (Erm...plus, I have to say that if I put arrays into this,
    //you'll have to write braces in the function, so just think that I give you a favor xP)
    /// <summary>
    /// Permits to display an image on the screen at given dimensions, position and color
    /// </summary>
    /// <param name="path"></param>
    /// <param name="id"></param>
    /// <param name="posX"></param>
    /// <param name="posY"></param>
    /// <param name="toneR"></param>
    /// <param name="toneG"></param>
    /// <param name="toneB"></param>
    /// <param name="toneA"></param>
    [CYFEventFunction] public void DispImg(string path, int id, float posX, float posY, int toneR = 255, int toneG = 255, int toneB = 255, int toneA = 255)
    {
        GameObject image;
        bool       newImage = false;

        if (GameObject.Find("Image" + id) != null)
        {
            image = GameObject.Find("Image" + id);
        }
        else
        {
            newImage   = true;
            image      = Object.Instantiate(Resources.Load <GameObject>("Prefabs/ImageEvent"));
            image.name = "Image" + id;
            image.tag  = "Event";
            image.GetComponent <RectTransform>().SetParent(GameObject.Find("Canvas OW").transform);
            EventManager.instance.spriteControllers.Add("Image" + id, new LuaSpriteController(image.GetComponent <Image>()));
        }

        image.GetComponent <Image>().sprite = SpriteRegistry.Get(path);
        if (image.GetComponent <Image>().sprite == null)
        {
            throw new CYFException("Screen.DispImg: The sprite given doesn't exist.");
        }
        if (toneR < 0 || toneR > 255 || toneR % 1 != 0 || toneG < 0 || toneG > 255 || toneG % 1 != 0 || toneB < 0 || toneB > 255 || toneB % 1 != 0)
        {
            throw new CYFException("Screen.DispImg: You can't input a value out of [0; 255] for a color value, as it is clamped from 0 to 255.\nThe number have to be an integer.");
        }

        if (toneA >= 0 && toneA <= 255 && toneR % 1 == 0)
        {
            image.GetComponent <Image>().color = new Color32((byte)toneR, (byte)toneG, (byte)toneB, (byte)toneA);
        }
        image.GetComponent <RectTransform>().sizeDelta = image.GetComponent <Image>().sprite.bounds.size * 100;
        image.GetComponent <RectTransform>().position  = (Vector2)Camera.main.transform.position + new Vector2(posX - 320, posY - 240);

        if (newImage)
        {
            EventManager.instance.events.Add(image);
        }

        appliedScript.Call("CYFEventNextCommand");
    }
Esempio n. 6
0
 public bool TryCall(string func, DynValue[] param = null)
 {
     try {
         DynValue sval = script.GetVar(func);
         if (sval == null || sval.Type == DataType.Nil)
         {
             return(false);
         }
         if (param != null)
         {
             script.Call(func, param);
         }
         else
         {
             script.Call(func);
         }
         return(true);
     } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message); }
     return(true);
 }
 public bool TryCall(string func, DynValue[] param = null)
 {
     try {
         if (script.GetVar(func) == null)
         {
             return(false);
         }
         if (param != null)
         {
             script.Call(func, param);
         }
         else
         {
             script.Call(func);
         }
         return(true);
     } catch (InterpreterException ex) {
         UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, ex.DecoratedMessage);
         return(true);
     }
 }
Esempio n. 8
0
 [MoonSharpHidden] public void SetEquip(string itemName)
 {
     if (!Inventory.ItemExists(itemName))
     {
         throw new CYFException("The item \"" + itemName + "\" doesn't exist in the item list.");
     }
     if (Inventory.InventoryNumber(itemName) == -1)
     {
         throw new CYFException("You can't equip an item that isn't in the inventory.");
     }
     Inventory.ChangeEquipment(Inventory.InventoryNumber(itemName));
     appliedScript.Call("CYFEventNextCommand");
 }
Esempio n. 9
0
    [CYFEventFunction] public void EndDialog()
    {
        if (EventManager.instance.LoadLaunched)
        {
            UnitaleUtil.DisplayLuaError(appliedScript.scriptname, "General.EndDialog: This function cannot be used in EventPage0.");
            return;
        }
        else if (EventManager.instance.script == appliedScript)
        {
            UnitaleUtil.DisplayLuaError(appliedScript.scriptname, "General.EndDialog: This function can only be used in a coroutine.");
            return;
        }

        if (GameObject.Find("textframe_border_outer") && GameObject.Find("textframe_border_outer").GetComponent <UnityEngine.UI.Image>().color.a != 0)
        {
            // Clean up text manager
            textmgr.SetTextFrameAlpha(0);
            textmgr.textQueue = new TextMessage[] { };
            textmgr.DestroyChars();

            // Clean up SetChoice if applicable
            if (EventManager.instance.script != null && EventManager.instance.script == textmgr.caller)
            {
                string key = EventManager.instance.script.GetVar("_internalScriptName").String + ".ISetChoice";
                if (EventManager.instance.cSharpCoroutines.ContainsKey(key))
                {
                    // Stop the ISetChoice coroutine
                    EventManager.instance.ForceEndCoroutine(key);

                    // Remove the "tempHeart" GameObject if it already exists
                    if (GameObject.Find("Canvas OW/tempHeart"))
                    {
                        GameObject.Destroy(GameObject.Find("Canvas OW/tempHeart"));
                    }
                }
            }

            // End event
            appliedScript.Call("CYFEventNextCommand");
            if (EventManager.instance.script != null && EventManager.instance.script == textmgr.caller) // End text from event
            {
                textmgr.caller.Call("CYFEventNextCommand");
            }
            else
            {
                PlayerOverworld.instance.PlayerNoMove = false;  // End text no event
            }
        }
        else
        {
            appliedScript.Call("CYFEventNextCommand");
        }
    }
Esempio n. 10
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)
        {
            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;

        // 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;

        if (UnitaleUtil.MapCorrespondanceList.ContainsKey(SceneManager.GetActiveScene().name))
        {
            mapName = UnitaleUtil.MapCorrespondanceList[SceneManager.GetActiveScene().name];
        }
        else
        {
            mapName = 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));

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

        appliedScript.Call("CYFEventNextCommand");
    }
Esempio n. 11
0
 [CYFEventFunction] public int GetLevel()
 {
     try { return(PlayerCharacter.instance.LV); } finally { appliedScript.Call("CYFEventNextCommand"); }
 }
Esempio n. 12
0
 [CYFEventFunction] public string GetMusic()
 {
     try { return(Object.FindObjectOfType <MapInfos>().music); } finally { appliedScript.Call("CYFEventNextCommand"); }
 }
Esempio n. 13
0
 void Interrupt(DynValue text, string nextState = "MENU")
 {
     if (currentState != State.INTERRUPT)
     {
         script.Call("OnInterrupt", DynValue.NewString(nextState));
         try { interruptState = (State)Enum.Parse(typeof(State), nextState, true); }
         catch {
             UnitaleUtil.DisplayLuaError("Interrupting the shop menu", "\"" + nextState + "\" is not a valid shop state.");
             return;
         }
         ChangeState(State.INTERRUPT, 0, text);
     }
 }
Esempio n. 14
0
 [CYFEventFunction] public int GetLevel()
 {
     try { return(player.LV); } finally { appliedScript.Call("CYFEventNextCommand"); }
 }
Esempio n. 15
0
 /// <summary>
 /// Permits to teleport an event.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="dirX"></param>
 /// <param name="dirY"></param>
 [CYFEventFunction] public void Teleport(string name, float dirX, float dirY)
 {
     for (int i = 0; i < EventManager.instance.events.Count || name == "Player"; i++)
     {
         GameObject go = null;
         try { go = EventManager.instance.events[i]; } catch { }
         if (name == go.name || name == "Player")
         {
             if (name == "Player")
             {
                 go = GameObject.Find("Player");
             }
             Transform target = null;
             if (go.transform.parent != null)
             {
                 if (go.transform.parent.name == "SpritePivot")
                 {
                     target = go.transform.parent;
                 }
             }
             target          = target ?? go.transform;                     //oof
             target.position = new Vector3(dirX, dirY, target.position.z); //NEED PARENTAL REMOVE
             appliedScript.Call("CYFEventNextCommand");
             return;
         }
     }
     throw new CYFException("Event.Teleport: The name you entered in the function doesn't exist. Did you forget to add the 'Event' tag?");
 }
Esempio n. 16
0
 /// <summary>
 /// Checks if an event exists.
 /// </summary>
 /// <param name="name">Name of the event to check for.</param>
 /// <returns>True if the event exists, false otherwise.</returns>
 [CYFEventFunction] public bool Exists(string name)
 {
     try { return(GameObject.Find(name) != null); }
     finally { appliedScript.Call("CYFEventNextCommand"); }
 }