Exemplo n.º 1
0
        /// <summary>
        ///     Get a random position to travel to that is within the bounding box
        ///     generated by the given points.
        /// </summary>
        /// <param name="positions"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public FFACE.Position GetPosition(IEnumerable<FFACE.Position> positions, float distance)
        {
            // Get the position of the player which will be our origin.
            var origin = new FFACE.Position();

            // Get the bounding box which will be our wandering area.
            var boundingBox = new BoundingBox(positions);

            // Generate the new X and Y coordinates.
            origin.X = GenerateX(_fface.Player.Position, boundingBox, distance);
            origin.Z = GenerateZ(_fface.Player.Position, boundingBox, distance);

            // Create a point that represents the center of the bounding box.
            var center = new FFACE.Position
            {
                X = new List<float>
                {
                    boundingBox.XMin,
                    boundingBox.XMax
                }.Average(),
                Z = new List<float>
                {
                    boundingBox.ZMin,
                    boundingBox.ZMax
                }.Average()
            };

            // Make player goto center if one of the coordinates are out of bounds.
            if (center.X == origin.X || center.Z == origin.Z) return center;

            // Return the new position to travel to.
            return origin;
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Gets a newly random generated coordinate in the Y direction.
 /// </summary>
 /// <param name="origin"></param>
 /// <param name="boundingBox"></param>
 /// <param name="distance"></param>
 /// <returns></returns>
 private float GenerateZ(FFACE.Position origin, BoundingBox boundingBox, float distance)
 {
     return GenerateCoordinate(origin.Z, boundingBox.ZMax, boundingBox.ZMin, distance);
 }