コード例 #1
0
    private void PrepareWave()
    {
        DynValue nextWaves = script.GetVar("nextwaves");

        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()
                {
                    script = LuaScriptBinder.BoundScript()
                };
                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;
                }
                else
                {
                    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", ex.DecoratedMessage); } 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", ex.DecoratedMessage); }
    }
コード例 #2
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", (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); }
    }
コード例 #3
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); }
    }
コード例 #4
0
    /*public override string GetRegularScreenDialog()
     * {
     *  if (!error)
     *      return script.Call(script.Globals["GetRegularScreenDialog"]).String;
     *  else
     *  {
     *      UIController.instance.textmgr.setFont(SpriteFontRegistry.F_UI_MONSTERDIALOG);
     *      luaErrorMsg = luaErrorMsg.Replace("\\n", "").Replace("\\r", "").Replace("\\t", "");
     *      for (int i = 0; i < luaErrorMsg.Length; i++)
     *          if (i > 0 && i % 40 == 0)
     *          {
     *              luaErrorMsg = luaErrorMsg.Insert(i, "\\r");
     *          }
     *      return "[starcolor:ffffff][color:ffffff]LUA error.\n" + luaErrorMsg;
     *  }
     * }*/

    public override string[] GetDefenseDialog()
    {
        if (!error)
        {
            DynValue dialogues = script.GetVar("currentdialogue");
            if (dialogues == null || dialogues.Table == null)
            {
                if (dialogues.String != null)
                {
                    return new string[] { dialogues.String }
                }
            }
            ;
            else if (Dialogue == null)
            {
                return(null);
            }
            else
            {
                return new string[] { Dialogue[UnityEngine.Random.Range(0, Dialogue.Length)] }
            };

            string[] dialogueStrings = new string[dialogues.Table.Length];
            for (int i = 0; i < dialogues.Table.Length; i++)
            {
                dialogueStrings[i] = dialogues.Table.Get(i + 1).String;
            }
            script.SetVar("currentdialogue", DynValue.NewNil());
            return(dialogueStrings);
        }
コード例 #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)
        {
            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();
    }
コード例 #6
0
    protected override void loadEnemiesAndPositions()
    {
        AudioSource musicSource = Camera.main.GetComponent <AudioSource>();

        EncounterText = script.GetVar("encountertext").String;
        DynValue enemyScriptsLua   = script.GetVar("enemies");
        DynValue enemyPositionsLua = script.GetVar("enemypositions");
        string   musicFile         = script.GetVar("music").String;

        try
        {
            enemies = new LuaEnemyController[enemyScriptsLua.Table.Length]; // dangerously assumes enemies is defined
        }
        catch (Exception)
        {
            UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, "There's no enemies table in your encounter. Is this a pre-0.1.2 encounter? It's easy to fix!\n\n"
                                        + "1. Create a Monsters folder in the mod's Lua folder\n"
                                        + "2. Add the monster script (custom.lua) to this new folder\n"
                                        + "3. Add the following line to the beginning of this encounter script, located in the mod folder/Lua/Encounters:\nenemies = {\"custom\"}\n"
                                        + "4. You're done! Starting from 0.1.2, you can name your monster and encounter scripts anything.");
            return;
        }
        if (enemyPositionsLua != null && enemyPositionsLua.Table != null)
        {
            enemyPositions = new Vector2[enemyPositionsLua.Table.Length];
            for (int i = 0; i < enemyPositionsLua.Table.Length; i++)
            {
                Table posTable = enemyPositionsLua.Table.Get(i + 1).Table;
                if (i >= enemies.Length)
                {
                    break;
                }

                enemyPositions[i] = new Vector2((float)posTable.Get(1).Number, (float)posTable.Get(2).Number);
            }
        }

        if (musicFile != null)
        {
            try
            {
                AudioClip music = AudioClipRegistry.GetMusic(musicFile);
                musicSource.clip = music;
            }
            catch (Exception)
            {
                Debug.Log("Loading custom music failed.");
            }
        }
        else
        {
            musicSource.clip = AudioClipRegistry.GetMusic("mus_battle1");
        }

        // Instantiate all the enemy objects
        if (enemies.Length > enemyPositions.Length)
        {
            UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, "All enemies in an encounter must have a screen position defined. Either your enemypositions table is missing, "
                                        + "or there are more enemies than available positions. Refer to the documentation's Basic Setup section on how to do this.");
        }
        enemyInstances = new GameObject[enemies.Length];
        for (int i = 0; i < enemies.Length; i++)
        {
            enemyInstances[i] = Instantiate(Resources.Load <GameObject>("Prefabs/LUAEnemy"));
            enemyInstances[i].transform.SetParent(gameObject.transform);
            enemyInstances[i].transform.localScale = new Vector3(1, 1, 1); // apparently this was suddenly required or the scale would be (0,0,0)
            enemies[i]            = enemyInstances[i].GetComponent <LuaEnemyController>();
            enemies[i].scriptName = enemyScriptsLua.Table.Get(i + 1).String;
            if (i < enemyPositions.Length)
            {
                enemies[i].GetComponent <RectTransform>().anchoredPosition = enemyPositions[i];
            }
            else
            {
                enemies[i].GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 1);
            }
        }

        // Attach the controllers to the encounter's enemies table
        DynValue[] enemyStatusCtrl = new DynValue[enemies.Length];
        Table      luaEnemyTable   = script.GetVar("enemies").Table;

        for (int i = 0; i < enemyStatusCtrl.Length; i++)
        {
            //enemies[i].luaStatus = new LuaEnemyStatus(enemies[i]);
            enemies[i].script = new ScriptWrapper();
            luaEnemyTable.Set(i + 1, UserData.Create(enemies[i].script));
        }
        script.SetVar("enemies", DynValue.NewTable(luaEnemyTable));
        musicSource.Play(); // play that funky music
    }