Example #1
0
 // Grab the first position
 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);
     CatchPos bp = new CatchPos();
     bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
     p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
 }
Example #2
0
        public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type)
        {
            p.ClearBlockchange();
            byte b = p.level.GetTile(x, y, z); //get the tile type of first set and set that to byte b

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

            bp.x           = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
        }
Example #3
0
        // Grab the first position
        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);
            CatchPos bp = new CatchPos();

            bp.x           = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
        }
Example #4
0
        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.CuboidLimit && p.group.CuboidLimit != 0)
            {
                p.SendMessage("You're trying to replace " + buffer.Count.ToString() + " blocks.");
                p.SendMessage("Your block limit is " + p.group.CuboidLimit.ToString() + " blocks. Replace in stages.");
                return;
            }


            p.SendMessage(buffer.Count.ToString() + " blocks.");
            buffer.ForEach(delegate(Pos pos)
            {
                p.level.Blockchange(p, pos.x, pos.y, pos.z, cpos.type2);                  //update block for everyone
            });
        }
Example #5
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            // Clear previously ignored blocks
            for (int i = 0; i < ignoreList.Length - 1; i++)
            {
                ignoreList[i] = 255;
            }
            int      counter = 0;
            CatchPos cpos    = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }

            cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            if (message != "")
            {
                // Here we can use the same principle as searching through opMats.
                // This function ignores op_material for security reasons.
                // This function also ignores any non-doorifiable block (ie: air, water, lava...etc)
                message = message.ToLower();
                message = " " + message;  // Add the whitespace back to work with the ignore list code below

                for (int i = 0; i < opMats.doorBlocks.Length; i++)
                {
                    if ((message.Contains(" " + Block.Name(opMats.doorBlocks[i]))) || (message.Contains(" " + Block.Name(opMats.regBlocks[i]))))
                    {
                        ignoreList[counter] = opMats.doorBlocks[i];
                        counter            += 1;
                        if (counter > ignoreList.Length - 1)
                        {
                            break;
                        }
                    }
                }
                if (message.Contains("all"))
                {   // User used "all"
                    Blockchange2(p, p.level.width, p.level.depth, p.level.height, type);
                    return;
                }
            }

            p.SendMessage("Place two blocks to determine the edges.");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
Example #6
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            // Clear previously ignored blocks
            for (int i = 0; i < ignoreList.Length - 1; i++)
            {
                ignoreList[i] = 255;
            }
            CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }

            cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            int counter = 0;

            if (message != "")
            {
                message = message.ToLower();
                message = " " + message;
                for (int i = 0; i < opMats.doorBlocks.Length; i++)
                {
                    if ((message.Contains(" " + Block.Name(opMats.doorBlocks[i]))) || (message.Contains(" " + Block.Name(opMats.regBlocks[i]))))
                    {
                        ignoreList[counter] = opMats.doorBlocks[i];
                        counter            += 1;
                        if (counter > ignoreList.Length - 2) // -2 because of air
                        {
                            break;
                        }
                    }
                }
                if (message.Contains("all"))
                {   // User used "all"
                    Blockchange2(p, p.level.width, p.level.depth, p.level.height, type);
                    return;
                }
            }
            // Code will only be reached if message doesn't contain "all"
            p.SendMessage("Place two blocks to determine the edges.");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
Example #7
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            // Clear previously ignored blocks
            for (int i = 0; i < ignoreList.Length - 1; i++)
            {
                ignoreList[i] = 255;
            }
            int counter = 0;
            CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }
            cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            if (message != "")
            {
                // Here we can use the same principle as searching through opMats.
                // This function ignores op_material for security reasons.
                // This function also ignores any non-doorifiable block (ie: air, water, lava...etc)
                message = message.ToLower();
                message = " " + message;  // Add the whitespace back to work with the ignore list code below

                for (int i = 0; i < opMats.doorBlocks.Length; i++)
                {
                    if ((message.Contains(" " + Block.Name(opMats.doorBlocks[i]))) || (message.Contains(" " + Block.Name(opMats.regBlocks[i]))))
                    {
                        ignoreList[counter] = opMats.doorBlocks[i];
                        counter += 1;
                        if (counter > ignoreList.Length - 1)
                        {
                            break;
                        }
                    }
                }
            } // Not allowing user to use "all" because turning a map into door_material would be pointless
              // User can still manually do it by placing blocks.
            p.SendMessage("Place two blocks to determine the edges.");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
