Пример #1
0
        static void WaterHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnWaterOn = (player.GetBind(Block.Aqua) != Block.Water ||
                                player.GetBind(Block.Cyan) != Block.Water ||
                                player.GetBind(Block.Blue) != Block.Water);

            if (cmd.HasNext && !cmd.NextOnOff(out turnWaterOn))
            {
                CdWater.PrintUsage(player);
                return;
            }

            if (turnWaterOn)
            {
                player.Bind(Block.Aqua, Block.Water);
                player.Bind(Block.Cyan, Block.Water);
                player.Bind(Block.Blue, Block.Water);
                player.Message("Water: ON. Blue blocks are replaced with water.");
            }
            else
            {
                player.ResetBind(Block.Aqua, Block.Cyan, Block.Blue);
                player.Message("Water: OFF");
            }
        }
Пример #2
0
        static void LavaHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnLavaOn = (player.GetBind(Block.Red) != Block.Lava);

            if (cmd.HasNext && !cmd.NextOnOff(out turnLavaOn))
            {
                CdLava.PrintUsage(player);
                return;
            }

            if (turnLavaOn)
            {
                player.Bind(Block.Red, Block.Lava);
                player.Message("Lava: ON. Red blocks are replaced with lava.");
            }
            else
            {
                player.ResetBind(Block.Red);
                player.Message("Lava: OFF");
            }
        }
Пример #3
0
        static void SolidHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnSolidOn = (player.GetBind(Block.Stone) != Block.Admincrete);

            if (cmd.HasNext && !cmd.NextOnOff(out turnSolidOn))
            {
                CdSolid.PrintUsage(player);
                return;
            }

            if (turnSolidOn)
            {
                player.Bind(Block.Stone, Block.Admincrete);
                player.Message("Solid: ON. Stone blocks are replaced with admincrete.");
            }
            else
            {
                player.ResetBind(Block.Stone);
                player.Message("Solid: OFF");
            }
        }
Пример #4
0
        static void GrassHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            bool turnGrassOn = (player.GetBind(Block.Dirt) != Block.Grass);

            if (cmd.HasNext && !cmd.NextOnOff(out turnGrassOn))
            {
                CdGrass.PrintUsage(player);
                return;
            }

            if (turnGrassOn)
            {
                player.Bind(Block.Dirt, Block.Grass);
                player.Message("Grass: ON. Dirt blocks are replaced with grass.");
            }
            else
            {
                player.ResetBind(Block.Dirt);
                player.Message("Grass: OFF");
            }
        }
Пример #5
0
        static void SolidHandler( Player player, CommandReader cmd ) {
            bool turnSolidOn = (player.GetBind( Block.Stone ) != Block.Admincrete);

            if( cmd.HasNext && !cmd.NextOnOff( out turnSolidOn ) ) {
                CdSolid.PrintUsage( player );
                return;
            }

            if( turnSolidOn ) {
                player.Bind( Block.Stone, Block.Admincrete );
                player.Message( "Solid: ON. Stone blocks are replaced with admincrete." );
            } else {
                player.ResetBind( Block.Stone );
                player.Message( "Solid: OFF" );
            }
        }
Пример #6
0
 static void LavaHandler( Player player, CommandReader cmd ) {
     if( player.GetBind( Block.Red ) == Block.Lava ) {
         player.ResetBind( Block.Red );
         player.Message( "Lava: OFF" );
     } else {
         player.Bind( Block.Red, Block.Lava );
         player.Message( "Lava: ON. Red blocks are replaced with lava." );
     }
 }
Пример #7
0
 static void WaterHandler( Player player, CommandReader cmd ) {
     if( player.GetBind( Block.Aqua ) == Block.Water ||
         player.GetBind( Block.Cyan ) == Block.Water ||
         player.GetBind( Block.Blue ) == Block.Water ) {
         player.ResetBind( Block.Aqua, Block.Cyan, Block.Blue );
         player.Message( "Water: OFF" );
     } else {
         player.Bind( Block.Aqua, Block.Water );
         player.Bind( Block.Cyan, Block.Water );
         player.Bind( Block.Blue, Block.Water );
         player.Message( "Water: ON. Blue blocks are replaced with water." );
     }
 }
Пример #8
0
 static void GrassHandler( Player player, CommandReader cmd ) {
     if( player.GetBind( Block.Dirt ) == Block.Grass ) {
         player.ResetBind( Block.Dirt );
         player.Message( "Grass: OFF" );
     } else {
         player.Bind( Block.Dirt, Block.Grass );
         player.Message( "Grass: ON. Dirt blocks are replaced with grass." );
     }
 }
