public static void OnSecondCorner(Player p, int x2, int y2, int z2, byte type) { p.OnBlockchange -= new Player.BlockHandler(OnSecondCorner); p.cuboiding = false; p.SendBlock((short)x2, (short)y2, (short)z2, p.world.GetTile(x2, y2, z2)); int x1 = p.cParams.x1, y1 = p.cParams.y1, z1 = p.cParams.z1; p.cParams.cuboidLock = true; int xMin = Math.Min(x1, x2); int yMin = Math.Min(y1, y2); int zMin = Math.Min(z1, z2); int xMax = Math.Max(x1, x2); int yMax = Math.Max(y1, y2); int zMax = Math.Max(z1, z2); int size = (xMax + 1 - xMin) * (yMax + 1 - yMin) * (zMax + 1 - zMin); if (size > 20000 && p.rank <= Rank.RankLevel("operator")) { p.SendMessage(0xFF, "You can't make a cuboid that large!"); p.cParams.cuboidLock = false; return; } p.SendMessage(0xFF, "Cuboiding &c" + size + "&e blocks"); System.Threading.Thread cuboidThread = new System.Threading.Thread((System.Threading.ThreadStart)delegate { DateTime start = DateTime.Now; World cWorld = p.world; Account user = Program.server.accounts[p.username.ToLower()]; for (int nx = xMin; nx <= xMax; nx++) { for (int ny = yMin; ny <= yMax; ny++) { for (int nz = zMin; nz <= zMax; nz++) { if (!p.cParams.replace && !p.cParams.replacenot) { if (cWorld.GetTile(nx, ny, nz) != p.cParams.type) { p.AuthenticateAndSetBlock(nx, ny, nz, p.cParams.type); System.Threading.Thread.Sleep(1); } } else if (p.cParams.replace) { if (cWorld.GetTile(nx, ny, nz) == p.cParams.replaceType) { p.AuthenticateAndSetBlock(nx, ny, nz, p.cParams.type); System.Threading.Thread.Sleep(1); } } else if (p.cParams.replacenot) { if (cWorld.GetTile(nx, ny, nz) != p.cParams.replaceType) { p.AuthenticateAndSetBlock(nx, ny, nz, p.cParams.type); System.Threading.Thread.Sleep(1); } } } } } double time = ((TimeSpan)(DateTime.Now - start)).TotalSeconds; p.SendMessage(0x00, "&c" + size + "&e blocks in &c" + (int)(time * 10.0) / 10.0 + "&e seconds"); p.SendMessage(0xFF, "(&c" + (int)((size / time)*10.0) / 10.0 + "&e blocks/sec)"); p.cParams.cuboidLock = false; }); cuboidThread.Start(); DrawThreadManager.cuboid_threads.Add(p, cuboidThread); }
public static void DrawSphere(Player p, int x, int y, int z, byte type) { short radius = p.sArgs.radius; Thread drawThread = new Thread((ThreadStart)delegate { World dWorld = p.world; Account user = Program.server.accounts[p.username.ToLower()]; for (int nx = x - radius; nx < x + radius + 1; nx++) { for (int nz = z - radius; nz < z + radius + 1; nz++) { for (int ny = y - radius; ny < y + radius + 1; ny++) { if (dWorld.GetTile(nx, ny, nz) != type) { if ((Math.Pow((x - nx), 2) + Math.Pow((z - nz), 2) + Math.Pow((y - ny), 2)) <= Math.Pow(radius, 2)) { if ((Math.Pow((x - nx), 2) + Math.Pow((z - nz), 2) + Math.Pow((y - ny), 2)) <= Math.Pow((radius - 1), 2) && !p.sArgs.solid) { p.AuthenticateAndSetBlock(nx, ny, nz, Blocks.air); Thread.Sleep(1); } else { p.AuthenticateAndSetBlock(nx, ny, nz, type); Thread.Sleep(1); } } } } } } if (!p.sArgs.solid) p.SendBlock((short)x, (short)y, (short)z, Blocks.air); p.sArgs.shapeLock = false; p.SendMessage(0xFF, "Drawing Complete."); }); drawThread.Start(); DrawThreadManager.shape_threads.Add(p, drawThread); }
public static void DrawCircle(Player p, int x, int y, int z, byte type) { /*int xo = p.sArgs.vertices[0], yo = p.sArgs.vertices[1], zo = p.sArgs.vertices[2]; int dx = x - xo, dz = z - zo; short radius = (short)Math.Sqrt(dx * dx + dz * dz); int dy = y - yo, y_low = Math.Min(y, yo); float m_y = (float)dy / (4 * radius * (radius + 1) + 1); float ny = (float)y_low; float ang = (float)Math.Atan((double)dz / dx); bool outer_loop = false; if (dx > dz) outer_loop = true;*/ short radius = p.sArgs.radius; Thread drawThread = new Thread((ThreadStart)delegate { World dWorld = p.world; Account user = Program.server.accounts[p.username.ToLower()]; /*for (int nx = xo - radius; nx < xo + radius + 1; nx++) { for (int nz = zo - radius; nz < zo + radius + 1; nz++) { if (dWorld.GetTile(nx, (int)ny, nz) != type) { if ((Math.Pow((xo - nx), 2) + Math.Pow((zo - nz), 2)) <= radius * radius) { if ((Math.Pow((xo - nx), 2) + Math.Pow((zo - nz), 2)) <= (radius - 1) * (radius - 1) && !p.sArgs.solid) { p.AuthenticateAndSetBlock(nx, (int)ny, nz, Blocks.air); Thread.Sleep(1); } else { p.AuthenticateAndSetBlock(nx, (int)ny, nz, type); Thread.Sleep(1); } } } if (Math.Abs(Math.Atan((double)(nz - zo) / (double)(nx - xo)) - ang) < 2) ny += m_y; } }*/ for (int nx = x - radius; nx < x + radius + 1; nx++) { for (int nz = z - radius; nz < z + radius + 1; nz++) { if (dWorld.GetTile(nx, y, nz) != type) { if ((Math.Pow((x - nx), 2) + Math.Pow((z - nz), 2)) <= radius * radius) { if ((Math.Pow((x - nx), 2) + Math.Pow((z - nz), 2)) <= (radius - 1) * (radius - 1) && !p.sArgs.solid) { p.AuthenticateAndSetBlock(nx, y, nz, Blocks.air); Thread.Sleep(1); } else { p.AuthenticateAndSetBlock(nx, y, nz, type); Thread.Sleep(1); } } } } } if (!p.sArgs.solid) p.SendBlock((short)x, (short)y, (short)z, Blocks.air); p.sArgs.shapeLock = false; p.SendMessage(0xFF, "Drawing Complete."); }); drawThread.Start(); DrawThreadManager.shape_threads.Add(p, drawThread); }
public static void DrawLine(Player p, int x1, int y1, int z1, int x2, int y2, int z2, byte type) { int dx = x2 - x1, dy = y2 - y1, dz = z2 - z1; int length = (int)Math.Sqrt(dx * dx + dy * dy + dz * dz); float m_x = (float)dx / length; float m_y = (float)dy / length; float m_z = (float)dz / length; Thread drawThread = new Thread((ThreadStart)delegate { int x = x1, y = y1, z = z1; for (int i = 0; i < length + 1; i++) { x = (int)Math.Round(i * m_x + x1); y = (int)Math.Round(i * m_y + y1); z = (int)Math.Round(i * m_z + z1); p.AuthenticateAndSetBlock(x, y, z, type); //Program.server.logger.log(x + ", " + y + ", " + z + ", " + type, Logger.LogType.Debug); } p.sArgs.shapeLock = false; p.SendMessage(0xFF, "Drawing complete."); }); drawThread.Start(); DrawThreadManager.shape_threads.Add(p, drawThread); }