Esempio n. 1
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)
        {
            throw new CYFException("You must give a valid script name to the function General.EnterShop()");
        }

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

        if (scriptText == null)
        {
            throw new CYFException("You must give a valid script name to the function General.EnterShop()");
        }

        try {
            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;
            TryCall("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>().time = 0;
            Camera.main.GetComponent <AudioSource>().Play();

            SetPlayerOnSelection();
        }
        catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage != null ? UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message : ex.Message); }
        catch (Exception ex)            { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); }
    }
Esempio n. 2
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();
    }
    private void Start()
    {
        try {
            string scriptText = ScriptRegistry.Get(ScriptRegistry.MONSTER_PREFIX + scriptName);
            if (scriptText == null)
            {
                UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Tried to load monster script " + scriptName + ".lua but it didn't exist. Is it misspelled?");
                return;
            }
            script.scriptname = scriptName;
            script.Bind("SetSprite", (Action <string>)SetSprite);
            script.Bind("SetActive", (Action <bool>)SetActive);
            script.Bind("isActive", (Func <bool>)InFight);
            script.Bind("Kill", (Action)DoKill);
            script.Bind("Spare", (Action)DoSpare);
            script.Bind("Move", (Action <float, float, bool>)Move);
            script.Bind("MoveTo", (Action <float, float, bool>)MoveTo);
            script.Bind("BindToArena", (Action <bool, bool>)BindToArena);
            script.Bind("SetDamage", (Action <int>)SetDamage);
            script.Bind("SetBubbleOffset", (Action <int, int>)SetBubbleOffset);
            script.Bind("SetDamageUIOffset", (Action <int, int>)SetDamageUIOffset);
            script.Bind("SetSliceAnimOffset", (Action <int, int>)SetSliceAnimOffset);
            script.Bind("GetLetters", (Func <Letter[]>)GetLetters);
            script.Bind("State", (Action <Script, string>)UIController.SwitchStateOnString);
            script.SetVar("canmove", DynValue.NewBoolean(false));
            sprite = new LuaSpriteController(GetComponent <Image>());
            script.SetVar("monstersprite", UserData.Create(sprite, LuaSpriteController.data));
            script.DoString(scriptText);

            string spriteFile = script.GetVar("sprite").String;
            if (spriteFile != null)
            {
                SetSprite(spriteFile);
            }
            else
            {
                throw new CYFException("missing sprite");
            }

            ui = FindObjectOfType <UIController>();
            if (MaxHP == 0)
            {
                MaxHP = HP;
            }

            textBubbleSprite = Resources.Load <Sprite>("Sprites/UI/SpeechBubbles/right");

            /*if (script.GetVar("canspare") == null) CanSpare = false;
             * if (script.GetVar("cancheck") == null) CanCheck = true;*/
        }
        catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage); }
        catch (Exception ex)            { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); }
    }
Esempio n. 4
0
    private void Start()
    {
        try
        {
            string scriptText = ScriptRegistry.Get(ScriptRegistry.MONSTER_PREFIX + scriptName);
            if (scriptText == null)
            {
                UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, "Tried to load monster script " + scriptName + ".lua but it didn't exist. Is it misspelled?");
                return;
            }

            script.scriptname = scriptName;
            script.Bind("SetSprite", (Action <string>)SetSprite);
            script.Bind("SetActive", (Action <bool>)SetActive);
            script.Bind("Kill", (Action)DoKill);
            script.Bind("Spare", (Action)DoSpare);
            script.DoString(scriptText);

            string spriteFile = script.GetVar("sprite").String;
            if (spriteFile != null)
            {
                SetSprite(spriteFile);
            }
            else
            {
                throw new InvalidOperationException("missing sprite");
            }

            ui               = FindObjectOfType <UIController>();
            maxHP            = HP;
            currentHP        = HP;
            textBubbleSprite = Resources.Load <Sprite>("Sprites/UI/SpeechBubbles/right");

            /*if (script.GetVar("canspare") == null)
             * {
             *  CanSpare = false;
             * }
             * if (script.GetVar("cancheck") == null)
             * {
             *  CanCheck = true;
             * }*/
        }
        catch (InterpreterException ex)
        {
            UnitaleUtil.displayLuaError(scriptName, ex.DecoratedMessage);
        }
        catch (Exception ex)
        {
            UnitaleUtil.displayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n" + ex.StackTrace);
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Attempts to initialize the encounter's script file and bind encounter-specific functions to it.
    /// </summary>
    /// <returns>True if initialization succeeded, false if there was an error.</returns>
    private bool initScript()
    {
        script            = new ScriptWrapper();
        script.scriptname = StaticInits.ENCOUNTER;
        string scriptText = ScriptRegistry.Get(ScriptRegistry.ENCOUNTER_PREFIX + StaticInits.ENCOUNTER);

        try
        {
            script.DoString(scriptText);
        }
        catch (InterpreterException ex)
        {
            UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, ex.DecoratedMessage);
            return(false);
        }
        script.Bind("RandomEncounterText", (Func <string>)RandomEncounterText);
        script.Bind("CreateProjectile", (Func <Script, string, float, float, DynValue>)CreateProjectile);
        script.Bind("CreateProjectileAbs", (Func <Script, string, float, float, DynValue>)CreateProjectileAbs);
        script_ref = script;
        return(true);
    }