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; })); }
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; })); }