Exemplo n.º 1
0
 public static void BattleDialog(DynValue arg)
 {
     if (UIController.instance == null)
     {
         UnitaleUtil.Warn("BattleDialog can only be used as early as EncounterStarting.");
     }
     else
     {
         UIController.instance.battleDialogueStarted = true;
         TextMessage[] msgs = null;
         if (arg.Type == DataType.String)
         {
             msgs = new TextMessage[] { new RegularMessage(arg.String) }
         }
         ;
         else if (arg.Type == DataType.Table && (GlobalControls.retroMode || arg.Table.Length > 0))
         {
             msgs = new TextMessage[arg.Table.Length];
             for (int i = 0; i < arg.Table.Length; i++)
             {
                 msgs[i] = new RegularMessage(arg.Table.Get(i + 1).String);
             }
         }
         else if (!GlobalControls.retroMode)
         {
             UnitaleUtil.DisplayLuaError("BattleDialog", "You need to input a non-empty array or a string here." +
                                         "\n\nIf you're sure that you've entered what's needed, you may contact the dev.");
         }
         if (!GlobalControls.retroMode)
         {
             UIController.instance.mainTextManager.SetEffect(new TwitchEffect(UIController.instance.mainTextManager));
         }
         UIController.instance.ActionDialogResult(msgs, UIController.UIState.ENEMYDIALOGUE);
     }
 }
Exemplo n.º 2
0
    public static AudioClip tryLoad(string key)
    {
        string k = key;

        key = key.ToLower();
        if (dictMod.ContainsKey(key))
        {
            dict[key] = FileLoader.getAudioClip(currentPath, dictMod[key].FullName);
        }
        else if (dictDefault.ContainsKey(key))
        {
            dict[key] = FileLoader.getAudioClip(currentPath, dictDefault[key].FullName);
        }
        else
        {
            if (GlobalControls.retroMode)
            {
                UnitaleUtil.Warn("The audio file \"" + k + "\" doesn't exist.");
            }
            else
            {
                throw new CYFException("Attempted to load the audio file \"" + k + "\" from either a mod or default directory, but it was missing in both.");
            }
            return(null);
        }
        return(dict[key]);
    }
Exemplo n.º 3
0
 /// <summary>
 /// Remove an image from the screen
 /// </summary>
 /// <param name="id"></param>
 [CYFEventFunction] public void SupprImg(int id)
 {
     if (GameObject.Find("Image" + id))
     {
         EventManager.instance.luaEventOw.Remove("Image" + id);
     }
     else
     {
         UnitaleUtil.Warn("The image #" + id + " doesn't exist.", false);
     }
     appliedScript.Call("CYFEventNextCommand");
 }
Exemplo n.º 4
0
 public void MoveAbove(LuaSpriteController sprite)
 {
     if (sprite == null)
     {
         throw new CYFException("sprite.MoveAbove: The sprite passed as an argument is nil.");
     }
     if (sprite.GetTarget().parent != GetTarget().parent)
     {
         UnitaleUtil.Warn("You can't change the order of two sprites without the same parent.");
     }
     else
     {
         GetTarget().SetSiblingIndex(sprite.GetTarget().GetSiblingIndex() + 1);
     }
 }
Exemplo n.º 5
0
 public void MoveAbove(LuaTextManager otherText)
 {
     CheckExists();
     if (otherText == null || !otherText.isactive)
     {
         throw new CYFException("The text object passed as an argument is nil or inactive.");
     }
     if (transform.parent.parent != otherText.transform.parent.parent)
     {
         UnitaleUtil.Warn("You can't change the order of two text objects without the same parent.");
     }
     else
     {
         try { transform.parent.SetSiblingIndex(otherText.transform.parent.GetSiblingIndex() + 1); }
         catch { throw new CYFException("Error while calling text.MoveAbove."); }
     }
 }
Exemplo n.º 6
0
 // Use this for initialization
 private void Start()
 {
     bgImage = GetComponent <Image>();
     try {
         Sprite bg = SpriteUtil.FromFile(FileLoader.pathToModFile("Sprites/bg.png"));
         if (bg == null)
         {
             return;
         }
         bg.texture.filterMode = FilterMode.Point;
         bgImage.sprite        = bg;
         bgImage.color         = Color.white;
     } catch {
         // Background failed loading, no need to do anything.
         UnitaleUtil.Warn("No background file found. Using empty background.");
     }
 }
