public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            byte b = p.level.GetTile(x, y, z);

            p.SendBlockchange(x, y, z, b);
            CatchPos cpos = (CatchPos)p.blockchangeObject;

            unchecked { if (cpos.type != (byte)-1)
                        {
                            type = cpos.type;
                        }
            }
            List <Pos> buffer = new List <Pos>();

            for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
            {
                for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                {
                    for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                    {
                        if (p.level.GetTile(xx, yy, zz) == type)
                        {
                            BufferAdd(buffer, xx, yy, zz);
                        }
                    }
                }
            }

            if (buffer.Count > p.group.maxBlocks)
            {
                Player.SendMessage(p, "You tried to replace " + buffer.Count + " blocks.");
                Player.SendMessage(p, "You cannot replace more than " + p.group.maxBlocks + ".");
                wait = 1;
                return;
            }

            Player.SendMessage(p, buffer.Count.ToString() + " blocks.");

            if (p.level.bufferblocks && !p.level.Instant)
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    BlockQueue.Addblock(p, pos.x, pos.y, pos.z, cpos.type2);                  //update block for everyone
                });
            }
            else
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    p.level.Blockchange(p, pos.x, pos.y, pos.z, cpos.type2);                  //update block for everyone
                });
            }

            wait = 2;
            if (p.staticCommands)
            {
                p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
            }
        }
Exemple #2
0
 public override void Use(Player p, string message)
 {
     if (p != null)
     {
         p.ClearBlockchange();
         p.painting       = false;
         p.BlockAction    = 0;
         p.megaBoid       = false;
         p.cmdTimer       = false;
         p.staticCommands = false;
         p.deleteMode     = false;
         p.ZoneCheck      = false;
         p.modeType       = 0;
         p.aiming         = false;
         p.onTrain        = false;
         p.isFlying       = false;
         try
         {
             p.level.blockqueue.RemoveAll((BlockQueue.block b) => { if (b.p == p)
                                                                    {
                                                                        return(true);
                                                                    }
                                                                    return(false); });
         }
         finally { BlockQueue.resume(); }
         Player.SendMessage(p, "Every toggle or action was aborted.");
         return;
     }
     Player.SendMessage(p, "This command can only be used in-game!");
 }
