Exemplo n.º 1
0
        static void CopySlotHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            int slotNumber;

            if (cmd.NextInt(out slotNumber))
            {
                if (cmd.HasNext)
                {
                    CdCopySlot.PrintUsage(player);
                    return;
                }
                if (slotNumber < 1 || slotNumber > player.Info.Rank.CopySlots)
                {
                    player.Message("CopySlot: Select a number between 1 and {0}", player.Info.Rank.CopySlots);
                }
                else
                {
                    player.CopySlot = slotNumber - 1;
                    CopyState info = player.GetCopyState();
                    if (info == null)
                    {
                        player.Message("Selected copy slot {0} (unused).", slotNumber);
                    }
                    else
                    {
                        player.Message("Selected copy slot {0}: {1} blocks from {2}, {3} old.",
                                       slotNumber,
                                       info.Blocks.Length,
                                       info.OriginWorld,
                                       DateTime.UtcNow.Subtract(info.CopyTime).ToMiniString());
                    }
                }
            }
            else
            {
                CopyState[] slots = player.CopyStates;
                player.Message("Using {0} of {1} slots. Selected slot: {2}",
                               slots.Count(info => info != null),
                               player.Info.Rank.CopySlots,
                               player.CopySlot + 1);
                for (int i = 0; i < slots.Length; i++)
                {
                    if (slots[i] != null)
                    {
                        player.Message("  {0}: {1} blocks from {2}, {3} old",
                                       i + 1,
                                       slots[i].Blocks.Length,
                                       slots[i].OriginWorld,
                                       DateTime.UtcNow.Subtract(slots[i].CopyTime).ToMiniString());
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void MirrorHandler( Player player, CommandReader cmd ) {
            CopyState originalInfo = player.GetCopyState();
            if( originalInfo == null ) {
                player.MessageNow( "Nothing to flip! Copy something first." );
                return;
            }

            // clone to avoid messing up any paste-in-progress
            CopyState info = new CopyState( originalInfo );

            bool flipX = false, flipY = false, flipH = false;
            string axis;
            while( (axis = cmd.Next()) != null ) {
                foreach( char c in axis.ToLower() ) {
                    if( c == 'x' ) flipX = true;
                    if( c == 'y' ) flipY = true;
                    if( c == 'z' ) flipH = true;
                }
            }

            if( !flipX && !flipY && !flipH ) {
                CdMirror.PrintUsage( player );
                return;
            }

            Block block;

            if( flipX ) {
                int left = 0;
                int right = info.Bounds.Width - 1;
                while( left < right ) {
                    for( int y = info.Bounds.Length - 1; y >= 0; y-- ) {
                        for( int z = info.Bounds.Height - 1; z >= 0; z-- ) {
                            block = info.Blocks[left, y, z];
                            info.Blocks[left, y, z] = info.Blocks[right, y, z];
                            info.Blocks[right, y, z] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if( flipY ) {
                int left = 0;
                int right = info.Bounds.Length - 1;
                while( left < right ) {
                    for( int x = info.Bounds.Width - 1; x >= 0; x-- ) {
                        for( int z = info.Bounds.Height - 1; z >= 0; z-- ) {
                            block = info.Blocks[x, left, z];
                            info.Blocks[x, left, z] = info.Blocks[x, right, z];
                            info.Blocks[x, right, z] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if( flipH ) {
                int left = 0;
                int right = info.Bounds.Height - 1;
                while( left < right ) {
                    for( int x = info.Bounds.Width - 1; x >= 0; x-- ) {
                        for( int y = info.Bounds.Length - 1; y >= 0; y-- ) {
                            block = info.Blocks[x, y, left];
                            info.Blocks[x, y, left] = info.Blocks[x, y, right];
                            info.Blocks[x, y, right] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if( flipX ) {
                if( flipY ) {
                    if( flipH ) {
                        player.Message( "Flipped copy along all axes." );
                    } else {
                        player.Message( "Flipped copy along X (east/west) and Y (north/south) axes." );
                    }
                } else {
                    if( flipH ) {
                        player.Message( "Flipped copy along X (east/west) and Z (vertical) axes." );
                    } else {
                        player.Message( "Flipped copy along X (east/west) axis." );
                    }
                }
            } else {
                if( flipY ) {
                    if( flipH ) {
                        player.Message( "Flipped copy along Y (north/south) and Z (vertical) axes." );
                    } else {
                        player.Message( "Flipped copy along Y (north/south) axis." );
                    }
                } else {
                    player.Message( "Flipped copy along Z (vertical) axis." );
                }
            }

            player.SetCopyState( info );
        }
Exemplo n.º 3
0
 static void CopySlotHandler( Player player, CommandReader cmd ) {
     int slotNumber;
     if( cmd.NextInt( out slotNumber ) ) {
         if( cmd.HasNext ) {
             CdCopySlot.PrintUsage( player );
             return;
         }
         if( slotNumber < 1 || slotNumber > player.Info.Rank.CopySlots ) {
             player.Message( "CopySlot: Select a number between 1 and {0}", player.Info.Rank.CopySlots );
         } else {
             player.CopySlot = slotNumber - 1;
             CopyState info = player.GetCopyState();
             if( info == null ) {
                 player.Message( "Selected copy slot {0} (unused).", slotNumber );
             } else {
                 player.Message( "Selected copy slot {0}: {1} blocks from {2}, {3} old.",
                                 slotNumber, info.Blocks.Length,
                                 info.OriginWorld, DateTime.UtcNow.Subtract( info.CopyTime ).ToMiniString() );
             }
         }
     } else {
         CopyState[] slots = player.CopyStates;
         player.Message( "Using {0} of {1} slots. Selected slot: {2}",
                         slots.Count( info => info != null ), player.Info.Rank.CopySlots, player.CopySlot + 1 );
         for( int i = 0; i < slots.Length; i++ ) {
             if( slots[i] != null ) {
                 player.Message( "  {0}: {1} blocks from {2}, {3} old",
                                 i + 1, slots[i].Blocks.Length,
                                 slots[i].OriginWorld,
                                 DateTime.UtcNow.Subtract( slots[i].CopyTime ).ToMiniString() );
             }
         }
     }
 }
Exemplo n.º 4
0
 static void PasteOpHandler( Player player, CommandReader cmd, int expectedMarks, DrawOpWithBrush op ) {
     if( !op.ReadParams( cmd ) ) return;
     player.SelectionStart( expectedMarks, DrawOperationCallback, op, Permission.Draw, Permission.CopyAndPaste );
     CopyState copyInfo = player.GetCopyState();
     if( copyInfo != null ) {
         player.MessageNow( "{0}: Click or &H/Mark&S the {1} corner.",
                            op.Description, copyInfo.OriginCorner );
     } else {
         player.MessageNow( "{0}: Click or &H/Mark&S a block.",
                            op.Description );
     }
 }
Exemplo n.º 5
0
        static void RotateHandler( Player player, CommandReader cmd ) {
            CopyState originalInfo = player.GetCopyState();
            if( originalInfo == null ) {
                player.MessageNow( "Nothing to rotate! Copy something first." );
                return;
            }

            int degrees;
            if( !cmd.NextInt( out degrees ) || (degrees != 90 && degrees != -90 && degrees != 180 && degrees != 270) ) {
                CdRotate.PrintUsage( player );
                return;
            }

            string axisName = cmd.Next();
            Axis axis = Axis.Z;
            if( axisName != null ) {
                switch( axisName.ToLower() ) {
                    case "x":
                        axis = Axis.X;
                        break;
                    case "y":
                        axis = Axis.Y;
                        break;
                    case "z":
                    case "h":
                        axis = Axis.Z;
                        break;
                    default:
                        CdRotate.PrintUsage( player );
                        return;
                }
            }

            // allocate the new buffer
            Block[, ,] oldBuffer = originalInfo.Blocks;
            Block[, ,] newBuffer;

            if( degrees == 180 ) {
                newBuffer = new Block[oldBuffer.GetLength( 0 ), oldBuffer.GetLength( 1 ), oldBuffer.GetLength( 2 )];

            } else if( axis == Axis.X ) {
                newBuffer = new Block[oldBuffer.GetLength( 0 ), oldBuffer.GetLength( 2 ), oldBuffer.GetLength( 1 )];

            } else if( axis == Axis.Y ) {
                newBuffer = new Block[oldBuffer.GetLength( 2 ), oldBuffer.GetLength( 1 ), oldBuffer.GetLength( 0 )];

            } else { // axis == Axis.Z
                newBuffer = new Block[oldBuffer.GetLength( 1 ), oldBuffer.GetLength( 0 ), oldBuffer.GetLength( 2 )];
            }

            // clone to avoid messing up any paste-in-progress
            CopyState info = new CopyState( originalInfo, newBuffer );

            // construct the rotation matrix
            int[,] matrix = {
                {1,0,0},
                {0,1,0},
                {0,0,1}
            };

            int a, b;
            switch( axis ) {
                case Axis.X:
                    a = 1;
                    b = 2;
                    break;
                case Axis.Y:
                    a = 0;
                    b = 2;
                    break;
                default:
                    a = 0;
                    b = 1;
                    break;
            }

            switch( degrees ) {
                case 90:
                    matrix[a, a] = 0;
                    matrix[b, b] = 0;
                    matrix[a, b] = -1;
                    matrix[b, a] = 1;
                    break;
                case 180:
                    matrix[a, a] = -1;
                    matrix[b, b] = -1;
                    break;
                case -90:
                case 270:
                    matrix[a, a] = 0;
                    matrix[b, b] = 0;
                    matrix[a, b] = 1;
                    matrix[b, a] = -1;
                    break;
            }

            // apply the rotation matrix
            for( int x = oldBuffer.GetLength( 0 ) - 1; x >= 0; x-- ) {
                for( int y = oldBuffer.GetLength( 1 ) - 1; y >= 0; y-- ) {
                    for( int z = oldBuffer.GetLength( 2 ) - 1; z >= 0; z-- ) {
                        int nx = (matrix[0, 0] < 0 ? oldBuffer.GetLength( 0 ) - 1 - x : (matrix[0, 0] > 0 ? x : 0)) +
                                 (matrix[0, 1] < 0 ? oldBuffer.GetLength( 1 ) - 1 - y : (matrix[0, 1] > 0 ? y : 0)) +
                                 (matrix[0, 2] < 0 ? oldBuffer.GetLength( 2 ) - 1 - z : (matrix[0, 2] > 0 ? z : 0));
                        int ny = (matrix[1, 0] < 0 ? oldBuffer.GetLength( 0 ) - 1 - x : (matrix[1, 0] > 0 ? x : 0)) +
                                 (matrix[1, 1] < 0 ? oldBuffer.GetLength( 1 ) - 1 - y : (matrix[1, 1] > 0 ? y : 0)) +
                                 (matrix[1, 2] < 0 ? oldBuffer.GetLength( 2 ) - 1 - z : (matrix[1, 2] > 0 ? z : 0));
                        int nz = (matrix[2, 0] < 0 ? oldBuffer.GetLength( 0 ) - 1 - x : (matrix[2, 0] > 0 ? x : 0)) +
                                 (matrix[2, 1] < 0 ? oldBuffer.GetLength( 1 ) - 1 - y : (matrix[2, 1] > 0 ? y : 0)) +
                                 (matrix[2, 2] < 0 ? oldBuffer.GetLength( 2 ) - 1 - z : (matrix[2, 2] > 0 ? z : 0));
                        newBuffer[nx, ny, nz] = oldBuffer[x, y, z];
                    }
                }
            }

            player.Message( "Rotated copy (slot {0}) by {1} degrees around {2} axis.",
                            info.Slot + 1, degrees, axis );
            player.SetCopyState( info );
        }
Exemplo n.º 6
0
        static void RotateHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            CopyState originalInfo = player.GetCopyState();

            if (originalInfo == null)
            {
                player.MessageNow("Nothing to rotate! Copy something first.");
                return;
            }

            int degrees;

            if (!cmd.NextInt(out degrees) || (degrees != 90 && degrees != -90 && degrees != 180 && degrees != 270))
            {
                CdRotate.PrintUsage(player);
                return;
            }

            string axisName = cmd.Next();
            Axis   axis     = Axis.Z;

            if (axisName != null)
            {
                switch (axisName.ToLower())
                {
                case "x":
                    axis = Axis.X;
                    break;

                case "y":
                    axis = Axis.Y;
                    break;

                case "z":
                case "h":
                    axis = Axis.Z;
                    break;

                default:
                    CdRotate.PrintUsage(player);
                    return;
                }
            }

            // allocate the new buffer
            Block[,,] oldBuffer = originalInfo.Blocks;
            Block[,,] newBuffer;

            if (degrees == 180)
            {
                newBuffer = new Block[oldBuffer.GetLength(0), oldBuffer.GetLength(1), oldBuffer.GetLength(2)];
            }
            else if (axis == Axis.X)
            {
                newBuffer = new Block[oldBuffer.GetLength(0), oldBuffer.GetLength(2), oldBuffer.GetLength(1)];
            }
            else if (axis == Axis.Y)
            {
                newBuffer = new Block[oldBuffer.GetLength(2), oldBuffer.GetLength(1), oldBuffer.GetLength(0)];
            }
            else
            {
                // axis == Axis.Z
                newBuffer = new Block[oldBuffer.GetLength(1), oldBuffer.GetLength(0), oldBuffer.GetLength(2)];
            }

            // clone to avoid messing up any paste-in-progress
            CopyState info = new CopyState(originalInfo, newBuffer);

            // construct the rotation matrix
            int[,] matrix =
            {
                { 1, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 1 }
            };

            int a,
                b;

            switch (axis)
            {
            case Axis.X:
                a = 1;
                b = 2;
                break;

            case Axis.Y:
                a = 0;
                b = 2;
                break;

            default:
                a = 0;
                b = 1;
                break;
            }

            switch (degrees)
            {
            case 90:
                matrix[a, a] = 0;
                matrix[b, b] = 0;
                matrix[a, b] = -1;
                matrix[b, a] = 1;
                break;

            case 180:
                matrix[a, a] = -1;
                matrix[b, b] = -1;
                break;

            case -90:
            case 270:
                matrix[a, a] = 0;
                matrix[b, b] = 0;
                matrix[a, b] = 1;
                matrix[b, a] = -1;
                break;
            }

            // apply the rotation matrix
            for (int x = oldBuffer.GetLength(0) - 1; x >= 0; x--)
            {
                for (int y = oldBuffer.GetLength(1) - 1; y >= 0; y--)
                {
                    for (int z = oldBuffer.GetLength(2) - 1; z >= 0; z--)
                    {
                        int nx = (matrix[0, 0] < 0 ? oldBuffer.GetLength(0) - 1 - x : (matrix[0, 0] > 0 ? x : 0)) +
                                 (matrix[0, 1] < 0 ? oldBuffer.GetLength(1) - 1 - y : (matrix[0, 1] > 0 ? y : 0)) +
                                 (matrix[0, 2] < 0 ? oldBuffer.GetLength(2) - 1 - z : (matrix[0, 2] > 0 ? z : 0));
                        int ny = (matrix[1, 0] < 0 ? oldBuffer.GetLength(0) - 1 - x : (matrix[1, 0] > 0 ? x : 0)) +
                                 (matrix[1, 1] < 0 ? oldBuffer.GetLength(1) - 1 - y : (matrix[1, 1] > 0 ? y : 0)) +
                                 (matrix[1, 2] < 0 ? oldBuffer.GetLength(2) - 1 - z : (matrix[1, 2] > 0 ? z : 0));
                        int nz = (matrix[2, 0] < 0 ? oldBuffer.GetLength(0) - 1 - x : (matrix[2, 0] > 0 ? x : 0)) +
                                 (matrix[2, 1] < 0 ? oldBuffer.GetLength(1) - 1 - y : (matrix[2, 1] > 0 ? y : 0)) +
                                 (matrix[2, 2] < 0 ? oldBuffer.GetLength(2) - 1 - z : (matrix[2, 2] > 0 ? z : 0));
                        newBuffer[nx, ny, nz] = oldBuffer[x, y, z];
                    }
                }
            }

            player.Message("Rotated copy (slot {0}) by {1} degrees around {2} axis.",
                           info.Slot + 1,
                           degrees,
                           axis);
            player.SetCopyState(info);
        }
Exemplo n.º 7
0
        static void MirrorHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            CopyState originalInfo = player.GetCopyState();

            if (originalInfo == null)
            {
                player.MessageNow("Nothing to flip! Copy something first.");
                return;
            }

            // clone to avoid messing up any paste-in-progress
            CopyState info = new CopyState(originalInfo);

            bool flipX = false,
                 flipY = false,
                 flipH = false;
            string axis;

            while ((axis = cmd.Next()) != null)
            {
                foreach (char c in axis.ToLower())
                {
                    if (c == 'x')
                    {
                        flipX = true;
                    }
                    if (c == 'y')
                    {
                        flipY = true;
                    }
                    if (c == 'z')
                    {
                        flipH = true;
                    }
                }
            }

            if (!flipX && !flipY && !flipH)
            {
                CdMirror.PrintUsage(player);
                return;
            }

            Block block;

            if (flipX)
            {
                int left  = 0;
                int right = info.Bounds.Width - 1;
                while (left < right)
                {
                    for (int y = info.Bounds.Length - 1; y >= 0; y--)
                    {
                        for (int z = info.Bounds.Height - 1; z >= 0; z--)
                        {
                            block = info.Blocks[left, y, z];
                            info.Blocks[left, y, z]  = info.Blocks[right, y, z];
                            info.Blocks[right, y, z] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if (flipY)
            {
                int left  = 0;
                int right = info.Bounds.Length - 1;
                while (left < right)
                {
                    for (int x = info.Bounds.Width - 1; x >= 0; x--)
                    {
                        for (int z = info.Bounds.Height - 1; z >= 0; z--)
                        {
                            block = info.Blocks[x, left, z];
                            info.Blocks[x, left, z]  = info.Blocks[x, right, z];
                            info.Blocks[x, right, z] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if (flipH)
            {
                int left  = 0;
                int right = info.Bounds.Height - 1;
                while (left < right)
                {
                    for (int x = info.Bounds.Width - 1; x >= 0; x--)
                    {
                        for (int y = info.Bounds.Length - 1; y >= 0; y--)
                        {
                            block = info.Blocks[x, y, left];
                            info.Blocks[x, y, left]  = info.Blocks[x, y, right];
                            info.Blocks[x, y, right] = block;
                        }
                    }
                    left++;
                    right--;
                }
            }

            if (flipX)
            {
                if (flipY)
                {
                    if (flipH)
                    {
                        player.Message("Flipped copy along all axes.");
                    }
                    else
                    {
                        player.Message("Flipped copy along X (east/west) and Y (north/south) axes.");
                    }
                }
                else
                {
                    if (flipH)
                    {
                        player.Message("Flipped copy along X (east/west) and Z (vertical) axes.");
                    }
                    else
                    {
                        player.Message("Flipped copy along X (east/west) axis.");
                    }
                }
            }
            else
            {
                if (flipY)
                {
                    if (flipH)
                    {
                        player.Message("Flipped copy along Y (north/south) and Z (vertical) axes.");
                    }
                    else
                    {
                        player.Message("Flipped copy along Y (north/south) axis.");
                    }
                }
                else
                {
                    player.Message("Flipped copy along Z (vertical) axis.");
                }
            }

            player.SetCopyState(info);
        }