Exemplo n.º 1
0
    public void UpdateWave()
    {
        string currentScript = "";

        try {
            for (int i = 0; i < waves.Length; i++)
            {
                currentScript = waveNames[i];
                try { waves[i].script.Call(waves[i].script.Globals["Update"]); }
                catch (InterpreterException ex) {
                    UnitaleUtil.DisplayLuaError(currentScript, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message);
                    return;
                } catch (Exception ex) {
                    if (GlobalControls.retroMode)
                    {
                        return;
                    }
                    if (waves[i].script.Globals["Update"] == null)
                    {
                        UnitaleUtil.DisplayLuaError(currentScript, "All the wave scripts need an Update() function!");
                    }
                    else
                    {
                        UnitaleUtil.DisplayLuaError(currentScript, "This error is a " + ex.GetType() + " error.\nPlease send this error to the main dev.\n\n" + ex.Message + "\n\n" + ex.StackTrace);
                    }
                    return;
                }
            }
        } catch (InterpreterException ex) {
            UnitaleUtil.DisplayLuaError(currentScript, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message);
        }
    }
Exemplo n.º 2
0
 public static bool TryCall(string func, DynValue[] param = null)
 {
     if (UnitaleUtil.IsOverworld)
     {
         return(false);
     }
     try {
         if (EnemyEncounter.script.GetVar(func) == null)
         {
             return(false);
         }
         if (param != null)
         {
             EnemyEncounter.script.Call(func, param);
         }
         else
         {
             EnemyEncounter.script.Call(func);
         }
         return(true);
     } catch (InterpreterException ex) {
         UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message);
         return(true);
     }
 }
Exemplo n.º 3
0
    public static bool TryCall(string func, DynValue[] param = null)
    {
        bool overworld = false;

        if (GameObject.Find("Main Camera OW"))
        {
            overworld = true;
        }
        if (!overworld)
        {
            try {
                if (LuaEnemyEncounter.script.GetVar(func) == null)
                {
                    return(false);
                }
                if (param != null)
                {
                    LuaEnemyEncounter.script.Call(func, param);
                }
                else
                {
                    LuaEnemyEncounter.script.Call(func);
                }
                return(true);
            } catch (InterpreterException ex) {
                UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message);
                return(true);
            }
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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); }
    }
Exemplo n.º 6
0
    //public override void OnUpdate() {
    // destroy projectiles outside of the screen

    /*if (!screen.Contains(self.position))
     *  BulletPool.instance.Requeue(this);*/
    //}

    public override void OnProjectileHit()
    {
        if (owner.Globals["OnHit"] != null && owner.Globals.Get("OnHit") != null)
        {
            try { owner.Call(owner.Globals["OnHit"], this.ctrl); }
            catch (ScriptRuntimeException ex) {
                UnitaleUtil.DisplayLuaError((owner.Globals["wavename"] != null) ? (string)owner.Globals["wavename"] : "[wave script filename here]\n(should be a filename, sorry! missing feature)", UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message, ex.DoNotDecorateMessage);
            }
        }
        else
        {
            PlayerController.instance.Hurt();
        }
    }
Exemplo n.º 7
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("isactive", DynValue.NewBoolean(true));
            script.Bind("Kill", (Action)DoKill);
            script.Bind("Spare", (Action)DoSpare);
            script.Bind("Move", (Action <float, float>)Move);
            script.Bind("MoveTo", (Action <float, float>)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("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 != 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); }
    }
Exemplo n.º 8
0
    private void PrepareWave()
    {
        DynValue nextWaves = script.GetVar("nextwaves");

        if (nextWaves.Type != DataType.Table)
        {
            if (nextWaves.Type == DataType.Nil)
            {
                UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "nextwaves is not defined in your script.");
            }
            else
            {
                UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "nextwaves is a " + nextWaves.Type + ", but should be a table.");
            }
            return;
        }
        waves     = new ScriptWrapper[nextWaves.Table.Length];
        waveNames = new string[waves.Length];
        int currentWaveScript = 0;

        try {
            List <int> indexes = new List <int>();
            for (int i = 0; i < waves.Length; i++)
            {
                currentWaveScript = i;
                DynValue ArenaStatus = UserData.Create(ArenaManager.luaStatus);
                waves[i] = new ScriptWrapper {
                    scriptname = nextWaves.Table.Get(i + 1).String
                };
                waves[i].script.Globals.Set("Arena", ArenaStatus);
                waves[i].script.Globals["EndWave"]             = (Action)EndWaveTimer;
                waves[i].script.Globals["State"]               = (Action <Script, string>)UIController.SwitchStateOnString;
                waves[i].script.Globals["CreateProjectile"]    = (Func <Script, string, float, float, string, DynValue>)CreateProjectile;
                waves[i].script.Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectileAbs;
                if (nextWaves.Table.Get(i + 1).Type != DataType.String)
                {
                    UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Non-string value encountered in nextwaves table");
                    return;
                }
                waveNames[i] = nextWaves.Table.Get(i + 1).String;
                waves[i].script.Globals["wavename"] = nextWaves.Table.Get(i + 1).String;
                try {
                    waves[i].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String));
                    indexes.Add(i);
                } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(i + 1).String + ".lua", UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message); } catch (Exception ex) {
                    if (!GlobalControls.retroMode && !ScriptRegistry.dict.ContainsKey(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String))
                    {
                        UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "The wave \"" + nextWaves.Table.Get(i + 1).String + "\" doesn't exist.");
                    }
                    else
                    {
                        UnitaleUtil.DisplayLuaError("<UNKNOWN LOCATION>", ex.Message + "\n\n" + ex.StackTrace);
                    }
                }
            }
            Table luaWaveTable = new Table(null);
            for (int i = 0; i < indexes.Count; i++)
            {
                luaWaveTable.Set(i + 1, UserData.Create(waves[indexes[i]]));
            }
            script.SetVar("Wave", DynValue.NewTable(luaWaveTable));
        } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message); }
    }
