Ejemplo n.º 1
0
        public static Task AsyncGenerateRandStatues(short amount)
        {
            WorldRefill.isTaskRunning = true;
            int realcount = 0;

            return(Task.Run(() =>
            {
                for (int trycount = 0; trycount < WorldRefill.config.GenerationMaxTries; trycount++)
                {
                    int tryX = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
                    int tryY = WorldGen.genRand.Next((int)Main.rockLayer, Main.UnderworldLayer);
                    int tryType = WorldGen.genRand.Next(0, WorldGen.statueList.Count() - 1);
                    Point16 randstatue = WorldGen.statueList[tryType];



                    if (!WorldRefill.IsProtected(tryX, tryY))
                    {
                        while (!TileValidation.StatueTileValidation(tryX, tryY))
                        {
                            tryY++;
                            if (tryY >= Main.UnderworldLayer)
                            {
                                break;
                            }
                        }

                        if (tryY < Main.UnderworldLayer && (!TileValidation.isinNonNaturalStatuePlace(Main.tile[tryX, tryY + 1].type)))
                        {
                            WorldGen.PlaceTile(tryX, tryY, randstatue.X, true, true, -1, randstatue.Y);

                            if (Main.tile[tryX, tryY].type == randstatue.X)
                            {
                                realcount++;
                                if (realcount == amount)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                WorldRefill.realcount = realcount;
            }).ContinueWith((d) => FinishGen()));
        }
Ejemplo n.º 2
0
        public static Task AsyncGenerateShrooms(short amount, int maxtries = Config.GenerationMaxTries)
        {
            WorldRefill.isTaskRunning = true;
            int realcount = 0;

            return(Task.Run(() =>
            {
                TryInitWorldGen();
                for (int trycount = 0; trycount <= maxtries; trycount++)
                {
                    int tryX = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                    int tryY = WorldGen.genRand.Next((int)Main.worldSurface - 150, MainExt.UnderworldLayer);

                    ITile blockbelow = Main.tile[tryX, tryY + 1];
                    List <ushort> shroom = TileValidation.GetShroom(blockbelow);

                    while (shroom == null)
                    {
                        tryY--;
                        blockbelow = Main.tile[tryX, tryY + 1];
                        shroom = TileValidation.GetShroom(blockbelow);
                        if (tryY < Main.worldSurface - 50)
                        {
                            break;
                        }
                    }
                    if (shroom != null && !Main.tile[tryX, tryY].active())
                    {
                        WorldGen.PlaceTile(tryX, tryY, shroom[0], false, true, -1, shroom[1]);
                        Main.tile[tryX, tryY].frameX = (short)shroom[2];
                        if (Main.tile[tryX, tryY].type == shroom[0])
                        {
                            realcount++;
                            if (realcount == amount)
                            {
                                break;
                            }
                        }
                    }
                }
                WorldRefill.realcount = realcount;
            }).ContinueWith((d) => { WorldRefill.isTaskRunning = false; }));
        }
Ejemplo n.º 3
0
        public static Task AsyncGenerateStatues(short amount, short tileid = 0, short style = 0, int maxtries = Config.GenerationMaxTries)
        {
            WorldRefill.isTaskRunning = true;
            int realcount = 0;

            return(Task.Run(() =>
            {
                TryInitWorldGen();
                for (int trycount = 0; trycount <= maxtries; trycount++)
                {
                    int tryX = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
                    int tryY = WorldGen.genRand.Next((int)Main.rockLayer, MainExt.UnderworldLayer);
                    int tryType = WorldGen.genRand.Next(0, WorldGen.statueList.Count() - 1);

                    while (!TileValidation.StatueTileValidation(tryX, tryY))
                    {
                        tryY++;
                        if (tryY >= MainExt.UnderworldLayer)
                        {
                            break;
                        }
                    }

                    if (tryY < MainExt.UnderworldLayer && (!TileValidation.isinNonNaturalStatuePlace(Main.tile[tryX, tryY + 1].type)))
                    {
                        WorldGen.PlaceTile(tryX, tryY, tileid, true, true, -1, style);

                        if (Main.tile[tryX, tryY].type == tileid)
                        {
                            realcount++;
                            if (realcount == amount)
                            {
                                break;
                            }
                        }
                    }
                }
                WorldRefill.realcount = realcount;
            }).ContinueWith((d) => { WorldRefill.isTaskRunning = false; }));
        }
Ejemplo n.º 4
0
        public static Task AsyncGenerateOres(short amount, ushort oreID, List <ushort[]> oreTiers, int maxtries = Config.GenerationMaxTries)
        {
            WorldRefill.isTaskRunning = true;
            int realcount = 0;
            int oreTier;
            int minFrequency;
            int maxFrequency;
            int minSpread;
            int maxSpread;

            //oreGened = track amount of ores generated already
            double maxY;
            double minY = Main.worldSurface + 50;

            //Rare Ores  - Adamantite (Titanium), Demonite, Diamond, Chlorophyte
            return(Task.Run(() =>
            {
                oreTier = TileValidation.GetOreTier(oreID, oreTiers);

                switch (oreTier)
                {
                case 1:
                    maxY = Main.rockLayer;
                    minY = Main.worldSurface;
                    minFrequency = 5;
                    minSpread = 5;
                    maxFrequency = 8;
                    maxSpread = 8;

                    break;

                case 2:
                    maxY = Main.rockLayer * 3 / 2;
                    minY = Main.rockLayer;
                    minFrequency = 4;
                    minSpread = 4;
                    maxFrequency = 6;
                    maxSpread = 6;
                    break;

                case 3:
                    maxY = MainExt.UnderworldLayer;
                    minY = (3 / 2) * Main.rockLayer;
                    minFrequency = 2;
                    minSpread = 2;
                    maxFrequency = 4;
                    maxSpread = 4;
                    break;

                case 4:
                    maxY = Main.maxTilesY - 1;
                    minY = MainExt.UnderworldLayer + 20;
                    minFrequency = 4;
                    minSpread = 4;
                    maxFrequency = 9;
                    maxSpread = 9;
                    break;

                case 5:
                    minY = Main.rockLayer;
                    maxY = Main.rockLayer * (3 / 2);
                    minFrequency = 5;
                    minSpread = 5;
                    maxFrequency = 9;
                    maxSpread = 9;
                    break;

                case 6:
                    minY = Main.rockLayer * (3 / 2);
                    maxY = MainExt.UnderworldLayer;
                    minFrequency = 4;
                    minSpread = 4;
                    maxFrequency = 7;
                    maxSpread = 7;
                    break;

                case 7:
                    minY = Main.rockLayer * (5 / 3);
                    maxY = MainExt.UnderworldLayer;
                    minFrequency = 3;
                    minSpread = 3;
                    maxFrequency = 5;
                    maxSpread = 5;
                    break;

                case 8:
                    minY = Main.rockLayer;
                    maxY = MainExt.UnderworldLayer;
                    minFrequency = 5;
                    minSpread = 5;
                    maxFrequency = 9;
                    maxSpread = 9;
                    break;

                default:
                    maxY = Main.rockLayer;
                    minFrequency = 5;
                    minSpread = 5;
                    maxFrequency = 9;
                    maxSpread = 9;
                    break;
                }
                for (int trycount = 0; trycount <= maxtries; trycount++)
                {
                    //Get random number from 100 tiles each side
                    int X = WorldGen.genRand.Next(100, Main.maxTilesX - 100);
                    //Gets random number based on minimum spawn point to maximum depth of map
                    int Y = WorldGen.genRand.Next((int)minY, (int)maxY);

                    if (TileValidation.TileOreValidation(Main.tile[X, Y], oreID))
                    {
                        WorldGen.OreRunner(X, Y, (double)WorldGen.genRand.Next(minSpread, maxSpread), WorldGen.genRand.Next(minFrequency, maxFrequency), oreID);
                        if (Main.tile[X, Y].type == oreID)
                        {
                            realcount++;
                            if (realcount == amount)
                            {
                                break;
                            }
                        }
                    }
                }
                WorldRefill.realcount = realcount;
            }).ContinueWith((d) => { WorldRefill.isTaskRunning = false; }));
        }
Ejemplo n.º 5
0
        public static Task AsyncGenerateRandOres(short amount, List <ushort[]> oreTiers, Dictionary <string, ushort> ores, int maxtries = Config.GenerationMaxTries)
        {
            WorldRefill.isTaskRunning = true;
            int           realcount = 0;
            int           oreTier;
            int           minFrequency;
            int           maxFrequency;
            int           minSpread;
            int           maxSpread;
            List <ushort> totalores = ores.Values.ToList <ushort>();

            return(Task.Run(() =>
            {
                TryInitWorldGen();
                for (int trycount = 0; trycount <= maxtries; trycount++)
                {
                    int X = WorldGen.genRand.Next(100, Main.maxTilesX - 100);

                    double maxY;
                    double minY = Main.worldSurface - 20;
                    var trytype = WorldGen.genRand.Next(0, totalores.Count - 1);

                    ushort oreID = totalores[trytype];
                    if (WorldGen.crimson && oreID == TileID.Demonite)
                    {
                        oreID = TileID.Crimtane;                                               //If randomly generated ore, make the ore world specific.
                    }
                    else if (!WorldGen.crimson && oreID == TileID.Crimtane)
                    {
                        oreID = TileID.Demonite;
                    }

                    oreTier = TileValidation.GetOreTier(oreID, oreTiers);

                    switch (oreTier)
                    {
                    case 1:
                        maxY = Main.rockLayer;
                        minY = Main.worldSurface;
                        minFrequency = 5;
                        minSpread = 5;
                        maxFrequency = 8;
                        maxSpread = 8;

                        break;

                    case 2:
                        maxY = Main.rockLayer * 3 / 2;
                        minY = Main.rockLayer;
                        minFrequency = 4;
                        minSpread = 4;
                        maxFrequency = 6;
                        maxSpread = 6;
                        break;

                    case 3:
                        maxY = MainExt.UnderworldLayer;
                        minY = (3 / 2) * Main.rockLayer;
                        minFrequency = 2;
                        minSpread = 2;
                        maxFrequency = 4;
                        maxSpread = 4;
                        break;

                    case 4:
                        maxY = Main.maxTilesY - 1;
                        minY = MainExt.UnderworldLayer + 20;
                        minFrequency = 4;
                        minSpread = 4;
                        maxFrequency = 9;
                        maxSpread = 9;
                        break;


                    case 5:
                        minY = Main.rockLayer;
                        maxY = Main.rockLayer * (3 / 2);
                        minFrequency = 5;
                        minSpread = 5;
                        maxFrequency = 9;
                        maxSpread = 9;
                        break;

                    case 6:
                        minY = Main.rockLayer * (3 / 2);
                        maxY = MainExt.UnderworldLayer;
                        minFrequency = 4;
                        minSpread = 4;
                        maxFrequency = 7;
                        maxSpread = 7;
                        break;

                    case 7:
                        minY = Main.rockLayer * (5 / 3);
                        maxY = MainExt.UnderworldLayer;
                        minFrequency = 3;
                        minSpread = 3;
                        maxFrequency = 5;
                        maxSpread = 5;
                        break;

                    case 8:
                        minY = Main.rockLayer;
                        maxY = MainExt.UnderworldLayer;
                        minFrequency = 5;
                        minSpread = 5;
                        maxFrequency = 9;
                        maxSpread = 9;
                        break;

                    default:
                        maxY = Main.rockLayer;
                        minFrequency = 5;
                        minSpread = 5;
                        maxFrequency = 9;
                        maxSpread = 9;
                        break;
                    }

                    //Gets random number based on minimum spawn point to maximum depth of map
                    int Y = WorldGen.genRand.Next((int)minY, (int)maxY);

                    if (TileValidation.TileOreValidation(Main.tile[X, Y], oreID))
                    {
                        WorldGen.OreRunner(X, Y, (double)WorldGen.genRand.Next(minSpread, maxSpread), WorldGen.genRand.Next(minFrequency, maxFrequency), oreID);



                        if (Main.tile[X, Y].type == oreID)
                        {
                            realcount++;
                            if (realcount == amount)
                            {
                                break;
                            }
                        }
                    }
                }
                WorldRefill.realcount = realcount;
            }).ContinueWith((d) => { WorldRefill.isTaskRunning = false; }));
        }