public static Task AsyncGenerateOrbs(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(50, Main.maxTilesX - 50); int tryY = WorldGen.genRand.Next((int)Main.worldSurface + 20, MainExt.UnderworldLayer); if ((!Main.tile[tryX, tryY].active()) && ((Main.tile[tryX, tryY].wall == WallID.EbonstoneUnsafe) || (Main.tile[tryX, tryY].wall == WallID.CrimstoneUnsafe))) { WorldGen.AddShadowOrb(tryX, tryY); if (Main.tile[tryX, tryY].type == 31) { realcount++; if (realcount == amount) { break; } } } } WorldRefill.realcount = realcount; }).ContinueWith((d) => { WorldRefill.isTaskRunning = false; })); }
private void DoOrbs(CommandArgs args) { if (args.Parameters.Count == 1) { var mOrb = Int32.Parse(args.Parameters[0]); var surface = Main.worldSurface; var trycount = 0; const int maxtries = 1000000; var realcount = 0; while (trycount < maxtries) { var tryX = WorldGen.genRand.Next(1, Main.maxTilesX); var tryY = WorldGen.genRand.Next((int)surface + 20, Main.maxTilesY); if ((!Main.tile[tryX, tryY].active()) && ((Main.tile[tryX, tryY].wall == (byte)3) || (Main.tile[tryX, tryY].wall == (byte)83))) { WorldGen.AddShadowOrb(tryX, tryY); if (Main.tile[tryX, tryY].type == 31) { realcount++; if (realcount == mOrb) { break; } } } trycount++; } InformPlayers(); args.Player.SendSuccessMessage("Generated and hid {0} Orbs.", realcount); } else { args.Player.SendInfoMessage("Usage: /genorbs (number of orbs to generate)"); } }