public bool GetNextPosition(ScenePresence scenePresence, float closeToRange, TimeSpan diffFromLastFrame, float secondsBeforeForcedTeleport, out Vector3 position, out TravelMode state, out bool needsToTeleportToPosition, out bool changingNodes) { changingNodes = false; lock (m_lock) { while (true) { //Initialize default values position = Vector3.Zero; state = TravelMode.None; needsToTeleportToPosition = false; //See if we have a valid position to attempt to move to if (CurrentPos < m_listOfPositions.Count) { //Get the position/state and make sure that it is within the region position = m_listOfPositions[CurrentPos]; Util.ForceValidRegionXYZ(ref position); state = m_listOfStates[CurrentPos]; if (state == TravelMode.Wait) { if (!m_waitingSince.HasValue)//Has no value, so we're just starting to wait { m_waitingSince = DateTime.Now; } else { double ms = (DateTime.Now - m_waitingSince.Value).TotalMilliseconds; if (ms > (position.X * 1000f)) { //We're done waiting, increment the position counter and go around the loop again m_waitingSince = null; CurrentPos++; changingNodes = true; m_timeSinceLastChangedPosition = TimeSpan.FromMilliseconds(0); continue; } } return(true); } else { //We are attempting to move somewhere if (scenePresence.IsAtTarget(position, closeToRange)) { //We made it to the position, begin proceeding towards the next position CurrentPos++; changingNodes = true; m_timeSinceLastChangedPosition = TimeSpan.FromMilliseconds(0); continue; } else { m_timeSinceLastChangedPosition = m_timeSinceLastChangedPosition.Add(diffFromLastFrame); //We need to see if we should teleport to the next node rather than waiting for us to get there if (m_timeSinceLastChangedPosition.TotalMilliseconds > (secondsBeforeForcedTeleport * 1000)) { changingNodes = true; m_timeSinceLastChangedPosition = TimeSpan.FromMilliseconds(0); needsToTeleportToPosition = true; } } return(true); } } else { //We've finished all the states in the position list m_timeSinceLastChangedPosition = TimeSpan.FromMilliseconds(0); if (m_listOfPositions.Count == 0)//Sanity check { return(false); } if (FollowIndefinitely) { //If we're following indefinitely, then the counter is reset to the beginning and we go around again CurrentPos = 0; changingNodes = true; continue; } return(false); } } } }