Example #8
0
 // Code to run when used by a player
 public override void Use(Player p, string message)
 {
     // Clear previously ignored blocks
     for (int i = 0; i < ignoreList.Length - 1; i++)
     {
         ignoreList[i] = 255;
     }
     int counter = 0;
     CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }
     cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     if (message != "")
     {
         message = message.ToLower();
         message = " " + message;
         for (int i = 0; i < opMats.opBlocks.Length; i++)
         {
             if ((message.Contains(" " + Block.Name(opMats.opBlocks[i]))) || (message.Contains(" " + Block.Name(opMats.regBlocks[i]))))
             {
                 ignoreList[counter] = opMats.opBlocks[i];
                 counter += 1;
                 if (counter > ignoreList.Length - 1)
                 {
                     break;
                 }
             }
         }
         if (message.Contains("all"))   // Add spaces before an after?  Block might contain "all" in the future
         {   // User used "all"
             Blockchange2(p, p.level.width, p.level.depth, p.level.height, type);
             return;
         }
     }
     // Code will only be reached if user message doesn't contain "all"
     p.SendMessage("Place two blocks to determine the edges.");
     p.ClearBlockchange();
     p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
 }
Example #9
0
 // Code to run when used by a player
 public override void Use(Player p, string message)
 {
     int number = message.Split(' ').Length;
     if (number > 2) { Help(p); return; }
     if (number == 2)
     {
         int pos = message.IndexOf(' ');
         string t = message.Substring(0, pos).ToLower();
         string s = message.Substring(pos + 1).ToLower();
         byte type = Block.Byte(t);
         if (type == 255) { p.SendMessage("There is no block \"" + t + "\"."); return; }
         SolidType solid;
         if (s == "solid") { solid = SolidType.solid; }
         else if (s == "hollow") { solid = SolidType.hollow; }
         else { Help(p); return; }
         CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
         cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     }
     else if (message != "")
     {
         SolidType solid = SolidType.solid;
         message = message.ToLower();
         byte type; unchecked { type = (byte)-1; }
         if (message == "solid") { solid = SolidType.solid; }
         else if (message == "hollow") { solid = SolidType.hollow; }
         else
         {
             byte t = Block.Byte(message);
             if (t == 255) { p.SendMessage("There is no block \"" + t + "\"."); return; }
             type = t;
         } CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
         cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     }
     else
     {
         CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }
         cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     }
     p.SendMessage("Place two blocks to determine the edges.");
     p.ClearBlockchange();
     p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
 }
Example #10
0
        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>();

            switch (cpos.solid)
            {
            case SolidType.solid:
                if (!Server.operators.Contains(p.name))
                {
                    int attemptedLimit = (Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z));
                    if (attemptedLimit > p.group.CuboidLimit && p.group.CuboidLimit != 0)     //OPERATOR door LIMIT, same as cuboid
                    {
                        p.SendMessage("You're trying to convert " + attemptedLimit + " blocks.");
                        p.SendMessage("Your block limit is " + p.group.CuboidLimit.ToString() + " blocks. Build in stages.");
                        return;
                    }
                }
                buffer.Capacity = Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z);
                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);     //}
                        }
                    }
                }
                break;
            }

            p.SendMessage("Converting " + buffer.Count.ToString() + " blocks to reg_material");

            // Disable physics before changing the blocks
            Physics physicsSetting = p.level.Physics;
            p.level.Physics = Physics.Off;
            p.level.ClearPhysics();
            // Because we are calling ClearPhysics() we do not need to account for doorair_material. These materials will be
            // converted back into door_material automatically.

            buffer.ForEach(delegate(Pos pos)
            {
                byte bl    = p.level.GetTile(pos.x, pos.y, pos.z);              //Get the block that is there at the moment
                byte newbl = Block.convertDoor(bl);
                if (newbl != bl)                                                // if the block is doorifiable
                {
                    if (opMats.doorBlocks.Contains(bl))                         // if the block is a door
                    {
                        if (!ignoreList.Contains(bl))                           // if the block is not being ignored   bl should be a door at this point
                        {
                            p.level.Blockchange(p, pos.x, pos.y, pos.z, newbl); // send converted reg_material
                        }
                    }
                }
            });

            p.level.Physics = physicsSetting;
            p.SendMessage("Conversion complete.");
        }