Пример #9
0
 static void SolidHandler( Player player, CommandReader cmd ) {
     if( player.GetBind( Block.Stone ) == Block.Admincrete ) {
         player.ResetBind( Block.Stone );
         player.Message( "Solid: OFF" );
     } else {
         player.Bind( Block.Stone, Block.Admincrete );
         player.Message( "Solid: ON. Stone blocks are replaced with admincrete." );
     }
 }
Пример #10
0
        static void BindHandler( Player player, Command cmd )
        {
            string originalBlockName = cmd.Next();
            if( originalBlockName == null ) {
                player.Message( "All bindings have been reset." );
                player.ResetAllBinds();
                return;
            }
            Block originalBlock = Map.GetBlockByName( originalBlockName );
            if( originalBlock == Block.Undefined ) {
                player.Message( "Bind: Unrecognized block name: {0}", originalBlockName );
                return;
            }

            string replacementBlockName = cmd.Next();
            if( replacementBlockName == null ) {
                if( player.GetBind( originalBlock ) != originalBlock ) {
                    player.Message( "{0} is no longer bound to {1}",
                                    originalBlock,
                                    player.GetBind( originalBlock ) );
                    player.ResetBind( originalBlock );
                } else {
                    player.Message( "{0} is not bound to anything.",
                                    originalBlock );
                }
                return;
            }

            if( cmd.HasNext ) {
                CdBind.PrintUsage( player );
                return;
            }

            Block replacementBlock = Map.GetBlockByName( replacementBlockName );
            if( replacementBlock == Block.Undefined ) {
                player.Message( "Bind: Unrecognized block name: {0}", replacementBlockName );
            } else {
                Permission permission = Permission.Build;
                switch( replacementBlock ) {
                    case Block.Grass:
                        permission = Permission.PlaceGrass;
                        break;
                    case Block.Admincrete:
                        permission = Permission.PlaceAdmincrete;
                        break;
                    case Block.Water:
                        permission = Permission.PlaceWater;
                        break;
                    case Block.Lava:
                        permission = Permission.PlaceLava;
                        break;
                }
                if( player.Can( permission ) ) {
                    player.Bind( originalBlock, replacementBlock );
                    player.Message( "{0} is now replaced with {1}", originalBlock, replacementBlock );
                } else {
                    player.Message( "&WYou do not have {0} permission.", permission );
                }
            }
        }
Пример #11
0
        static void DoubleStairHandler(Player player, Command cmd)
        {
            if (player.GetBind(Block.Stair) == Block.DoubleStair)
            {
                player.ResetBind(Block.Stair);
                player.Message("DoubleStair: OFF");
            }

            else
            {
                player.Bind(Block.Stair, Block.DoubleStair);
                player.Message("DoubleStair: ON. Stair blocks are replaced with DoubleStairs.");
            }
        }
