Example #1
0
            } // @ public void GotoXYZ(dPoint x, dPoint y, dPoint z, bool KeepRunning)

            /// <summary>
            /// Will move the player to the passed destination or stop within a specified time.
            /// </summary>
            /// <param name="x">Function returning X coordinate of the destination</param>
            /// <param name="y">Function returning Y coordinate of the destination</param>
            /// <param name="z">Function returning Z coordinate of the destination</param>
            /// <param name="KeepRunning">Whether to keep moving after reaching the destination</param>
            /// <param name="timeOut">Time out in milliseconds</param>
            public void Goto(dPoint x, dPoint y, dPoint z, bool KeepRunning, int timeOut)
            {
                float X = x();
                float Y = y();
                float Z = z();

                // if passed values are all 0's we won't even bother.
                // because a target we're running to shouldn't be the player WHILE HE'S ZONING
                if (X == 0.0f && Y == 0.0f && Z == 0.0f)
                {
                    return;
                }

                double Heading       = 0.0f; // = HeadingTo(X, Y, Z, HeadingType.Degrees);
                double PlayerHeading = 0.0f; // = GetPlayerPosHInDegrees();
                double Herror        = 0.0f; // = HeadingError(PlayerHeading, Heading);

                DateTime Start = DateTime.Now;

                // while we're not within our distance tolerance
                // and
                // either timeOut is <= 0 (unlimited) or timeOut > 0 and Time since Goto called < timeOut
                while ((DistanceTo(X, Y, Z) > DistanceTolerance) &&
                       ((timeOut <= 0) || ((timeOut > 0) && ((DateTime.Now - Start).TotalMilliseconds) < timeOut)))
                {
                    // Update X, Y, and Z values
                    X = x();
                    Y = y();
                    Z = z();

                    // if ANY of the values are NOT zero, then we aren't zoning, do something
                    if (X != 0.0f || Y != 0.0f || Z != 0.0f)
                    {
                        if (UseNewMovement)
                        {
                            FFACE.StartRunning(_InstanceID, X, Z);
                        }

                        else
                        {
                            // Force ViewMode to first person otherwise this doesn't make sense
                            SetViewMode(ViewMode.FirstPerson);

                            // Check Heading Error
                            Heading       = HeadingTo(X, Y, Z, HeadingType.Degrees);
                            PlayerHeading = GetPlayerPosHInDegrees();
                            Herror        = HeadingError(PlayerHeading, Heading);

                            // if we're out of our heading tolerance
                            if (Math.Abs(Herror) > HeadingTolerance)
                            {
                                // Face proper direction
                                FaceHeading(X, Y, Z);
                            }
                            else if (UseArrowKeysForTurning && (Herror < -(HeadingTolerance / 2.0f)))
                            {
                                _FFACE.Windower.SendKeyPress(KeyCode.NP_Number4);
                            }
                            else if (UseArrowKeysForTurning && (Herror > (HeadingTolerance / 2.0f)))
                            {
                                _FFACE.Windower.SendKeyPress(KeyCode.NP_Number6);
                            }

                            // Moved StartRunning to AFTER the Distance check
                            // to avoid tap-tap-tapping when we're already within distance
                            if (!IsRunning())
                            {
                                StartRunning();
                            }
                        }
                    }

                    // Sleep(GotoDelay) milliseconds before next loop
                    System.Threading.Thread.Sleep(GotoDelay);
                } // @ while (DistanceToPosXZ(X, Z) > DistanceTolerance)

                if (!KeepRunning)
                {
                    StopRunning();
                }
            } // @ public void GotoXYZ(dPoint x, dPoint y, dPoint z, bool KeepRunning, int timeOut)