Example #11
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            int number = message.Split(' ').Length;

            if (number > 2)
            {
                Help(p); return;
            }
            // example, /cuboid op_white walls
            if (number == 2)
            {
                int    pos  = message.IndexOf(' ');
                string t    = message.Substring(0, pos).ToLower();
                string s    = message.Substring(pos + 1).ToLower();
                byte   type = Block.Byte(t);
                if (type == 255)
                {
                    p.SendMessage("There is no block \"" + t + "\"."); return;
                }
                if (Server.advbuilders.Contains(p.name))
                {
                    if (!Block.Placable(type) && !Block.AdvPlacable(type))
                    {
                        p.SendMessage("Your not allowed to place that."); return;
                    }
                }
                SolidType solid;
                if (s == "solid")
                {
                    solid = SolidType.solid;
                }
                else if (s == "hollow")
                {
                    solid = SolidType.hollow;
                }
                else if (s == "walls")
                {
                    solid = SolidType.walls;
                }
                else
                {
                    Help(p); return;
                }
                CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
                cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            }
            // Example, /cuboid op_white
            // Example, /cuboid walls
            else if (message != "")
            {
                SolidType solid = SolidType.solid;
                message = message.ToLower();
                byte type; unchecked { type = (byte)-1; }
                if (message == "solid")
                {
                    solid = SolidType.solid;
                }
                else if (message == "hollow")
                {
                    solid = SolidType.hollow;
                }
                else if (message == "walls")
                {
                    solid = SolidType.walls;
                }
                else
                {
                    byte t = Block.Byte(message);
                    if (t == 255)
                    {
                        p.SendMessage("There is no block \"" + message + "\"."); return;
                    }
                    if (p.Rank == GroupEnum.AdvBuilder)
                    {
                        if (!Block.Placable(t) && !Block.AdvPlacable(t))
                        {
                            p.SendMessage("Your not allowed to place that."); return;
                        }
                    }
                    type = t;
                } CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
                cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            }
            // Example, /cuboid
            // Take currently held block
            else
            {
                CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }
                cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            }
            p.SendMessage("Place two blocks to determine the edges.");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