Пример #12
0
        /*
        internal static void EllipsoidHollowCallback( Player player, Position[] marks, object tag ) {
            byte drawBlock = (byte)tag;
            if( drawBlock == (byte)Block.Undefined ) {
                drawBlock = (byte)player.LastUsedBlockType;
            }

            // find start/end coordinates
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sh = Math.Min( marks[0].H, marks[1].H );
            int eh = Math.Max( marks[0].H, marks[1].H );

            // find axis lengths
            double rx = (ex - sx + 1) / 2d;
            double ry = (ey - sy + 1) / 2d;
            double rh = (eh - sh + 1) / 2d;

            double rx2 = 1 / (rx * rx);
            double ry2 = 1 / (ry * ry);
            double rh2 = 1 / (rh * rh);

            // find center points
            double cx = (ex + sx) / 2d;
            double cy = (ey + sy) / 2d;
            double ch = (eh + sh) / 2d;

            // rougher estimation than the non-hollow form, a voxelized surface is a bit funky
            int volume = (int)(4 / 3d * Math.PI * ((rx + .5) * (ry + .5) * (rh + .5) - (rx - .5) * (ry - .5) * (rh - .5)) * 0.85);
            if( !player.CanDraw( volume ) ) {
                player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                   player.Info.Rank.DrawLimit,
                                   volume );
                return;
            }

            player.UndoBuffer.Clear();

            int blocks = 0, blocksDenied = 0;
            bool cannotUndo = false;

            for( int x = sx; x <= ex; x++ ) {
                for( int y = sy; y <= ey; y++ ) {
                    for( int h = sh; h <= eh; h++ ) {

                        double dx = (x - cx);
                        double dy = (y - cy);
                        double dh = (h - ch);

                        if( (dx * dx) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 <= 1 ) {
                            // we touched the surface
                            // keep drilling until we hit an internal block
                            do {
                                DrawOneBlock( player, drawBlock, x, y, h, ref blocks, ref blocksDenied, ref cannotUndo );
                                DrawOneBlock( player, drawBlock, x, y, (int)(ch - dh), ref blocks, ref blocksDenied, ref cannotUndo );
                                dh = (++h - ch);
                            } while( h <= (int)ch &&
                                    ((dx + 1) * (dx + 1) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 > 1 ||
                                     (dx - 1) * (dx - 1) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 > 1 ||
                                     (dx * dx) * rx2 + (dy + 1) * (dy + 1) * ry2 + (dh * dh) * rh2 > 1 ||
                                     (dx * dx) * rx2 + (dy - 1) * (dy - 1) * ry2 + (dh * dh) * rh2 > 1 ||
                                     (dx * dx) * rx2 + (dy * dy) * ry2 + (dh + 1) * (dh + 1) * rh2 > 1 ||
                                     (dx * dx) * rx2 + (dy * dy) * ry2 + (dh - 1) * (dh - 1) * rh2 > 1) );
                            break;
                        }
                    }
                }
            }
            Logger.Log( "{0} drew a hollow ellipsoid containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
                        player.Name,
                        blocks,
                        (Block)drawBlock,
                        player.World.Name );
            DrawingFinished( player, "drawn", blocks, blocksDenied );
        }
        */

        internal static void EllipsoidHollowCallback( Player player, Position[] marks, object tag ) {

            HollowShapeArgs args = (HollowShapeArgs)tag;
            byte drawBlock = (byte)args.OuterBlock;
            if( drawBlock == (byte)Block.Undefined ) {
                drawBlock = (byte)player.GetBind( player.LastUsedBlockType );
            }

            // find start/end coordinates
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sh = Math.Min( marks[0].H, marks[1].H );
            int eh = Math.Max( marks[0].H, marks[1].H );

            bool fillInner = (args.InnerBlock != Block.Undefined && (ex - sx) > 1 && (ey - sy) > 1 && (eh - sh) > 1);

            // find axis lengths
            double rx = (ex - sx + 1) / 2d;
            double ry = (ey - sy + 1) / 2d;
            double rh = (eh - sh + 1) / 2d;

            double rx2 = 1 / (rx * rx);
            double ry2 = 1 / (ry * ry);
            double rh2 = 1 / (rh * rh);

            // find center points
            double cx = (ex + sx) / 2d;
            double cy = (ey + sy) / 2d;
            double ch = (eh + sh) / 2d;

            int volume;
            if( fillInner ) {
                volume = (int)(4 / 3d * Math.PI * rx * ry * rh);
            } else {
                // rougher estimation than the non-hollow form, a voxelized surface is a bit funky
                volume = (int)(4 / 3d * Math.PI * ((rx + .5) * (ry + .5) * (rh + .5) - (rx - .5) * (ry - .5) * (rh - .5)) * 0.85);
            }

            if( !player.CanDraw( volume ) ) {
                player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                   player.Info.Rank.DrawLimit,
                                   volume );
                return;
            }

            player.UndoBuffer.Clear();

            int blocks = 0, blocksDenied = 0;
            bool cannotUndo = false;

            for( int x = sx; x <= ex; x++ ) {
                for( int y = sy; y <= ey; y++ ) {
                    for( int h = sh; h <= eh; h++ ) {

                        double dx = (x - cx);
                        double dy = (y - cy);
                        double dh = (h - ch);

                        if( (dx * dx) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 > 1 ) continue;

                        // we touched the surface
                        // keep drilling until we hit an internal block
                        do {
                            DrawOneBlock( player, drawBlock, x, y, h, ref blocks, ref blocksDenied, ref cannotUndo );
                            DrawOneBlock( player, drawBlock, x, y, (int)(ch - dh), ref blocks, ref blocksDenied, ref cannotUndo );
                            dh = (++h - ch);
                        } while( h <= (int)ch &&
                                 ((dx + 1) * (dx + 1) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 > 1 ||
                                  (dx - 1) * (dx - 1) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 > 1 ||
                                  (dx * dx) * rx2 + (dy + 1) * (dy + 1) * ry2 + (dh * dh) * rh2 > 1 ||
                                  (dx * dx) * rx2 + (dy - 1) * (dy - 1) * ry2 + (dh * dh) * rh2 > 1 ||
                                  (dx * dx) * rx2 + (dy * dy) * ry2 + (dh + 1) * (dh + 1) * rh2 > 1 ||
                                  (dx * dx) * rx2 + (dy * dy) * ry2 + (dh - 1) * (dh - 1) * rh2 > 1)
                            );
                        if( fillInner ) {
                            for( ; h <= (int)(ch - dh); h++ ) {
                                DrawOneBlock( player, (byte)args.InnerBlock, x, y, h, ref blocks, ref blocksDenied, ref cannotUndo );
                            }
                        }
                        break;
                    }
                }
            }
            Logger.Log( "{0} drew a hollow ellipsoid containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
                        player.Name,
                        blocks,
                        (Block)drawBlock,
                        player.World.Name );
            DrawingFinished( player, "drawn", blocks, blocksDenied );
        }
