Exemplo n.º 1
0
        /// <summary>
        /// Adds a step to the queue internally.
        /// </summary>
        /// <param name="x">X coordinate of step.</param>
        /// <param name="y">Y coordinate of step.</param>
        private void AddStepInternal(short x, short y)
        {
            // Check to see if the current count of queues overflows the capacity limit.
            if (this.writePosition >= WalkingQueue.Capacity)
            {
                /*
                 * The character most likely is a bot, cause
                 * normal characters cannot reach this limit.
                 */
                return;
            }

            // Get differences.
            short diffX = (short)(x - this.points[this.writePosition - 1].X);
            short diffY = (short)(y - this.points[this.writePosition - 1].Y);

            // Caclulate direction from differences.
            sbyte direction = DirectionUtilities.CalculateDirection(diffX, diffY);

            // We only need to enqueue the point if the direction is valid.
            if (direction > -1)
            {
                // Enqueue the calculated point.
                this.points[this.writePosition++] = new MovementPoint(x, y, direction);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the next point.
        /// </summary>
        /// <returns>Returns the point's direction.</returns>
        private sbyte GetNextPoint()
        {
            // Nothing to read.
            if (this.readPosition == this.writePosition)
            {
                return(-1);
            }

            MovementPoint mp  = points[this.readPosition++];
            sbyte         dir = DirectionUtilities.CalculateDirection(this.npc.Location.X, this.npc.Location.Y, mp.X, mp.Y);


            /*
             * You cannot search though an array with a negative number,
             * so we must check if the direction is higher than -1.
             */
            if (dir != -1)
            {
                dir >>= 1;
                this.npc.Location = Location.Create(mp.X, mp.Y, this.npc.Location.Z);
            }
            return(dir);
        }