Example #12
0
        // Second block change (defining second corner)
        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>();

            // Solid is default
            switch (cpos.solid)
            {
            case SolidType.solid:

                // redundant?
                if (Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z) > p.group.CuboidLimit && p.group.CuboidLimit != 0)
                {
                    p.SendMessage("You're trying to place " + buffer.Count.ToString() + " blocks.");
                    p.SendMessage("Your block limit is " + p.group.CuboidLimit.ToString() + " blocks. Build in stages.");
                    return;
                }
                // end redundant?

                buffer.Capacity = Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z);

                // Nested for loops to cover a solid cube
                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);
                            }
                        }
                    }
                }
                break;

            case SolidType.hollow:
                // TODO: Work out if theres 800 blocks used before making the buffer

                // Hollow will build only the outer shell of a cube leaving the center alone
                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(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 (ushort xx = (ushort)(Math.Min(cpos.x, x) + 1); xx <= Math.Max(cpos.x, x) - 1; ++xx)
                    {
                        for (ushort 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 (ushort xx = (ushort)(Math.Min(cpos.x, x) + 1); xx <= Math.Max(cpos.x, x) - 1; ++xx)
                        {
                            for (ushort 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;

            // Walls builds only the surrounding vertical borders of a cube
            case SolidType.walls:
                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(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 (ushort xx = (ushort)(Math.Min(cpos.x, x) + 1); xx <= Math.Max(cpos.x, x) - 1; ++xx)
                        {
                            for (ushort 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;
            }

            // Why are we running this in the solid case statement as well?
            if (buffer.Count > p.group.CuboidLimit && p.group.CuboidLimit != 0)
            {
                p.SendMessage("You're trying to place " + buffer.Count.ToString() + " blocks.");
                p.SendMessage("Your block limit is " + p.group.CuboidLimit.ToString() + " blocks. Build in stages.");
                return;
            }


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


            // This code may not be needed. We already check whether the player can place the block near the top of this class
            if (!Server.advbuilders.Contains(p.name))
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    p.level.Blockchange(p, pos.x, pos.y, pos.z, type);                  //update block for everyone
                });
            }
            else
            {
                buffer.ForEach(delegate(Pos pos)
                {
                    byte bl = p.level.GetTile(pos.x, pos.y, pos.z);
                    if (Block.Placable(bl) || Block.AdvPlacable(bl))
                    {
                        p.level.Blockchange(p, pos.x, pos.y, pos.z, type);
                    }                                                                                                                        //update block for everyone
                });
            }
            // end possibly not needed code
        }
Example #13
0
 // Code to run when used by a player
 public override void Use(Player p, string message)
 {
     int number = message.Split(' ').Length;
     if (number > 2) { Help(p); return; }
     // example, /cuboid op_white walls
     if (number == 2)
     {
         int pos = message.IndexOf(' ');
         string t = message.Substring(0, pos).ToLower();
         string s = message.Substring(pos + 1).ToLower();
         byte type = Block.Byte(t);
         if (type == 255) { p.SendMessage("There is no block \"" + t + "\"."); return; }
         if (Server.advbuilders.Contains(p.name))
         {
             if (!Block.Placable(type) && !Block.AdvPlacable(type)) { p.SendMessage("Your not allowed to place that."); return; }
         }
         SolidType solid;
         if (s == "solid") { solid = SolidType.solid; }
         else if (s == "hollow") { solid = SolidType.hollow; }
         else if (s == "walls") { solid = SolidType.walls; }
         else { Help(p); return; }
         CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
         cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     }
     // Example, /cuboid op_white
     // Example, /cuboid walls
     else if (message != "")
     {
         SolidType solid = SolidType.solid;
         message = message.ToLower();
         byte type; unchecked { type = (byte) -1; }
         if (message == "solid") { solid = SolidType.solid; }
         else if (message == "hollow") { solid = SolidType.hollow; }
         else if (message == "walls") { solid = SolidType.walls; }
         else
         {
             byte t = Block.Byte(message);
             if (t == 255) { p.SendMessage("There is no block \"" + message + "\"."); return; }
             if (p.Rank == GroupEnum.AdvBuilder)
             {
                 if (!Block.Placable(t) && !Block.AdvPlacable(t)) { p.SendMessage("Your not allowed to place that."); return; }
             }
             type = t;
         } CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
         cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     }
     // Example, /cuboid
     // Take currently held block
     else
     {
         CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte) -1; }
         cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
     }
     p.SendMessage("Place two blocks to determine the edges.");
     p.ClearBlockchange();
     p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
 }
Example #14
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            int number = message.Split(' ').Length;

            if (number > 2)
            {
                Help(p); return;
            }
            if (number == 2)
            {
                int    pos  = message.IndexOf(' ');
                string t    = message.Substring(0, pos).ToLower();
                string s    = message.Substring(pos + 1).ToLower();
                byte   type = Block.Byte(t);
                if (type == 255)
                {
                    p.SendMessage("There is no block \"" + t + "\"."); return;
                }
                SolidType solid;
                if (s == "solid")
                {
                    solid = SolidType.solid;
                }
                else if (s == "hollow")
                {
                    solid = SolidType.hollow;
                }
                else
                {
                    Help(p); return;
                }
                CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
                cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            }
            else if (message != "")
            {
                SolidType solid = SolidType.solid;
                message = message.ToLower();
                byte type; unchecked { type = (byte)-1; }
                if (message == "solid")
                {
                    solid = SolidType.solid;
                }
                else if (message == "hollow")
                {
                    solid = SolidType.hollow;
                }
                else
                {
                    byte t = Block.Byte(message);
                    if (t == 255)
                    {
                        p.SendMessage("There is no block \"" + t + "\"."); return;
                    }
                    type = t;
                } CatchPos cpos = new CatchPos(); cpos.solid = solid; cpos.type = type;
                cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            }
            else
            {
                CatchPos cpos = new CatchPos(); cpos.solid = SolidType.solid; unchecked { cpos.type = (byte)-1; }
                cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            }
            p.SendMessage("Place two blocks to determine the edges.");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
Example #15
0
        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>();

            if (Math.Abs(x - cpos.x) != Math.Abs(z - cpos.z))
            {
                p.SendMessage("No good, make it a circle."); return;
            }

            float CenX = Middle(x, cpos.x);
            float CenZ = Middle(z, cpos.z);
            float Rad  = Math.Abs(CenX - (float)x);

            if (Rad != (int)Rad)
            {
                p.SendMessage("No good, try a diferent radius."); return;
            }
            switch (cpos.solid)
            {
            case SolidType.solid:
                //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 != type) { BufferAdd(buffer, xx, yy, zz); }


                float error = -Rad;
                float varx  = Rad;
                float varz  = 0;

                p.SendMessage("Radius " + Rad.ToString());

                while (varx >= varz)
                {
                    for (ushort yy = (ushort)(Math.Min(cpos.y, y)); yy <= Math.Max(cpos.y, y); ++yy)
                    {
                        BufferAdd(buffer, (ushort)(CenX + varx), yy, (ushort)(CenZ + varz));
                        BufferAdd(buffer, (ushort)(CenX - varx), yy, (ushort)(CenZ + varz));
                        BufferAdd(buffer, (ushort)(CenX + varx), yy, (ushort)(CenZ - varz));
                        BufferAdd(buffer, (ushort)(CenX - varx), yy, (ushort)(CenZ - varz));

                        BufferAdd(buffer, (ushort)(CenX + varz), yy, (ushort)(CenZ + varx));
                        BufferAdd(buffer, (ushort)(CenX - varz), yy, (ushort)(CenZ + varx));
                        BufferAdd(buffer, (ushort)(CenX + varz), yy, (ushort)(CenZ - varx));
                        BufferAdd(buffer, (ushort)(CenX - varz), yy, (ushort)(CenZ - varx));
                    }

                    error += varz;
                    ++varz;
                    error += varz;

                    // The following test may be implemented in assembly language in
                    // most machines by testing the carry flag after adding 'y' to
                    // the value of 'error' in the previous step, since 'error'
                    // nominally has a negative value.
                    if (error >= 0)
                    {
                        --varx;
                        error -= varx;
                        error -= varx;
                    }
                }


                break;

            case SolidType.hollow:
                p.SendMessage("Not implemented yet.");
                return;
            }

            if (!Server.operators.Contains(p.name))
            {
                if (buffer.Count > 800)
                {
                    p.SendMessage("Too many blocks, build in stages.");
                    return;
                }
            }
            else if (buffer.Count > 20000)
            {
                p.SendMessage("That is a bad idea.");
                return;
            }

            p.SendMessage(buffer.Count.ToString() + " blocks.");
            buffer.ForEach(delegate(Pos pos)
            {
                p.level.Blockchange(p, pos.x, pos.y, pos.z, type);                  //update block for everyone
            });
        }
