Beispiel #1
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = points[0];

            vicMazeGen.cMaze maze     = new vicMazeGen.cMaze();
            string[]         rawLines = main.GetMessage(originalchatline).Split(' ');
            if (rawLines.Length < 4)            //Not enough arguements given
            {
                main.SendMessagePacket("Not enough arguements. (" + (rawLines.Length - 2) + " given, 2 expected.)");
                main.SetDrawerToNull();
                return;
            }
            int mazeX; int mazeY; byte smoothness;  int seed;

            //Required paramters - Fail if these are not found.
            if (!Int32.TryParse(rawLines[2], out mazeX) || !Int32.TryParse(rawLines[3], out mazeY))
            {
                main.SendMessagePacket("Given maze size was in the incorrect format.");
                main.SetDrawerToNull();
                return;
            }             //todo catch divide by zero exceptions.
            //Optional paramters - Otherwise use random numbers.
            if (rawLines.Length > 4 && Byte.TryParse(rawLines[4], out smoothness))
            {
            }
            else
            {
                smoothness = (byte)(new Random().Next(0, 30));
            }
            if (rawLines.Length > 5 && Int32.TryParse(rawLines[5], out seed))
            {
            }
            else
            {
                seed = (new Random().Next(0, Int32.MaxValue));
            }                                                                   //I think it can go larger. Random can't though.
            //Actually generate.
            maze.GenerateMaze(mazeX / 2, mazeY / 2, smoothness, seed);
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator <Vector3I> coordEnumerator = maze.BlockEnumerator(points[0], mazeX, mazeY);

            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
Beispiel #2
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords    = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            double   rx        = (MaxVertex.X - MinVertex.X + 1) / 2d;
            double   ry        = (MaxVertex.Y - MinVertex.Y + 1) / 2d;
            double   rz        = (MaxVertex.Z - MinVertex.Z + 1) / 2d;

            radius.X = (float)(1 / (rx * rx));
            radius.Y = (float)(1 / (ry * ry));
            radius.Z = (float)(1 / (rz * rz));

            // find center points
            center.X = (float)((MinVertex.X + MaxVertex.X) / 2d);
            center.Y = (float)((MinVertex.Y + MaxVertex.Y) / 2d);
            center.Z = (float)((MinVertex.Z + MaxVertex.Z) / 2d);

            Coords = MinVertex;
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator <Vector3I> coordEnumerator = BlockEnumerator(MinVertex, MaxVertex).GetEnumerator();

            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
Beispiel #3
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords    = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            for (; Coords.X <= MaxVertex.X; Coords.X++)
            {
                for (; Coords.Y <= MaxVertex.Y; Coords.Y++)
                {
                    for (; Coords.Z <= MaxVertex.Z; Coords.Z++)
                    {
                        if (Aborted == true)
                        {
                            return;
                        }
                        Thread.Sleep(sleeptime);
                        main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                        main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                    }
                    Coords.Z = MinVertex.Z;                     //Reset height.
                }
                Coords.Y = MinVertex.Y;
            }
            main.SetDrawerToNull();
        }
Beispiel #4
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing. 
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            for (; Coords.X <= MaxVertex.X; Coords.X++)
            {
                for (; Coords.Y <=  MaxVertex.Y; Coords.Y++)
                {
                    for (; Coords.Z <=  MaxVertex.Z; Coords.Z++)
                    {
                        if (Aborted == true) {
                            return;
                        }
                        Thread.Sleep(sleeptime);
                        main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                        main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                    }
                    Coords.Z = MinVertex.Z; //Reset height.
                }
                Coords.Y = MinVertex.Y;
            }
            main.SetDrawerToNull();
        }
Beispiel #5
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            coordEnumerator = LineEnumerator(points[0], points[1]).GetEnumerator();
            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true) {
                    return;
                }
                Coords = coordEnumerator.Current;
                Thread.Sleep(sleeptime);
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
Beispiel #6
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords    = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            Vector3I Coords2   = Vector3I.Max(points[0], points[1]);

            Coords2.Z = MinVertex.Z;
            Vector3I Coords3 = Coords;
            int      xMax    = (MinVertex.X + MaxVertex.X / 2);
            int      yMax    = (MinVertex.Y + MaxVertex.Y / 2);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);

            while (Coords3.X <= xMax && Coords3.Y <= yMax)             //It's not pretty, but it works.
            {
                Coords = Coords3;
                for (; Coords.X <= Coords2.X; Coords.X++)
                {
                    for (; Coords.Y <= Coords2.Y; Coords.Y++)
                    {
                        for (; Coords.Z <= Coords2.Z; Coords.Z++)
                        {
                            if (Aborted == true)
                            {
                                return;
                            }
                            Thread.Sleep(sleeptime);
                            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                            main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                        }
                        Coords.Z = Coords3.Z;                         //Reset height.
                    }
                    Coords.Y = Coords3.Y;
                }
                Coords3.X++;
                Coords3.Y++;
                Coords3.Z++;
                Coords2.X--;
                Coords2.Y--;
                Coords2.Z++;                 //All these are needed, maybe some day I'll improve this.
            }
            main.SetDrawerToNull();
        }