Пример #13
0
        static void LavaHandler( Player player, CommandReader cmd ) {
            bool turnLavaOn = (player.GetBind( Block.Red ) != Block.Lava);

            if( cmd.HasNext && !cmd.NextOnOff( out turnLavaOn ) ) {
                CdLava.PrintUsage( player );
                return;
            }

            if( turnLavaOn ) {
                player.Bind( Block.Red, Block.Lava );
                player.Message( "Lava: ON. Red blocks are replaced with lava." );
            } else {
                player.ResetBind( Block.Red );
                player.Message( "Lava: OFF" );
            }
        }
Пример #14
0
        static void GrassHandler( Player player, CommandReader cmd ) {
            bool turnGrassOn = (player.GetBind( Block.Dirt ) != Block.Grass);

            if( cmd.HasNext && !cmd.NextOnOff( out turnGrassOn ) ) {
                CdGrass.PrintUsage( player );
                return;
            }

            if( turnGrassOn ) {
                player.Bind( Block.Dirt, Block.Grass );
                player.Message( "Grass: ON. Dirt blocks are replaced with grass." );
            } else {
                player.ResetBind( Block.Dirt );
                player.Message( "Grass: OFF" );
            }
        }
Пример #15
0
        internal static void LineCallback( Player player, Position[] marks, object tag ) {
            byte drawBlock = (byte)tag;
            if( drawBlock == (byte)Block.Undefined ) {
                drawBlock = (byte)player.GetBind( player.LastUsedBlockType );
            }

            player.UndoBuffer.Clear();

            int blocks = 0, blocksDenied = 0;
            bool cannotUndo = false;

            // LINE CODE

            int x1 = marks[0].X,
                y1 = marks[0].Y,
                z1 = marks[0].H,
                x2 = marks[1].X,
                y2 = marks[1].Y,
                z2 = marks[1].H;
            int i, err1, err2;
            int[] pixel = new int[3];
            pixel[0] = x1;
            pixel[1] = y1;
            pixel[2] = z1;
            int dx = x2 - x1;
            int dy = y2 - y1;
            int dz = z2 - z1;
            int xInc = (dx < 0) ? -1 : 1;
            int l = Math.Abs( dx );
            int yInc = (dy < 0) ? -1 : 1;
            int m = Math.Abs( dy );
            int zInc = (dz < 0) ? -1 : 1;
            int n = Math.Abs( dz );
            int dx2 = l << 1;
            int dy2 = m << 1;
            int dz2 = n << 1;

            DrawOneBlock( player, drawBlock, x2, y2, z2, ref blocks, ref blocksDenied, ref cannotUndo );

            if( (l >= m) && (l >= n) ) {

                err1 = dy2 - l;
                err2 = dz2 - l;
                for( i = 0; i < l; i++ ) {
                    DrawOneBlock( player, drawBlock, pixel[0], pixel[1], pixel[2], ref blocks, ref blocksDenied, ref cannotUndo );
                    if( err1 > 0 ) {
                        pixel[1] += yInc;
                        err1 -= dx2;
                    }
                    if( err2 > 0 ) {
                        pixel[2] += zInc;
                        err2 -= dx2;
                    }
                    err1 += dy2;
                    err2 += dz2;
                    pixel[0] += xInc;
                }
            } else if( (m >= l) && (m >= n) ) {
                err1 = dx2 - m;
                err2 = dz2 - m;
                for( i = 0; i < m; i++ ) {
                    DrawOneBlock( player, drawBlock, pixel[0], pixel[1], pixel[2], ref blocks, ref blocksDenied, ref cannotUndo );
                    if( err1 > 0 ) {
                        pixel[0] += xInc;
                        err1 -= dy2;
                    }
                    if( err2 > 0 ) {
                        pixel[2] += zInc;
                        err2 -= dy2;
                    }
                    err1 += dx2;
                    err2 += dz2;
                    pixel[1] += yInc;
                }
            } else {
                err1 = dy2 - n;
                err2 = dx2 - n;
                for( i = 0; i < n; i++ ) {
                    DrawOneBlock( player, drawBlock, pixel[0], pixel[1], pixel[2], ref blocks, ref blocksDenied, ref cannotUndo );
                    if( err1 > 0 ) {
                        pixel[1] += yInc;
                        err1 -= dz2;
                    }
                    if( err2 > 0 ) {
                        pixel[0] += xInc;
                        err2 -= dz2;
                    }
                    err1 += dy2;
                    err2 += dx2;
                    pixel[2] += zInc;
                }
            }

            // END LINE CODE
            Logger.Log( "{0} drew a line containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
                        player.Name,
                        blocks,
                        (Block)drawBlock,
                        player.World.Name );
            DrawingFinished( player, "drawn", blocks, blocksDenied );
        }