Exemplo n.º 7
0
    public static void SetItemList(string[] items)
    {
        foreach (string item in items)
        {
            // Make sure that the item exists before trying to create it
            string outString;
            int    outInt;
            if (!addedItems.Contains(item) && !NametoDesc.TryGetValue(item, out outString) && !NametoShortName.TryGetValue(item, out outString) && !NametoType.TryGetValue(item, out outInt) && !NametoPrice.TryGetValue(item, out outInt))
            {
                throw new CYFException("Inventory.SetInventory: The item \"" + item + "\" was not found." + (UnitaleUtil.IsOverworld ? "" : "\n\nAre you sure you called Inventory.AddCustomItems first?"));
            }
        }

        inventory = new List <UnderItem>(new UnderItem[] { });
        for (int i = 0; i < items.Length; i++)
        {
            if (i == inventorySize)
            {
                UnitaleUtil.Warn("The inventory can only contain " + inventorySize + " items, yet you tried to add the item \"" + items[i] + "\" as item number " + (i + 1) + ".");
                break;
            }
            inventory.Add(new UnderItem(items[i]));
        }
    }
Exemplo n.º 8
0
    public static void ItemLibrary(string name, int type, out TextMessage[] mess, out float amount, out string replacement)
    {
        mess = new TextMessage[] { }; amount = 0; replacement = null;
        switch (type)
        {
        case 0:
            switch (name)
            {
            case "Bandage":
                amount = 10;
                mess   = new[] { new TextMessage("You re-applied the bandage.[w:10]\rStill kind of gooey.[w:10]\nYou recovered 10 HP!", true, false) };
                break;

            case "Monster Candy":
                amount = 10;
                mess   = new[] { new TextMessage("You ate the Monster Candy.[w:10]\rVery un-licorice-like.[w:10]\nYou recovered 10 HP!", true, false) };
                break;

            case "Spider Donut":
                amount = 12;
                mess   = new[] { new TextMessage("Don't worry,[w:5]spider didn't.[w:10]\nYou recovered 12 HP!", true, false) };
                break;

            case "Spider Cider":
                amount = 24;
                mess   = new[] { new TextMessage("You drank the Spider Cider.[w:10]\nYou recovered 24 HP!", true, false) };
                break;

            case "Butterscotch Pie":
                amount = 999;
                mess   = new[] { new TextMessage("You ate the Butterscotch Pie.[w:10]\nYour HP was maxed out.", true, false) };
                break;

            case "Snail Pie":
                amount = PlayerCharacter.instance.MaxHP - (int)PlayerCharacter.instance.HP - 1;
                mess   = new[] { new TextMessage("You ate the Snail Pie.[w:10]\nYour HP was maxed out.", true, false) };
                break;

            case "Snowman Piece":
                amount = 45;
                mess   = new[] { new TextMessage("You ate the Snowman Piece.[w:10]\nYou recovered 45 HP!", true, false) };
                break;

            case "Nice Cream":
                amount = 15;
                int    randomCream   = Math.RandomRange(0, 8);
                string sentenceCream = "[w:10]\nYou recovered 15 HP!";
                switch (randomCream)
                {
                case 0: sentenceCream = "You're super spiffy!" + sentenceCream; break;

                case 1: sentenceCream = "Are those claws natural?" + sentenceCream; break;

                case 2: sentenceCream = "Love yourself! I love you!" + sentenceCream; break;

                case 3: sentenceCream = "You look nice today!" + sentenceCream; break;

                case 4: sentenceCream = "(An illustration of a hug)" + sentenceCream; break;

                case 5: sentenceCream = "Have a wonderful day!" + sentenceCream; break;

                case 6: sentenceCream = "Is this as sweet as you?" + sentenceCream; break;

                case 7: sentenceCream = "You're just great!" + sentenceCream; break;
                }
                mess = new[] { new TextMessage(sentenceCream, true, false) }; break;

            case "Bisicle":
                amount      = 11;
                replacement = "Unisicle";
                mess        = new[] { new TextMessage("You ate one half of\rthe Bisicle.[w:10]\nYou recovered 11 HP!", true, false) };
                break;

            case "Unisicle":
                amount = 11;
                mess   = new[] { new TextMessage("You ate the Unisicle.[w:10]\nYou recovered 11 HP!", true, false) };
                break;

            case "Cinnabon Bunny":
                amount = 22;
                mess   = new[] { new TextMessage("You ate the Cinnabon Bun.[w:10]\nYou recovered 22 HP!", true, false) };
                break;

            case "Astronaut Food":
                amount = 21;
                mess   = new[] { new TextMessage("You ate the Astronaut Food.[w:10]\nYou recovered 21 HP!", true, false) };
                break;

            case "Crab Apple":
                amount = 18;
                mess   = new[] { new TextMessage("You ate the Crab Apple.[w:10]\nYou recovered 18 HP!", true, false) };
                break;

            case "Sea Tea":
                amount = 18;
                mess   = new[] { new TextMessage("[sound:SeaTea]You drank the Sea Tea.[w:10]\nYour SPEED boosts![w:10]\nYou recovered 18 HP!", true, false),
                                 new TextMessage("[music:pause][waitall:10]...[waitall:1]but for now stats\rdon't change.", true, false),
                                 new TextMessage("[noskip][music:unpause][next]", true, false) }; break;

            case "Abandoned Quiche":
                amount = 34;
                mess   = new[] { new TextMessage("You ate the quiche.[w:10]\nYou recovered 34 HP!", true, false) };
                break;

            case "Temmie Flakes":
                amount = 2;
                mess   = new[] { new TextMessage("You ate the Temmie Flakes.[w:10]\nYou recovered 2 HP!", true, false) };
                break;

            case "Dog Salad":
                int    randomSalad = Math.RandomRange(0, 4);
                string sentenceSalad;
                switch (randomSalad)
                {
                case 0:
                    amount        = 2;
                    sentenceSalad = "Oh. These are bones...[w:10]\rYou recovered 2 HP!";
                    break;

                case 1:
                    amount        = 10;
                    sentenceSalad = "Oh. Fried tennis ball...[w:10]\rYou recovered 10 HP!";
                    break;

                case 2:
                    amount        = 30;
                    sentenceSalad = "Oh. Tastes yappy...[w:10]\rYou recovered 30 HP!";
                    break;

                default:
                    amount        = 999;
                    sentenceSalad = "It's literally garbage???[w:10]\rYour HP was maxed out.";
                    break;
                }
                mess = new[] { new TextMessage(sentenceSalad, true, false) };
                break;

            case "Instant Noodles":
                mess = new[] { new TextMessage("You remove the Instant\rNoodles from their\rpackaging.", true, false),
                               new TextMessage("You put some water in\rthe pot and place it\ron the heat.", true, false),
                               new TextMessage("You wait for the water\rto boil...", true, false),
                               new TextMessage("[noskip][music:pause]...[w:30]\n...[w:30]\n...", true, false),
                               new TextMessage("[noskip]It's[w:30] boiling.", true, false),
                               new TextMessage("[noskip]You place the noodles[w:30]\rinto the pot.", true, false),
                               new TextMessage("[noskip]4[w:30] minutes left[w:30] until\rthe noodles[w:30] are finished.", true, false),
                               new TextMessage("[noskip]3[w:30] minutes left[w:30] until\rthe noodles[w:30] are finished.", true, false),
                               new TextMessage("[noskip]2[w:30] minutes left[w:30] until\rthe noodles[w:30] are finished.", true, false),
                               new TextMessage("[noskip]1[w:30] minute left[w:30] until\rthe noodles[w:30] are finished.", true, false),
                               new TextMessage("[noskip]The noodles[w:30] are finished.", true, false),
                               new TextMessage("...they don't taste very\rgood.", true, false),
                               new TextMessage("You add the flavor packet.", true, false),
                               new TextMessage("That's better.", true, false),
                               new TextMessage("Not great,[w:5] but better.", true, false),
                               new TextMessage("[music:unpause]You ate the Instant Noodles.[w:10]\nYou recovered 4 HP!", true, false) };
                break;

            case "Hot Dog...?":
                amount = 20;
                mess   = new[] { new TextMessage("[sound:HotDog]You ate the Hot Dog.[w:10]\nYou recovered 20 HP!", true, false) };
                break;

            case "Hot Cat":
                amount = 21;
                mess   = new[] { new TextMessage("[sound:HotCat]You ate the Hot Cat.[w:10]\nYou recovered 21 HP!", true, false) };
                break;

            case "Junk Food":
                amount = 17;
                mess   = new[] { new TextMessage("You ate the Junk Food.[w:10]\nYou recovered 17 HP!", true, false) };
                break;

            case "Hush Puppy":
                amount = 65;
                mess   = new[] { new TextMessage("You ate the Hush Puppy.[w:10]\rDog-magic is neutralized.[w:10]\nYou recovered 65 HP!", true, false) };
                break;

            case "Starfait":
                amount = 14;
                mess   = new[] { new TextMessage("You ate the Starfait.[w:10]\nYou recovered 14 HP!", true, false) };
                break;

            case "Glamburger":
                amount = 27;
                mess   = new[] { new TextMessage("You ate the Glamburger.[w:10]\nYou recovered 27 HP!", true, false) }; break;

            case "Legendary Hero":
                amount = 40;
                mess   = new[] { new TextMessage("[sound:LegHero]You ate the Legendary Hero.[w:10]\nATTACK increased by 4![w:10]\nYou recovered 40 HP!", true, false),
                                 new TextMessage("[music:pause][waitall:10]...[waitall:1]but for now stats\rdon't change.", true, false),
                                 new TextMessage("[noskip][music:unpause][next]", true, false) };
                break;

            case "Steak in the Shape of Mettaton's Face":
                amount = 60;
                mess   = new[] { new TextMessage("You ate the Face Steak.[w:10]\nYou recovered 60 HP!", true, false) };
                break;

            case "Popato Chisps":
                amount = 13;
                mess   = new[] { new TextMessage("You ate the Popato Chisps.[w:10]\nYou recovered 13 HP!", true, false) };
                break;

            case "Bad Memory":
                if (PlayerCharacter.instance.HP <= 3)
                {
                    amount = 999;
                    mess   = new[] { new TextMessage("You consume the Bad Memory.[w:10]\nYour HP was maxed out.", true, false) };
                }
                else
                {
                    amount = -1;
                    mess   = new[] { new TextMessage("You consume the Bad Memory.[w:10]\nYou lost 1 HP.", true, false) };
                }
                break;

            case "Last Dream":
                amount = 17;
                mess   = new[] { new TextMessage("Through DETERMINATION,\rthe dream became true.[w:10]\nYou recovered 17 HP!", true, false) };
                break;

            default:
                UnitaleUtil.Warn("The item doesn't exist in this pool.");
                break;
            }
            if (amount != 0)
            {
                if (UnitaleUtil.IsOverworld)
                {
                    EventManager.instance.luaPlayerOw.setHP(PlayerController.instance.HP + amount);
                }
                else
                {
                    PlayerController.instance.Hurt(-amount, 0);
                }
            }
            break;

        case 1:
            switch (name)
            {
            case "Toy Knife":     amount = 3;  break;

            case "Tough Glove":   amount = 5;  break;

            case "Ballet Shoes":  amount = 7;  break;

            case "Torn Notebook": amount = 2;  break;

            case "Burnt Pan":     amount = 10; break;

            case "Empty Gun":     amount = 12; break;

            case "Worn Dagger":   amount = 15; break;

            case "Real Knife":    amount = 99; break;

            default:              UnitaleUtil.Warn("The item doesn't exist in this pool."); break;
            }
            break;

        case 2:
            switch (name)
            {
            case "Faded Ribbon":   amount = 3;  break;

            case "Manly Bandanna": amount = 7;  break;

            case "Old Tutu":       amount = 10; break;

            case "Cloudy Glasses": amount = 6;  break;

            case "Stained Apron":  amount = 11; break;

            case "Cowboy Hat":     amount = 12; break;

            case "Heart Locket":   amount = 15; break;

            case "The Locket":     amount = 99; break;

            default:               UnitaleUtil.Warn("The item doesn't exist in this pool."); break;
            }
            break;

        default:
            switch (name)
            {
            case "Testing Dog": mess = new[] { new TextMessage("This dog is testing something.", true, false), new TextMessage("I must leave it alone.", true, false) }; break;

            case "Stick":       mess = new[] { new TextMessage("You throw the stick.[w:10]\nNothing happens.", true, false) }; break;

            default:            UnitaleUtil.Warn("The item doesn't exist in this pool."); break;
            }
            break;
        }
    }