Beispiel #7
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            coordEnumerator = LineEnumerator(points[0], points[1]).GetEnumerator();
            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Coords = coordEnumerator.Current;
                Thread.Sleep(sleeptime);
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
Beispiel #8
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            Vector3I Coords2 = Vector3I.Max(points[0], points[1]);
            Coords2.Z = MinVertex.Z;
            Vector3I Coords3 = Coords;
            int xMax = (MinVertex.X + MaxVertex.X / 2);
            int yMax = (MinVertex.Y + MaxVertex.Y / 2);
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);

            while (Coords3.X <= xMax && Coords3.Y <= yMax) //It's not pretty, but it works.
            {
                Coords = Coords3;
                for (; Coords.X <= Coords2.X; Coords.X++)
                {
                    for (; Coords.Y <= Coords2.Y; Coords.Y++)
                    {
                        for (; Coords.Z <= Coords2.Z; Coords.Z++)
                        {
                            if (Aborted == true) {
                                return;
                            }
                            Thread.Sleep(sleeptime);
                            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                            main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                        }
                        Coords.Z = Coords3.Z; //Reset height.
                    }
                    Coords.Y = Coords3.Y;
                }
                Coords3.X++;
                Coords3.Y++;
                Coords3.Z++;
                Coords2.X--;
                Coords2.Y--;
                Coords2.Z++; //All these are needed, maybe some day I'll improve this.
            }
            main.SetDrawerToNull();
        }