Пример #16
0
        static void CenterCallback(Player player, Vector3I[] marks, object tag)
        {
            if (player.LastUsedBlockType != Block.Undefined)
            {
                int sx = Math.Min(marks[0].X, marks[1].X), ex = Math.Max(marks[0].X, marks[1].X),
                sy = Math.Min(marks[0].Y, marks[1].Y), ey = Math.Max(marks[0].Y, marks[1].Y),
                sz = Math.Min(marks[0].Z, marks[1].Z), ez = Math.Max(marks[0].Z, marks[1].Z);

                BoundingBox bounds = new BoundingBox(sx, sy, sz, ex, ey, ez);
                Vector3I cPos = new Vector3I((bounds.XMin + bounds.XMax) / 2,
                    (bounds.YMin + bounds.YMax) / 2,
                    (bounds.ZMin + bounds.ZMax) / 2);
                int blocksDrawn = 0,
                blocksSkipped = 0;
                UndoState undoState = player.DrawBegin(null);

                World playerWorld = player.World;
                if (playerWorld == null) PlayerOpException.ThrowNoWorld(player);
                Map map = player.WorldMap;
                DrawOneBlock(player, player.World.Map, player.GetBind(player.LastUsedBlockType), cPos,
                          BlockChangeContext.Drawn,
                          ref blocksDrawn, ref blocksSkipped, undoState);
                DrawingFinished(player, "Placed", blocksDrawn, blocksSkipped);
            }else{
                player.Message("&WCannot deduce desired block. Click a block or type out the block name.");
            }
        }
Пример #17
0
        static void Place(Player player, Command cmd)
        {
            Block block;
            if (player.LastUsedBlockType == Block.Undefined)
            {
                block = Block.Stone;
            }
            else
            {
                block = player.LastUsedBlockType;
            }
            Vector3I Pos = new Vector3I(player.Position.X / 32, player.Position.Y / 32, (player.Position.Z / 32) - 2);

            if (player.CanPlace(player.World.Map, Pos, player.GetBind(block), BlockChangeContext.Manual) != CanPlaceResult.Allowed)
            {
                player.Message("&WYou are not allowed to build here");
                return;
            }

            Player.RaisePlayerPlacedBlockEvent(player, player.WorldMap, Pos, player.WorldMap.GetBlock(Pos), block, BlockChangeContext.Manual);
            BlockUpdate blockUpdate = new BlockUpdate(null, Pos, block);
            player.World.Map.QueueUpdate(blockUpdate);
            player.Message("Block placed below your feet");
        }