Exemplo n.º 9
0
    protected void LoadEnemiesAndPositions()
    {
        AudioSource musicSource = GameObject.Find("Main Camera").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 EnemyController[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 (MusicManager.IsStoppedOrNull(PlayerOverworld.audioKept))
        {
            if (musicFile != null)
            {
                try {
                    AudioClip music = AudioClipRegistry.GetMusic(musicFile);
                    musicSource.clip      = music;
                    MusicManager.filename = "music:" + musicFile.ToLower();
                } catch (Exception) { UnitaleUtil.Warn("Loading custom music failed."); }
            }
            else
            {
                musicSource.clip      = AudioClipRegistry.GetMusic("mus_battle1");
                musicSource.volume    = .6f;
                MusicManager.filename = "music:mus_battle1";
            }
            NewMusicManager.audioname["src"] = MusicManager.filename;
        }
        // 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 1"));
            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 <EnemyController>();
            enemies[i].scriptName = enemyScriptsLua.Table.Get(i + 1).String;
            enemies[i].index      = i;
            enemies[i].GetComponent <RectTransform>().anchoredPosition = i < enemyPositions.Length ? new Vector2(enemyPositions[i].x, enemyPositions[i].y) : 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].script = new ScriptWrapper();
            luaEnemyTable.Set(i + 1, UserData.Create(enemies[i].script));
        }
        script.SetVar("enemies", DynValue.NewTable(luaEnemyTable));
        Table luaWaveTable = new Table(null);

        script.SetVar("Wave", DynValue.NewTable(luaWaveTable));

        //if (MusicManager.isStoppedOrNull(PlayerOverworld.audioKept))
        //    musicSource.Play(); // play that funky music
    }