Beispiel #9
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I firstPoint = points[0];
            Bitmap   myBitmap   = null;

            string[] full = main.GetMessage(originalchatline).Trim().Split(new char[] { ' ' }, 3);
            try { myBitmap = new Bitmap(full[2]); } catch { return; }             //Invalid file, stop drawing.
            myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            byte direction = GetDirection(points);

            if (direction == 4)
            {
                return;
            }

            Block[] refCols = GetReferenceColours();
            Block   currentBlock;

            double[] distance = new double[refCols.Length];
            int      position;

            for (int curwidth = 0; curwidth < myBitmap.Width; curwidth++)
            {
                for (int curheight = 0; curheight < myBitmap.Height; curheight++)
                {
                    currentBlock.Z = (firstPoint.Z + curheight);
                    if (direction == 0)
                    {
                        currentBlock.X = (firstPoint.X + curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if (direction == 1)
                    {
                        currentBlock.X = (firstPoint.X - curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if (direction == 2)
                    {
                        currentBlock.Y = (firstPoint.Y + curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    else
                    {
                        currentBlock.Y = (firstPoint.Y - curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    currentBlock.col = myBitmap.GetPixel(curwidth, curheight);

                    for (int j = 0; j < distance.Length; j++)                        //Calculate distances between the colors in the image and the set reference colors, and store them.
                    {
                        distance[j] = Math.Sqrt(Math.Pow((currentBlock.col.R - refCols[j].col.R), 2) +
                                                Math.Pow((currentBlock.col.B - refCols[j].col.B), 2) +
                                                Math.Pow((currentBlock.col.G - refCols[j].col.G), 2));
                    }
                    position = 0;
                    double minimum = distance[0];
                    for (int h = 1; h < distance.Length; h++)                        //Find the smallest distance in the array of distances.
                    {
                        if (distance[h] < minimum)
                        {
                            minimum  = distance[h];
                            position = h;
                        }
                    }
                    currentBlock.blockType = refCols[position].blockType; //Set the block we found closest to the image to the block we are placing.
                    if (position <= 20)                                   //Back colour blocks
                    {
                        if (direction == 0)
                        {
                            currentBlock.Y += 1;
                        }
                        else if (direction == 1)
                        {
                            currentBlock.Y -= 1;
                        }
                        else if (direction == 2)
                        {
                            currentBlock.X -= 1;
                        }
                        else if (direction == 3)
                        {
                            currentBlock.X += 1;
                        }
                    }                     //Otherwise, draw them in the front row.
                    if (currentBlock.col.A < 20)
                    {
                        currentBlock.blockType = 0;                                                //Transparent pixels.
                    }
                    if (Aborted == true)
                    {
                        return;
                    }
                    Thread.Sleep(sleeptime);
                    main.SendPositionPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z);
                    main.SendBlockPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z, 1, currentBlock.blockType);
                }
            }
            myBitmap.Dispose();
            main.SetDrawerToNull();
        }
Beispiel #10
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            double rx = (MaxVertex.X - MinVertex.X + 1) / 2d;
            double ry = (MaxVertex.Y - MinVertex.Y + 1) / 2d;
            double rz = (MaxVertex.Z - MinVertex.Z + 1) / 2d;

            radius.X = (float)(1 / (rx * rx));
            radius.Y = (float)(1 / (ry * ry));
            radius.Z = (float)(1 / (rz * rz));

            // find center points
            center.X = (float)((MinVertex.X + MaxVertex.X) / 2d);
            center.Y = (float)((MinVertex.Y + MaxVertex.Y) / 2d);
            center.Z = (float)((MinVertex.Z + MaxVertex.Z) / 2d);

            Coords = MinVertex;
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator<Vector3I> coordEnumerator = BlockEnumerator(MinVertex, MaxVertex).GetEnumerator();
            while(coordEnumerator.MoveNext())
            {
                if (Aborted == true) {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);

            }
            main.SetDrawerToNull();
        }
Beispiel #11
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I firstPoint = points[0];
            Bitmap myBitmap = null;
            string[] full = main.GetMessage(originalchatline).Trim().Split(new char[] {' '}, 3);
            try { myBitmap = new Bitmap(full[2]); } catch { return; } //Invalid file, stop drawing.
            myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            byte direction = GetDirection(points);
            if (direction == 4) return;

            Block[] refCols = GetReferenceColours();
            Block currentBlock;
            double[] distance = new double[refCols.Length];
            int position;
            for ( int curwidth = 0; curwidth < myBitmap.Width; curwidth++ ) {
                for ( int curheight = 0; curheight < myBitmap.Height; curheight++ ) {

                    currentBlock.Z = (firstPoint.Z + curheight);
                    if(direction == 0) {
                        currentBlock.X = (firstPoint.X + curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if ( direction == 1 ) {
                        currentBlock.X = (firstPoint.X - curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if(direction == 2) {
                        currentBlock.Y = (firstPoint.Y + curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    else {
                        currentBlock.Y = (firstPoint.Y - curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    currentBlock.col = myBitmap.GetPixel(curwidth, curheight);

                    for ( int j = 0; j < distance.Length; j++ ) {//Calculate distances between the colors in the image and the set reference colors, and store them.
                        distance[j] = Math.Sqrt(Math.Pow((currentBlock.col.R - refCols[j].col.R ), 2) +
                                                Math.Pow(( currentBlock.col.B - refCols[j].col.B ), 2) +
                                                Math.Pow(( currentBlock.col.G - refCols[j].col.G ), 2 ));
                    }
                    position = 0;
                    double minimum = distance[0];
                    for ( int h = 1; h < distance.Length; h++ ) {//Find the smallest distance in the array of distances.
                        if ( distance[h] < minimum ) {
                            minimum = distance[h];
                            position = h;
                        }
                    }
                    currentBlock.blockType = refCols[position].blockType;//Set the block we found closest to the image to the block we are placing.
                    if ( position <= 20 ) {//Back colour blocks
                        if ( direction == 0 ) { currentBlock.Y += 1; }
                        else if (direction == 1) { currentBlock.Y -= 1;  }
                        else if ( direction == 2 ) { currentBlock.X -=1; }
                        else if ( direction == 3 ) { currentBlock.X +=1; }
                    } //Otherwise, draw them in the front row.
                    if ( currentBlock.col.A < 20 ) currentBlock.blockType = 0; //Transparent pixels.
                    if (Aborted == true) {
                        return;
                    }
                    Thread.Sleep(sleeptime);
                    main.SendPositionPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z);
                    main.SendBlockPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z, 1, currentBlock.blockType);
                }
            }
            myBitmap.Dispose();
            main.SetDrawerToNull();
        }