Пример #18
0
        internal static void CuboidWireframeCallback( Player player, Position[] marks, object tag ) {
            byte drawBlock = (byte)tag;
            if( drawBlock == (byte)Block.Undefined ) {
                drawBlock = (byte)player.GetBind( player.LastUsedBlockType );
            }

            // find start/end coordinates
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sh = Math.Min( marks[0].H, marks[1].H );
            int eh = Math.Max( marks[0].H, marks[1].H );

            // Calculate the upper limit on the volume
            int solidVolume = (ex - sx + 1) *  (ey - sy + 1) *  (eh - sh + 1);
            int hollowVolume = Math.Max( 0, ex - sx - 1 ) * Math.Max( 0, ey - sy - 1 ) * Math.Max( 0, eh - sh - 1 );
            int sideVolume = Math.Max( 0, ex - sx - 1 ) * Math.Max( 0, ey - sy - 1 ) * (ex != sx ? 2 : 1) +
                             Math.Max( 0, ey - sy - 1 ) * Math.Max( 0, eh - sh - 1 ) * (ey != sy ? 2 : 1) +
                             Math.Max( 0, eh - sh - 1 ) * Math.Max( 0, ex - sx - 1 ) * (eh != sh ? 2 : 1);
            int volume = solidVolume - hollowVolume - sideVolume;

            if( !player.CanDraw( volume ) ) {
                player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                   player.Info.Rank.DrawLimit,
                                   volume );
                return;
            }

            player.UndoBuffer.Clear();

            int blocks = 0, blocksDenied = 0;
            bool cannotUndo = false;

            // Draw cuboid vertices
            DrawOneBlock( player, drawBlock, sx, sy, sh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sx != ex ) DrawOneBlock( player, drawBlock, ex, sy, sh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sy != ey ) DrawOneBlock( player, drawBlock, sx, ey, sh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sx != ex && sy != ey ) DrawOneBlock( player, drawBlock, ex, ey, sh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sh != eh ) DrawOneBlock( player, drawBlock, sx, sy, eh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sx != ex && sh != eh ) DrawOneBlock( player, drawBlock, ex, sy, eh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sy != ey && sh != eh ) DrawOneBlock( player, drawBlock, sx, ey, eh, ref blocks, ref blocksDenied, ref cannotUndo );
            if( sx != ex && sy != ey && sh != eh ) DrawOneBlock( player, drawBlock, ex, ey, eh, ref blocks, ref blocksDenied, ref cannotUndo );

            // Draw edges along the X axis
            if( ex - sx > 1 ) {
                for( int x = sx + 1; x < ex; x++ ) {
                    DrawOneBlock( player, drawBlock, x, sy, sh, ref blocks, ref blocksDenied, ref cannotUndo );
                    if( sh != eh ) DrawOneBlock( player, drawBlock, x, sy, eh, ref blocks, ref blocksDenied, ref cannotUndo );
                    if( sy != ey ) {
                        DrawOneBlock( player, drawBlock, x, ey, sh, ref blocks, ref blocksDenied, ref cannotUndo );
                        if( sh != eh ) DrawOneBlock( player, drawBlock, x, ey, eh, ref blocks, ref blocksDenied, ref cannotUndo );
                    }
                }
            }

            // Draw edges along the Y axis
            if( ey - sy > 1 ) {
                for( int y = sy + 1; y < ey; y++ ) {
                    DrawOneBlock( player, drawBlock, sx, y, sh, ref blocks, ref blocksDenied, ref cannotUndo );
                    if( sh != eh ) DrawOneBlock( player, drawBlock, sx, y, eh, ref blocks, ref blocksDenied, ref cannotUndo );
                    if( sx != ex ) {
                        DrawOneBlock( player, drawBlock, ex, y, sh, ref blocks, ref blocksDenied, ref cannotUndo );
                        if( sh != eh ) DrawOneBlock( player, drawBlock, ex, y, eh, ref blocks, ref blocksDenied, ref cannotUndo );
                    }
                }
            }

            // Draw edges along the H axis
            if( eh - sh > 1 ) {
                for( int h = sh + 1; h < eh; h++ ) {
                    DrawOneBlock( player, drawBlock, sx, sy, h, ref blocks, ref blocksDenied, ref cannotUndo );
                    if( sy != ey ) DrawOneBlock( player, drawBlock, sx, ey, h, ref blocks, ref blocksDenied, ref cannotUndo );
                    if( sx != ex ) {
                        DrawOneBlock( player, drawBlock, ex, ey, h, ref blocks, ref blocksDenied, ref cannotUndo );
                        if( sy != ey ) DrawOneBlock( player, drawBlock, ex, sy, h, ref blocks, ref blocksDenied, ref cannotUndo );
                    }
                }
            }

            Logger.Log( "{0} drew a wireframe cuboid containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
                        player.Name,
                        blocks,
                        (Block)drawBlock,
                        player.World.Name );
            DrawingFinished( player, "drawn", blocks, blocksDenied );
        }