Exemplo n.º 10
0
    [CYFEventFunction] public void Remove(string eventName)
    {
        GameObject go = GameObject.Find(eventName);

        if (!go)
        {
            UnitaleUtil.Warn("Event.Remove: The event " + eventName + " doesn't exist but you tried to remove it.", false);
        }
        else
        {
            EventOW ev = go.GetComponent <EventOW>();
            if (ev != null)
            {
                if (!(ev.name.Contains("Image") || ev.name.Contains("Tone")))
                {
                    if (GlobalControls.EventData.ContainsKey(ev.name))
                    {
                        GlobalControls.EventData.Remove(ev.name);
                    }

                    try {
                        GameState.EventInfos ei = new GameState.EventInfos()
                        {
                            CurrPage = ev.actualPage,
                            CurrSpriteNameOrCYFAnim = ev.GetComponent <CYFAnimator>()
                                ? ev.GetComponent <CYFAnimator>().specialHeader
                                : EventManager.instance.spriteControllers[ev.name].img.GetComponent <SpriteRenderer>()
                                    ? EventManager.instance.spriteControllers[ev.name].img.GetComponent <SpriteRenderer>().sprite.name
                                    : EventManager.instance.spriteControllers[ev.name].img.GetComponent <Image>().sprite.name,
                            NoCollision = ev.gameObject.layer == 0,
                            Anchor      = UnitaleUtil.VectorToVect(ev.GetComponent <RectTransform>().anchorMax),
                            Pivot       = UnitaleUtil.VectorToVect(ev.GetComponent <RectTransform>().pivot)
                        };
                        GlobalControls.EventData.Add(ev.name, ei);
                    } catch { /* ignored */ }
                }
            }

            if (EventManager.instance.eventScripts.ContainsKey(go))
            {
                if (EventManager.instance.coroutines.ContainsKey(EventManager.instance.eventScripts[go]))
                {
                    EventManager.instance.coroutines.Remove(EventManager.instance.eventScripts[go]);
                }
                EventManager.instance.eventScripts.Remove(go);
            }
            EventManager.instance.spriteControllers.Remove(eventName);
            EventManager.instance.events.Remove(go);
            if (go.transform.parent != null)
            {
                if (go.transform.parent.name == "SpritePivot")
                {
                    go = go.transform.parent.gameObject;
                }
            }
            Object.Destroy(go); //NEED PARENTAL REMOVE
        }
        if (appliedScript != null && (EventManager.instance.ScriptRunning || EventManager.instance.coroutines.ContainsKey(appliedScript)))
        {
            appliedScript.Call("CYFEventNextCommand");
        }
    }