Exemple #3
0
        public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            byte b = p.level.GetTile(x, y, z);

            p.SendBlockchange(x, y, z, b);

            Player.UndoPos Pos1;
            //p.UndoBuffer.Clear();
            if (p.level.bufferblocks && !p.level.Instant)
            {
                p.CopyBuffer.ForEach(delegate(Player.CopyPos pos)
                {
                    Pos1.x = (ushort)(Math.Abs(pos.x) + x);
                    Pos1.y = (ushort)(Math.Abs(pos.y) + y);
                    Pos1.z = (ushort)(Math.Abs(pos.z) + z);

                    if (pos.type != Block.air || p.copyAir)
                    {
                        unchecked { if (p.level.GetTile(Pos1.x, Pos1.y, Pos1.z) != Block.Zero)
                                    {
                                        BlockQueue.Addblock(p, (ushort)(Pos1.x + p.copyoffset[0]), (ushort)(Pos1.y + p.copyoffset[1]), (ushort)(Pos1.z + p.copyoffset[2]), pos.type);
                                    }
                        }
                    }
                });
            }
            else
            {
                p.CopyBuffer.ForEach(delegate(Player.CopyPos pos)
                {
                    Pos1.x = (ushort)(Math.Abs(pos.x) + x);
                    Pos1.y = (ushort)(Math.Abs(pos.y) + y);
                    Pos1.z = (ushort)(Math.Abs(pos.z) + z);

                    if (pos.type != Block.air || p.copyAir)
                    {
                        unchecked { if (p.level.GetTile(Pos1.x, Pos1.y, Pos1.z) != Block.Zero)
                                    {
                                        p.level.Blockchange(p, (ushort)(Pos1.x + p.copyoffset[0]), (ushort)(Pos1.y + p.copyoffset[1]), (ushort)(Pos1.z + p.copyoffset[2]), pos.type);
                                    }
                        }
                    }
                });
            }

            Player.SendMessage(p, "Pasted " + p.CopyBuffer.Count + " blocks.");

            if (p.staticCommands)
            {
                p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
            }
        }
        public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            byte b = p.level.GetTile(x, y, z);

            p.SendBlockchange(x, y, z, b);
            CatchPos cpos = (CatchPos)p.blockchangeObject;

            unchecked { if (cpos.type != (byte)-1)
                        {
                            type = cpos.type;
                        }
                        else
                        {
                            type = p.bindings[type];
                        } }
            List <Pos> buffer = new List <Pos>();

            ushort xx; ushort yy; ushort zz;

            switch (cpos.solid)
            {
            case SolidType.solid:
                buffer.Capacity = Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z);
                for (xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                {
                    for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                    {
                        for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                        {
                            if (p.level.GetTile(xx, yy, zz) != type)
                            {
                                BufferAdd(buffer, xx, yy, zz);
                            }
                        }
                    }
                }
                break;

            case SolidType.hollow:
                //todo work out if theres 800 blocks used before making the buffer
                for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                {
                    for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                    {
                        if (p.level.GetTile(cpos.x, yy, zz) != type)
                        {
                            BufferAdd(buffer, cpos.x, yy, zz);
                        }
                        if (cpos.x != x)
                        {
                            if (p.level.GetTile(x, yy, zz) != type)
                            {
                                BufferAdd(buffer, x, yy, zz);
                            }
                        }
                    }
                }
                if (Math.Abs(cpos.x - x) >= 2)
                {
                    for (xx = (ushort)(Math.Min(cpos.x, x) + 1); xx <= Math.Max(cpos.x, x) - 1; ++xx)
                    {
                        for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                        {
                            if (p.level.GetTile(xx, cpos.y, zz) != type)
                            {
                                BufferAdd(buffer, xx, cpos.y, zz);
                            }
                            if (cpos.y != y)
                            {
                                if (p.level.GetTile(xx, y, zz) != type)
                                {
                                    BufferAdd(buffer, xx, y, zz);
                                }
                            }
                        }
                    }
                    if (Math.Abs(cpos.y - y) >= 2)
                    {
                        for (xx = (ushort)(Math.Min(cpos.x, x) + 1); xx <= Math.Max(cpos.x, x) - 1; ++xx)
                        {
                            for (yy = (ushort)(Math.Min(cpos.y, y) + 1); yy <= Math.Max(cpos.y, y) - 1; ++yy)
                            {
                                if (p.level.GetTile(xx, yy, cpos.z) != type)
                                {
                                    BufferAdd(buffer, xx, yy, cpos.z);
                                }
                                if (cpos.z != z)
                                {
                                    if (p.level.GetTile(xx, yy, z) != type)
                                    {
                                        BufferAdd(buffer, xx, yy, z);
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case SolidType.walls:
                for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                {
                    for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                    {
                        if (p.level.GetTile(cpos.x, yy, zz) != type)
                        {
                            BufferAdd(buffer, cpos.x, yy, zz);
                        }
                        if (cpos.x != x)
                        {
                            if (p.level.GetTile(x, yy, zz) != type)
                            {
                                BufferAdd(buffer, x, yy, zz);
                            }
                        }
                    }
                }
                if (Math.Abs(cpos.x - x) >= 2)
                {
                    if (Math.Abs(cpos.z - z) >= 2)
                    {
                        for (xx = (ushort)(Math.Min(cpos.x, x) + 1); xx <= Math.Max(cpos.x, x) - 1; ++xx)
                        {
                            for (yy = (ushort)(Math.Min(cpos.y, y)); yy <= Math.Max(cpos.y, y); ++yy)
                            {
                                if (p.level.GetTile(xx, yy, cpos.z) != type)
                                {
                                    BufferAdd(buffer, xx, yy, cpos.z);
                                }
                                if (cpos.z != z)
                                {
                                    if (p.level.GetTile(xx, yy, z) != type)
                                    {
                                        BufferAdd(buffer, xx, yy, z);
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case SolidType.holes:
                bool Checked = true, startZ, startY;

                for (xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                {
                    startY = Checked;
                    for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                    {
                        startZ = Checked;
                        for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                        {
                            Checked = !Checked;
                            if (Checked && p.level.GetTile(xx, yy, zz) != type)
                            {
                                BufferAdd(buffer, xx, yy, zz);
                            }
                        }
                        Checked = !startZ;
                    }
                    Checked = !startY;
                }
                break;

            case SolidType.wire:
                for (xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                {
                    BufferAdd(buffer, xx, y, z);
                    BufferAdd(buffer, xx, y, cpos.z);
                    BufferAdd(buffer, xx, cpos.y, z);
                    BufferAdd(buffer, xx, cpos.y, cpos.z);
                }
                for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                {
                    BufferAdd(buffer, x, yy, z);
                    BufferAdd(buffer, x, yy, cpos.z);
                    BufferAdd(buffer, cpos.x, yy, z);
                    BufferAdd(buffer, cpos.x, yy, cpos.z);
                }
                for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                {
                    BufferAdd(buffer, x, y, zz);
                    BufferAdd(buffer, x, cpos.y, zz);
                    BufferAdd(buffer, cpos.x, y, zz);
                    BufferAdd(buffer, cpos.x, cpos.y, zz);
                }
                break;

            case SolidType.random:
                Random rand = new Random();
                for (xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                {
                    for (yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                    {
                        for (zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                        {
                            if (rand.Next(1, 11) <= 5 && p.level.GetTile(xx, yy, zz) != type)
                            {
                                BufferAdd(buffer, xx, yy, zz);
                            }
                        }
                    }
                }
                break;
            }

            // Check to see if user is subject to anti-tunneling
            if (Server.antiTunnel && p.group.Permission == LevelPermission.Guest && !p.ignoreGrief)
            {
                int CheckForBlocksBelowY = p.level.depth / 2 - Server.maxDepth;
                if (buffer.Any(pos => pos.y < CheckForBlocksBelowY))
                {
                    p.SendMessage("You're not allowed to build this far down!");
                    return;
                }
            }

            if (Server.forceCuboid)
            {
                int counter = 1;
                buffer.ForEach(delegate(Pos pos)
                {
                    if (counter <= p.group.maxBlocks)
                    {
                        counter++;
                        p.level.Blockchange(p, pos.x, pos.y, pos.z, type);
                    }
                });
                if (counter >= p.group.maxBlocks)
                {
                    Player.SendMessage(p, "Tried to cuboid " + buffer.Count + " blocks, but your limit is " + p.group.maxBlocks + ".");
                    Player.SendMessage(p, "Executed cuboid up to limit.");

                    wait = 2;
                }
                else
                {
                    Player.SendMessage(p, buffer.Count.ToString() + " blocks.");
                }
                wait = 2;
                if (p.staticCommands)
                {
                    p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
                }
                return;
            }

            if (buffer.Count > p.group.maxBlocks)
            {
                Player.SendMessage(p, "You tried to cuboid " + buffer.Count + " blocks.");
                Player.SendMessage(p, "You cannot cuboid more than " + p.group.maxBlocks + ".");
                wait = 1;
                return;
            }

            if (p.pyramidsilent == false)
            {
                Player.SendMessage(p, buffer.Count.ToString() + " blocks.");
            }

            if (p.level.bufferblocks && !p.level.Instant)
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    BlockQueue.Addblock(p, pos.x, pos.y, pos.z, type);
                });
            }
            else
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    p.level.Blockchange(p, pos.x, pos.y, pos.z, type);
                });
            }

            wait = 2;
            if (p.staticCommands)
            {
                p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
            }
        }
        public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
        {
            try
            {
                p.ClearBlockchange();
                CatchPos cpos = (CatchPos)p.blockchangeObject;
                if (cpos.type == Block.Zero)
                {
                    cpos.type = p.bindings[type];
                }

                byte oldType = p.level.GetTile(x, y, z);
                p.SendBlockchange(x, y, z, oldType);

                if (cpos.type == oldType)
                {
                    Player.SendMessage(p, "Cannot fill with the same type."); return;
                }
                if (!Block.canPlace(p, oldType) && !Block.BuildIn(oldType))
                {
                    Player.SendMessage(p, "Cannot fill with that."); return;
                }

                byte[]     mapBlocks = new byte[p.level.blocks.Length];
                List <Pos> buffer    = new List <Pos>();
                p.level.blocks.CopyTo(mapBlocks, 0);

                fromWhere.Clear();
                deep = 0;
                FloodFill(p, x, y, z, cpos.type, oldType, cpos.fillType, ref mapBlocks, ref buffer);

                int totalFill = fromWhere.Count;
                for (int i = 0; i < totalFill; i++)
                {
                    totalFill = fromWhere.Count;
                    Pos pos = fromWhere[i];
                    deep = 0;
                    FloodFill(p, pos.x, pos.y, pos.z, cpos.type, oldType, cpos.fillType, ref mapBlocks, ref buffer);
                    totalFill = fromWhere.Count;
                }
                fromWhere.Clear();

                if (buffer.Count > p.group.maxBlocks)
                {
                    Player.SendMessage(p, "You tried to fill " + buffer.Count + " blocks.");
                    Player.SendMessage(p, "You cannot fill more than " + p.group.maxBlocks + ".");
                    return;
                }

                if (p.level.bufferblocks && !p.level.Instant)
                {
                    foreach (Pos pos in buffer)
                    {
                        BlockQueue.Addblock(p, pos.x, pos.y, pos.z, cpos.type);
                    }
                }
                else
                {
                    foreach (Pos pos in buffer)
                    {
                        p.level.Blockchange(p, pos.x, pos.y, pos.z, cpos.type);
                    }
                }

                Player.SendMessage(p, "Filled " + buffer.Count + " blocks.");
                buffer.Clear();
                buffer    = null;
                mapBlocks = null;

                if (p.staticCommands)
                {
                    p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
                }
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
            }
        }
        public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            p.SendBlockchange(x, y, z, p.level.GetTile(x, y, z));
            CatchPos   cpos = (CatchPos)p.blockchangeObject;
            FileStream fs   = File.OpenRead(@Server.backupLocation + "/" + p.level.name + "/" + cpos.backup + "/" + p.level.name + ".lvl");
            GZipStream gs   = new GZipStream(fs, CompressionMode.Decompress);

            byte[] ver = new byte[2];
            gs.Read(ver, 0, ver.Length);
            ushort version = BitConverter.ToUInt16(ver, 0);

            ushort[] vars = new ushort[6];
            try
            {
                if (version == 1874)
                {
                    byte[] header = new byte[16]; gs.Read(header, 0, header.Length);

                    vars[0] = BitConverter.ToUInt16(header, 0);
                    vars[1] = BitConverter.ToUInt16(header, 2);
                    vars[2] = BitConverter.ToUInt16(header, 4);
                }
                else
                {
                    byte[] header = new byte[12]; gs.Read(header, 0, header.Length);

                    vars[0] = version;
                    vars[1] = BitConverter.ToUInt16(header, 0);
                    vars[2] = BitConverter.ToUInt16(header, 2);
                }
                byte[] blocks = new byte[vars[0] * vars[2] * vars[1]];
                gs.Read(blocks, 0, blocks.Length);
                gs.Dispose();
                fs.Dispose();

                if (blocks.Length != p.level.blocks.Length)
                {
                    p.SendMessage("Cant restore selection of different size maps."); blocks = null; return;
                }

                if (p.level.bufferblocks && !p.level.Instant)
                {
                    for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                    {
                        for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                        {
                            for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                            {
                                BlockQueue.Addblock(p, xx, yy, zz, blocks[xx + (zz * vars[0]) + (yy * vars[0] * vars[1])]);
                            }
                        }
                    }
                }
                else
                {
                    for (ushort xx = Math.Min(cpos.x, x); xx <= Math.Max(cpos.x, x); ++xx)
                    {
                        for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); ++yy)
                        {
                            for (ushort zz = Math.Min(cpos.z, z); zz <= Math.Max(cpos.z, z); ++zz)
                            {
                                p.level.Blockchange(p, xx, yy, zz, blocks[xx + (zz * vars[0]) + (yy * vars[0] * vars[1])]);
                            }
                        }
                    }
                }

                blocks = null;
                if (p.staticCommands)
                {
                    p.Blockchange += Blockchange1;
                }
            }
            catch { Server.s.Log("Restore selection failed"); }
        }
        public override void Use(Player p, string message)
        {
            wait = 0;
            if (message.IndexOf(' ') == -1 || message.Split(' ').Length > 2)
            {
                Help(p); wait = 1; return;
            }

            byte b1, b2;

            b1 = Block.Byte(message.Split(' ')[0]);
            b2 = Block.Byte(message.Split(' ')[1]);

            if (b1 == Block.Zero || b2 == Block.Zero)
            {
                Player.SendMessage(p, "Could not find specified blocks."); wait = 1; return;
            }
            if (!Block.canPlace(p, b1) && !Block.BuildIn(b2))
            {
                Player.SendMessage(p, "Cannot replace that."); wait = 1; return;
            }
            if (!Block.canPlace(p, b2))
            {
                Player.SendMessage(p, "Cannot place that."); wait = 1; return;
            }
            ushort     x, y, z; int currentBlock = 0;
            List <Pos> stored = new List <Pos>(); Pos pos;

            foreach (byte b in p.level.blocks)
            {
                if (b == b1)
                {
                    p.level.IntToPos(currentBlock, out x, out y, out z);
                    pos.x = x; pos.y = y; pos.z = z;
                    stored.Add(pos);
                }
                currentBlock++;
            }

            if (stored.Count > (p.group.maxBlocks * 2))
            {
                Player.SendMessage(p, "Cannot replace more than " + (p.group.maxBlocks * 2) + " blocks."); wait = 1; return;
            }

            Player.SendMessage(p, stored.Count + " blocks out of " + currentBlock + " are " + Block.Name(b1));

            if (p.level.bufferblocks && !p.level.Instant)
            {
                foreach (Pos Pos in stored)
                {
                    BlockQueue.Addblock(p, Pos.x, Pos.y, Pos.z, b2);
                }
            }
            else
            {
                foreach (Pos Pos in stored)
                {
                    p.level.Blockchange(p, Pos.x, Pos.y, Pos.z, b2);
                }
            }

            Player.SendMessage(p, "&4/replaceall finished!");
            wait = 2;
        }