Пример #19
0
        internal static void CuboidHollowCallback( Player player, Position[] marks, object tag ) {
            HollowShapeArgs args = (HollowShapeArgs)tag;
            byte drawBlock = (byte)args.OuterBlock;
            if( drawBlock == (byte)Block.Undefined ) {
                drawBlock = (byte)player.GetBind( player.LastUsedBlockType );
            }

            // find start/end coordinates
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sh = Math.Min( marks[0].H, marks[1].H );
            int eh = Math.Max( marks[0].H, marks[1].H );

            bool fillInner = (args.InnerBlock != Block.Undefined && (ex - sx) > 1 && (ey - sy) > 1 && (eh - sh) > 1);


            int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
            if( !fillInner ) {
                volume -= (ex - sx - 1) * (ey - sy - 1) * (eh - sh - 1);
            }

            if( !player.CanDraw( volume ) ) {
                player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                   player.Info.Rank.DrawLimit,
                                   volume );
                return;
            }

            player.UndoBuffer.Clear();

            int blocks = 0, blocksDenied = 0;
            bool cannotUndo = false;

            for( int x = sx; x <= ex; x++ ) {
                for( int y = sy; y <= ey; y++ ) {
                    DrawOneBlock( player, drawBlock, x, y, sh, ref blocks, ref blocksDenied, ref cannotUndo );
                    DrawOneBlock( player, drawBlock, x, y, eh, ref blocks, ref blocksDenied, ref cannotUndo );
                }
            }
            for( int x = sx; x <= ex; x++ ) {
                for( int h = sh; h <= eh; h++ ) {
                    DrawOneBlock( player, drawBlock, x, sy, h, ref blocks, ref blocksDenied, ref cannotUndo );
                    DrawOneBlock( player, drawBlock, x, ey, h, ref blocks, ref blocksDenied, ref cannotUndo );
                }
            }
            for( int y = sy; y <= ey; y++ ) {
                for( int h = sh; h <= eh; h++ ) {
                    DrawOneBlock( player, drawBlock, sx, y, h, ref blocks, ref blocksDenied, ref cannotUndo );
                    DrawOneBlock( player, drawBlock, ex, y, h, ref blocks, ref blocksDenied, ref cannotUndo );
                }
            }

            if( fillInner ) {
                for( int x = sx + 1; x < ex; x += DrawStride ) {
                    for( int y = sy + 1; y < ey; y += DrawStride ) {
                        for( int h = sh + 1; h < eh; h++ ) {
                            for( int y3 = 0; y3 < DrawStride && y + y3 < ey; y3++ ) {
                                for( int x3 = 0; x3 < DrawStride && x + x3 < ex; x3++ ) {
                                    DrawOneBlock( player, (byte)args.InnerBlock, x + x3, y + y3, h, ref blocks, ref blocksDenied, ref cannotUndo );
                                }
                            }
                        }
                    }
                }
            }

            Logger.Log( "{0} drew a hollow cuboid containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
                        player.Name,
                        blocks,
                        (Block)drawBlock,
                        player.World.Name );
            DrawingFinished( player, "drawn", blocks, blocksDenied );
        }
Пример #20
0
        static void WaterHandler( Player player, CommandReader cmd ) {
            bool turnWaterOn = (player.GetBind( Block.Aqua ) != Block.Water ||
                                player.GetBind( Block.Cyan ) != Block.Water ||
                                player.GetBind( Block.Blue ) != Block.Water);

            if( cmd.HasNext && !cmd.NextOnOff( out turnWaterOn ) ) {
                CdWater.PrintUsage( player );
                return;
            }

            if( turnWaterOn ) {
                player.Bind( Block.Aqua, Block.Water );
                player.Bind( Block.Cyan, Block.Water );
                player.Bind( Block.Blue, Block.Water );
                player.Message( "Water: ON. Blue blocks are replaced with water." );
            } else {
                player.ResetBind( Block.Aqua, Block.Cyan, Block.Blue );
                player.Message( "Water: OFF" );
            }
        }
Пример #21
0
        static void BindHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            if (!cmd.HasNext)
            {
                player.Message("All bindings have been reset.");
                player.ResetAllBinds();
                return;
            }

            Block originalBlock;

            if (!cmd.NextBlock(player, false, out originalBlock))
            {
                return;
            }

            if (!cmd.HasNext)
            {
                if (player.GetBind(originalBlock) != originalBlock)
                {
                    player.Message("{0} is no longer bound to {1}",
                                   originalBlock,
                                   player.GetBind(originalBlock));
                    player.ResetBind(originalBlock);
                }
                else
                {
                    player.Message("{0} is not bound to anything.",
                                   originalBlock);
                }
                return;
            }

            Block replacementBlock;

            if (!cmd.NextBlock(player, false, out replacementBlock))
            {
                return;
            }

            if (cmd.HasNext)
            {
                CdBind.PrintUsage(player);
                return;
            }

            Permission permission = Permission.Build;

            switch (replacementBlock)
            {
            case Block.Grass:
                permission = Permission.PlaceGrass;
                break;

            case Block.Admincrete:
                permission = Permission.PlaceAdmincrete;
                break;

            case Block.Water:
                permission = Permission.PlaceWater;
                break;

            case Block.Lava:
                permission = Permission.PlaceLava;
                break;
            }
            if (player.Can(permission))
            {
                player.Bind(originalBlock, replacementBlock);
                player.Message("{0} is now replaced with {1}", originalBlock, replacementBlock);
            }
            else
            {
                player.Message("&WYou do not have {0} permission.", permission);
            }
        }
