Beispiel #1
0
            public void Goto(Position position, bool useObjectAvoidance)
            {
                if (DistanceTo(position) > DistanceTolerance)
                {
                    DateTime duration = DateTime.Now.AddSeconds(5);
                    api.ThirdParty.KeyDown(Keys.NUMPAD8);

                    while (DistanceTo(position) > DistanceTolerance && DateTime.Now < duration)
                    {
                        if ((ViewMode)api.Player.ViewMode != ViewMode.FirstPerson)
                        {
                            api.Player.ViewMode = (int)ViewMode.FirstPerson;
                        }

                        FaceHeading(position);

                        if (useObjectAvoidance)
                        {
                            AvoidObstacles();
                        }

                        Thread.Sleep(30);
                    }

                    api.ThirdParty.KeyUp(Keys.NUMPAD8);
                }
            }
Beispiel #2
0
        public Position GetNextPosition(Position playerPosition)
        {
            _positions = Waypoints.ToList();

            if (_position == _positions.Count)
            {
                if (StraightRoute)
                {
                    Waypoints = new ObservableCollection<Position>(Waypoints.Reverse());
                    _positions.Reverse();
                }
                _position = 0;
            }

            var distance = Distance(playerPosition, _positions[_position]);

            if (distance > 15)
            {
                var closest = _positions.OrderBy(x => Distance(playerPosition, x)).FirstOrDefault();
                _position = _positions.IndexOf(closest);
            }

            var newPosition = _positions[_position];

            _position++;

            return newPosition;
        }
Beispiel #3
0
 public bool FaceHeading(Position position)
 {
     var player = api.Entity.GetLocalPlayer();
     var angle = (byte)(Math.Atan((position.Z - player.Z) / (position.X - player.X)) * -(128.0f / Math.PI));
     if (player.X > position.X) angle += 128;
     var radian = (float)angle / 255 * 2 * Math.PI;
     return api.Entity.SetEntityHPosition(api.Entity.LocalPlayerIndex, (float)radian);
 }
Beispiel #4
0
            public double DistanceTo(Position position)
            {
                var player = api.Entity.GetLocalPlayer();

                return Math.Sqrt(
                    Math.Pow(position.X - player.X, 2) +
                    Math.Pow(position.Y - player.Y, 2) +
                    Math.Pow(position.Z - player.Z, 2));
            }
Beispiel #5
0
        public static Position ToPosition(float x, float y, float z, float h)
        {
            var position = new Position();

            position.X = x;
            position.Y = y;
            position.Z = z;
            position.H = h;

            return position;
        }
Beispiel #6
0
        public void AddNewPositionWithPositionWillRecordIt()
        {
            Position expected = new Position {H = 1, X = 1, Y = 1, Z = 1};
            Position result = null;

            var recorder = new PathRecorder(null);

            recorder.OnPositionAdded += actual => result = actual;
            recorder.AddNewPosition(expected);

            Assert.Equal(expected, result);
        }
Beispiel #7
0
        public static Position ToPosition(float x, float y, float z, float h)
        {
            var position = new Position
            {
                X = x,
                Y = y,
                Z = z,
                H = h
            };

            return position;
        }
Beispiel #8
0
 private double Distance(Position one, Position other)
 {
     return Math.Sqrt(Math.Pow(one.X - other.X, 2) + Math.Pow(one.Z - other.Z, 2));
 }
Beispiel #9
0
 public bool IsWithinDistance(Position position, double distance)
 {
     return Waypoints.Any(x => Distance(position, x) <= distance);
 }
Beispiel #10
0
 public void AddNewPosition(Position position)
 {
     // Update the path if we've changed out position. Rotating our heading does not
     // count as the player moving.
     if (_lastPosition == null ||
         position.X != _lastPosition.X ||
         position.Z != _lastPosition.Z)
     {
         // Fire positon added event.
         OnPositionAdded?.Invoke(position);
         _lastPosition = position;
     }
 }
Beispiel #11
0
        /// <summary>
        ///     Records a new path for the player to travel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RouteRecorder_Tick(object sender, EventArgs e)
        {
            // Add a new waypoint only when we are not standing at
            // our last position.
            var pos = _memory.Player.Position;

            Position position = new Position()
            {
                H = pos.H,
                X = pos.X,
                Y = pos.Y,
                Z = pos.Z
            };

            AddNewPosition(position);
        }
Beispiel #12
0
 /// <summary>
 /// Return the 2-D distance between the unit and a position. 
 /// </summary>
 /// <param name="mob"></param>
 /// <param name="waypoint"></param>
 /// <returns></returns>
 private static double Distance(Unit mob, Position waypoint)
 {
     return Math.Sqrt(Math.Pow(waypoint.X - mob.PosX, 2) + Math.Pow(waypoint.Z - mob.PosZ, 2));
 }
Beispiel #13
0
 private void _recorder_OnPositionAdded(Position position)
 {
     App.Current.Dispatcher.Invoke(() => this.Route.Add(position));
 }
Beispiel #14
0
        /// <summary>
        ///     Records a new path for the player to travel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RouteRecorder_Tick(object sender, EventArgs e)
        {
            // Add a new waypoint only when we are not standing at 
            // our last position. 
            var pos = _memory.Player.Position;

            Position position = new Position()
            {
                H = pos.H,
                X = pos.X,
                Y = pos.Y,
                Z = pos.Z
            };

            // Update the path if we've changed out position. Rotating our heading does not
            // count as the player moving. 
            if (position.X != _lastPosition.X || position.Z != _lastPosition.Z)
            {
                // Fire positon added event. 
                if (OnPositionAdded != null)
                {
                    OnPositionAdded(position);
                }

                _lastPosition = position;
            }
        }