Example #16
0
        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>();

            switch (cpos.solid)
            {
            case SolidType.solid:
                if (!Server.operators.Contains(p.name))
                {
                    int attemptedLimit = (Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z));
                    if (attemptedLimit > p.group.CuboidLimit && p.group.CuboidLimit != 0)     //OPERATOR Lock LIMIT, same as cuboid
                    {
                        p.SendMessage("You're trying to lock " + attemptedLimit + " blocks.");
                        p.SendMessage("Your block limit is " + p.group.CuboidLimit.ToString() + " blocks. Build in stages.");
                        return;
                    }
                }
                buffer.Capacity = Math.Abs(cpos.x - x) * Math.Abs(cpos.y - y) * Math.Abs(cpos.z - z);
                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);     //}
                        }
                    }
                }
                break;
            }

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

            // Disable physics before changing the blocks
            Physics physicsSetting = p.level.Physics;
            p.level.Physics = Physics.Off;
            p.level.ClearPhysics();

            buffer.ForEach(delegate(Pos pos)
            {
                byte bl = p.level.GetTile(pos.x, pos.y, pos.z);                                 //Get the block that is there at the moment
                if (!opMats.opBlocks.Contains(bl))                                              // if the block is not op_material
                {
                    if (!ignoreList.Contains((byte)Block.convertOp(bl)))                        // if the block is not being ignored
                    {
                        p.level.Blockchange(p, pos.x, pos.y, pos.z, (byte)Block.convertOp(bl)); // send converted reg_material
                    }
                }
            });

            p.level.Physics = physicsSetting;
            p.SendMessage("Locking complete.");
        }