Пример #22
0
        static void BindHandler( Player player, CommandReader cmd ) {
            if( !cmd.HasNext ) {
                player.Message( "All bindings have been reset." );
                player.ResetAllBinds();
                return;
            }

            Block originalBlock;
            if( !cmd.NextBlock( player, false, out originalBlock ) ) return;

            if( !cmd.HasNext ) {
                if( player.GetBind( originalBlock ) != originalBlock ) {
                    player.Message( "{0} is no longer bound to {1}",
                                    originalBlock,
                                    player.GetBind( originalBlock ) );
                    player.ResetBind( originalBlock );
                } else {
                    player.Message( "{0} is not bound to anything.",
                                    originalBlock );
                }
                return;
            }

            Block replacementBlock;
            if( !cmd.NextBlock( player, false, out replacementBlock ) ) return;

            if( cmd.HasNext ) {
                CdBind.PrintUsage( player );
                return;
            }

            Permission permission = Permission.Build;
            switch( replacementBlock ) {
                case Block.Grass:
                    permission = Permission.PlaceGrass;
                    break;
                case Block.Admincrete:
                    permission = Permission.PlaceAdmincrete;
                    break;
                case Block.Water:
                    permission = Permission.PlaceWater;
                    break;
                case Block.Lava:
                    permission = Permission.PlaceLava;
                    break;
            }
            if( player.Can( permission ) ) {
                player.Bind( originalBlock, replacementBlock );
                player.Message( "{0} is now replaced with {1}", originalBlock, replacementBlock );
            } else {
                player.Message( "&WYou do not have {0} permission.", permission );
            }
        }
Пример #23
0
        internal static void EllipsoidCallback( Player player, Position[] marks, object tag ) {
            byte drawBlock = (byte)tag;
            if( drawBlock == (byte)Block.Undefined ) {
                drawBlock = (byte)player.GetBind( player.LastUsedBlockType );
            }

            // find start/end coordinates
            int sx = Math.Min( marks[0].X, marks[1].X );
            int ex = Math.Max( marks[0].X, marks[1].X );
            int sy = Math.Min( marks[0].Y, marks[1].Y );
            int ey = Math.Max( marks[0].Y, marks[1].Y );
            int sh = Math.Min( marks[0].H, marks[1].H );
            int eh = Math.Max( marks[0].H, marks[1].H );

            // find axis lengths
            double rx = (ex - sx + 1) / 2d;
            double ry = (ey - sy + 1) / 2d;
            double rh = (eh - sh + 1) / 2d;

            double rx2 = 1 / (rx * rx);
            double ry2 = 1 / (ry * ry);
            double rh2 = 1 / (rh * rh);

            // find center points
            double cx = (ex + sx) / 2d;
            double cy = (ey + sy) / 2d;
            double ch = (eh + sh) / 2d;


            int volume = (int)(4 / 3d * Math.PI * rx * ry * rh);
            if( !player.CanDraw( volume ) ) {
                player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                   player.Info.Rank.DrawLimit,
                                   volume );
                return;
            }

            player.UndoBuffer.Clear();

            int blocks = 0, blocksDenied = 0;
            bool cannotUndo = false;

            for( int x = sx; x <= ex; x += DrawStride ) {
                for( int y = sy; y <= ey; y += DrawStride ) {
                    for( int h = sh; h <= eh; h++ ) {
                        for( int y3 = 0; y3 < DrawStride && y + y3 <= ey; y3++ ) {
                            for( int x3 = 0; x3 < DrawStride && x + x3 <= ex; x3++ ) {

                                // get relative coordinates
                                double dx = (x + x3 - cx);
                                double dy = (y + y3 - cy);
                                double dh = (h - ch);

                                // test if it's inside ellipse
                                if( (dx * dx) * rx2 + (dy * dy) * ry2 + (dh * dh) * rh2 <= 1 ) {
                                    DrawOneBlock( player, drawBlock, x + x3, y + y3, h, ref blocks, ref blocksDenied, ref cannotUndo );
                                }
                            }
                        }
                    }
                }
            }
            Logger.Log( "{0} drew an ellipsoid containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
                        player.Name,
                        blocks,
                        (Block)drawBlock,
                        player.World.Name );
            DrawingFinished( player, "drawn", blocks, blocksDenied );
        }