public static void FlyMove(Player p, short[] oldPos, byte[] oldRot, short[] newPos, byte[] newRot) { if (p.flyBlocks == null) { p.flyBlocks = new List<Block>(); } if (Math.Abs((newPos[0] >> 5) - p.lastFlyPos[0]) >= 1 || Math.Abs((newPos[2] >> 5) - p.lastFlyPos[2]) >= 1 || Math.Abs(p.lastFlyPos[1] - ((newPos[1] >> 5) - 2)) >= 1) { int oy = (p.lastFlyPos[1] < p.world.height ? p.lastFlyPos[1] : p.world.height - 1); int ny = ((newPos[1] >> 5) - 2 < p.world.height ? (newPos[1] >> 5) - 2 : p.world.height - 1); List<Block> newPlatform = new List<Block>(); for (int x = ((newPos[0] >> 5) - 3); x < ((newPos[0] >> 5) + 3); x++) { for (int z = ((newPos[2] >> 5) - 3); z < ((newPos[2] >> 5) + 3); z++) { newPlatform.Add(new Block((short)x, (short)ny, (short)z, Blocks.glass)); } } List<Block> pNewBlocks = new List<Block>(p.flyBlocks); foreach (Block b in p.flyBlocks) { if (!newPlatform.Contains(b)) { pNewBlocks.Remove(b); p.SendBlock(b.x, b.y, b.z, p.world.GetTile(b.x, b.y, b.z)); } } foreach (Block b in newPlatform) { if (!pNewBlocks.Contains(b)) { pNewBlocks.Add(b); p.SendBlock(b.x, b.y, b.z, Blocks.glass); } } p.flyBlocks = pNewBlocks; /*for (int x = p.lastFlyPos[0] - 3; x < p.lastFlyPos[0] + 3; x++) { for (int z = p.lastFlyPos[2] - 3; z < p.lastFlyPos[2] + 3; z++) { p.SendBlock((short)x, (short)oy, (short)z, p.world.GetTile(x, oy, z)); } } */ p.lastFlyPos = new int[] { newPos[0] >> 5, (newPos[1] >> 5) - 2, newPos[2] >> 5 }; } }
public static void BlockRemoved(Player p, int x, int y, int z, byte type) { p.SendBlock((short)x, (short)y, (short)z, p.world.GetTile(x, y, z)); p.world.messageBlocks.Remove(p.world.CoordsToIndex((short)x, (short)y, (short)z)); p.world.Save(); p.SendMessage(0xFF, "Message block deleted"); p.OnBlockchange -= new Player.BlockHandler(BlockRemoved); }
public static void Fly(Player p, string message) { if (!p.flying) { p.SendMessage(0xFF, "Fly mode is now &aenabled"); p.flying = true; p.OnMovement += new Player.PositionChangeHandler(FlyMove); } else { p.SendMessage(0xFF, "Fly mode is now &cdisabled"); p.flying = false; p.OnMovement -= new Player.PositionChangeHandler(FlyMove); foreach(Block b in p.flyBlocks) { p.SendBlock(b.x, b.y, b.z, p.world.GetTile(b.x, b.y, b.z)); } } }
public static void OnSecond(Player p, int x, int y, int z, byte type) { p.SendBlock((short)x, (short)y, (short)z, p.world.GetTile(x, y, z)); p.cParams.cuboidLock = true; int x1 = p.cParams.x1, y1 = p.cParams.y1, z1 = p.cParams.z1; int xMin = Math.Min(x1, x); int yMin = Math.Min(y1, y); int zMin = Math.Min(z1, z); int xMax = Math.Max(x1, x); int yMax = Math.Max(y1, y); int zMax = Math.Max(z1, z); if (((xMax + 1 - xMin) * (yMax + 1 - yMin) * (zMax + 1 - zMin)) > 100000 && p.rank < Rank.RankLevel("operator")) { p.SendMessage(0xFF, "You can't copy something that large!"); return; } p.copyClipboard = new Block[(xMax + 1 - xMin) * (yMax + 1 - yMin) * (zMax + 1 - zMin)]; for (int nx = xMin; nx <= xMax; nx++) { for (int ny = yMin; ny <= yMax; ny++) { for (int nz = zMin; nz <= zMax; nz++) { p.copyClipboard[((ny - yMin) * (zMax + 1 - zMin) + (nz - zMin)) * (xMax + 1 - xMin) + (nx - xMin)] = new Block((short)(nx - xMin), (short)(ny - yMin), (short)(nz - zMin), p.world.GetTile(nx, ny, nz)); } } } p.SendMessage(0xFF, "Copied &c" + ((xMax + 1 - xMin) * (yMax + 1 - yMin) * (zMax + 1 - zMin)) + "&e blocks"); p.OnBlockchange -= new Player.BlockHandler(OnSecond); p.cParams.cuboidLock = false; }
public static void OnPasteChat(Player p, string msg) { if (msg.Trim().ToLower().Equals("finalize")) { p.cParams.cuboidLock = true; foreach (Block b in p.copyClipboard) { p.world.SetTile(b.x + p.cParams.x1, b.y + p.cParams.y1, b.z + p.cParams.z1, b.type); if (b.type == Blocks.air) Program.server.accounts[p.username.ToLower()].blocksDestroyed++; else Program.server.accounts[p.username.ToLower()].blocksCreated++; } p.cParams.cuboidLock = false; p.OnChat -= new Player.ChatHandler(OnPasteChat); p.OnBlockchange -= new Player.BlockHandler(OnPasteBlockchange); p.SendMessage(0xFF, "Pasted."); } else if (msg.Trim().ToLower().Equals("cancel")) { if (p.cParams.x1 != -1 && p.cParams.y1 != -1 && p.cParams.z1 != -1) { foreach (Block b in p.copyClipboard) { p.SendBlock((short)(b.x + p.cParams.x1), (short)(b.y + p.cParams.y1), (short)(b.z + p.cParams.z1), p.world.GetTile(b.x + p.cParams.x1, b.y + p.cParams.y1, b.z + p.cParams.z1)); } } p.OnChat -= new Player.ChatHandler(OnPasteChat); p.OnBlockchange -= new Player.BlockHandler(OnPasteBlockchange); p.SendMessage(0xFF, "Canceled."); } else if (msg.Trim().ToLower().Equals("rotate")) { Rotate90(p, ""); } }
public static void OnPasteBlockchange(Player p, int x, int y, int z, byte type) { if (p.cParams.x1 != -1 && p.cParams.y1 != -1 && p.cParams.z1 != -1) { foreach (Block b in p.copyClipboard) { p.SendBlock((short)(b.x + p.cParams.x1), (short)(b.y + p.cParams.y1), (short)(b.z + p.cParams.z1), p.world.GetTile(b.x + p.cParams.x1, b.y + p.cParams.y1, b.z + p.cParams.z1)); } } else { p.SendMessage(0xFF, "Type \"finalize\" to finish the paste, \"cancel\" to cancel it, or \"rotate\" to rotate it."); p.OnChat += new Player.ChatHandler(OnPasteChat); } p.cParams.x1 = x; p.cParams.y1 = y; p.cParams.z1 = z; foreach (Block b in p.copyClipboard) { byte bType = Blocks.glass; if (b.type == Blocks.air) bType = Blocks.air; if (b.type == Blocks.water || b.type == Blocks.waterstill) bType = Blocks.waterstill; if (b.type == Blocks.lava || b.type == Blocks.lavastill) bType = Blocks.lavastill; p.SendBlock((short)(b.x + x), (short)(b.y + y), (short)(b.z + z), bType); } }
public static void OnFirst(Player p, int x, int y, int z, byte type) { p.SendBlock((short)x, (short)y, (short)z, p.world.GetTile(x, y, z)); p.cParams.x1 = x; p.cParams.y1 = y; p.cParams.z1 = z; p.OnBlockchange -= new Player.BlockHandler(OnFirst); p.OnBlockchange += new Player.BlockHandler(OnSecond); p.SendMessage(0xFF, "Change the block at the second corner"); }
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 NoBuildMode(Player p, int x, int y, int z, byte type) { p.SendBlock((short)x, (short)y, (short)z, p.world.GetTile(x, y, z)); }
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 LinePointOneHandler(Player p, int x, int y, int z, byte type) { byte t = type; if (p.sArgs.type == 0xFF) p.sArgs.type = t; p.sArgs.vertices = new int[3] { x, y, z }; p.SendBlock((short)x, (short)y, (short)z, p.world.GetTile(x, y, z)); p.OnBlockchange -= new Player.BlockHandler(LinePointOneHandler); p.OnBlockchange += new Player.BlockHandler(LinePointTwoHandler); }
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); }