Exemplo n.º 9
0
 private void Advance()
 {
     NextLine();
     if (caller.script.Globals["OnTextAdvance"] == null || caller.script.Globals.Get("OnTextAdvance") == null)
     {
         return;
     }
     try { caller.script.Call(caller.script.Globals["OnTextAdvance"], this, autoDestroyed); }
     catch (ScriptRuntimeException ex) { UnitaleUtil.DisplayLuaError(caller.scriptname, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message, ex.DoNotDecorateMessage); }
 }
Exemplo n.º 10
0
 public DynValue Call(Script caller, string function, DynValue[] args = null, bool checkExist = false)
 {
     if (script.Globals[function] == null || script.Globals.Get(function) == null)
     {
         if (checkExist && !GlobalControls.retroMode)
         {
             UnitaleUtil.DisplayLuaError(scriptname, "Attempted to call the function \"" + function + "\", but it didn't exist.");
         }
         //Debug.LogWarning("Attempted to call the function " + function + " but it didn't exist.");
         return(DynValue.Nil);
     }
     if (args != null)
     {
         DynValue d = DynValue.Nil;
         try { d = script.Call(script.Globals[function], args); }
         catch (Exception e) {
             if (args[0].Type == DataType.Table && args.Length == 1)
             {
                 DynValue[] argsNew = UnitaleUtil.TableToDynValueArray(args[0].Table);
                 try { d = script.Call(script.Globals[function], argsNew); }
                 catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptname, ex.DecoratedMessage == null ?
                                                                               ex.Message :
                                                                               UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message,
                                                                               ex.DoNotDecorateMessage); }
                 catch (Exception ex) {
                     if (!GlobalControls.retroMode)
                     {
                         UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + ex.GetType() + " error. Contact a developer and show them this screen, this must be an engine-side error.\n\n" + ex.Message + "\n\n" + ex.StackTrace + "\n");
                     }
                 }
             }
             else if (e.GetType() == typeof(InterpreterException) || e.GetType().BaseType == typeof(InterpreterException) || e.GetType().BaseType.BaseType == typeof(InterpreterException))
             {
                 UnitaleUtil.DisplayLuaError(scriptname, ((InterpreterException)e).DecoratedMessage == null ?
                                             ((InterpreterException)e).Message :
                                             UnitaleUtil.FormatErrorSource(((InterpreterException)e).DecoratedMessage, ((InterpreterException)e).Message) + ((InterpreterException)e).Message,
                                             ((InterpreterException)e).DoNotDecorateMessage);
             }
             else if (!GlobalControls.retroMode)
             {
                 UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + e.GetType() + " error. Contact a dev and show them this screen, this must be an engine-side error.\n\n" + e.Message + "\n\n" + e.StackTrace + "\n");
             }
         }
         return(d);
     }
     else
     {
         DynValue d = DynValue.Nil;
         try { d = script.Call(script.Globals[function]); }
         catch (InterpreterException ex) {
             UnitaleUtil.DisplayLuaError(scriptname, ex.DecoratedMessage == null ?
                                         ex.Message :
                                         UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message,
                                         ex.DoNotDecorateMessage);
         } catch (Exception ex) {
             if (GlobalControls.retroMode)
             {
                 return(d);
             }
             if (ex.GetType().ToString() == "System.IndexOutOfRangeException" && ex.StackTrace.StartsWith("  at (wrapper stelemref) object:stelemref (object,intptr,object)"
                                                                                                          + "\r\n  at MoonSharp.Interpreter.DataStructs.FastStack`1[MoonSharp.Interpreter.DynValue].Push"))
             {
                 UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "<b>Possible infinite loop</b>\n\nThis is a " + ex.GetType() + " error.\n\n"
                                             + "You almost definitely have an infinite loop in your code. A function tried to call itself infinitely. It could be a normal function or a metatable function."
                                             + "\n\n\nFull stracktrace (see CYF output log at <b>" + Application.persistentDataPath + "/output_log.txt</b>):\n\n" + ex.StackTrace);
             }
             else
             {
                 UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + ex.GetType() + " error. Contact a dev and show them this screen, this must be an engine-side error.\n\n" + ex.Message + "\n\n" + ex.StackTrace + "\n");
             }
         }
         return(d);
     }
 }