Example #17
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            int number = message.Split(' ').Length;
            if (number != 2) { Help(p); return; }

            int pos = message.IndexOf(' ');
            string t = message.Substring(0, pos).ToLower();
            string t2 = message.Substring(pos + 1).ToLower();
            byte type = Block.Byte(t);
            if (type == 255) { p.SendMessage("There is no block \"" + t + "\"."); return; }
            byte type2 = Block.Byte(t2);
            if (type2 == 255) { p.SendMessage("There is no block \"" + t2 + "\"."); return; }

            CatchPos cpos = new CatchPos(); cpos.type2 = type2; cpos.type = type;
            cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
            p.SendMessage("Place two blocks to determine the edges.");
            p.ClearBlockchange();
            p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
        }
Example #18
0
        // Get the second position
        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;
                        }
            }

            byte[,,] blockBuffer;

            ushort lowX = Math.Min(cpos.x, x);
            ushort lowY = Math.Min(cpos.y, y);
            ushort lowZ = Math.Min(cpos.z, z);

            ushort highX = Math.Max(cpos.x, x);
            ushort highY = Math.Max(cpos.y, y);
            ushort highZ = Math.Max(cpos.z, z);


            ushort dimX = (ushort)Math.Abs(cpos.x - x);
            ushort dimY = (ushort)Math.Abs(cpos.y - y);
            ushort dimZ = (ushort)Math.Abs(cpos.z - z);

            dimX++;
            dimY++;
            dimZ++;

            Map copyLevel = p.level;

            // Now that we have the positions, check the size
            // If it's too big, cancel
            if (dimX * dimY * dimZ <= p.group.CuboidLimit || p.group.CuboidLimit == 0)
            {
                try
                {
                    // Resize the buffer
                    blockBuffer = new byte[highX - lowX + 1, highY - lowY + 1, highZ - lowZ + 1];

                    // Let the player know we're copying blocks now
                    p.SendMessage("Copying " + blockBuffer.Length + " blocks.");


                    // Add the tiles to a temporary buffer
                    for (ushort xx = lowX; xx <= highX; ++xx)
                    {
                        for (ushort yy = lowY; yy <= highY; ++yy)
                        {
                            for (ushort zz = lowZ; zz <= highZ; ++zz)
                            {
                                blockBuffer[xx - lowX, yy - lowY, zz - lowZ] = copyLevel.GetTile(xx, yy, zz);
                            }
                        }
                    }
                    // Replace the players buffer
                    p.copyBuffer.SetBuffer(blockBuffer, dimX, dimY, dimZ);
                    p.SendMessage("The block copy was successful!");
                }
                catch (Exception e)
                {
                    Logger.Log("Error copying blocks for " + p.name, LogType.Error);
                    Logger.Log(e.Message, LogType.ErrorMessage);
                    p.SendMessage("There was an error doing /copy!");
                }
            }
            else
            {
                p.SendMessage("You're trying to copy " + dimX * dimY * dimZ + " blocks.");
                p.SendMessage("Your block limit is " + p.group.CuboidLimit.ToString() + " blocks. Copy in stages.");
            }
        }