/// <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; }
private FFACE.Position ToPosition(IPosition position) { FFACE.Position pos = new FFACE.Position(); pos.X = position.X; pos.Y = position.Y; pos.Z = position.Z; pos.H = position.H; return pos; }
void RouteRecorder_Tick(object sender, EventArgs e) { var Point = ftools.FFACE.Player.Position; if (!Point.Equals(LastPosition)) { ftools.UserSettings.Waypoints.Add(new Waypoint(Point)); LastPosition = Point; } }
public Waypoint() { Position = new FFACE.Position(); }
static void go() { string[] destinations = goArgument.Split(';'); TurnMe turnMe = new TurnMe(fface); foreach (string destination in destinations) { string[] xy = destination.Split(','); double distanceToGoal = 1; FFACE.Position p = new FFACE.Position(); p.X = float.Parse(xy[0]); p.Z = float.Parse(xy[1]); Console.WriteLine("player =" + ToString(fface.Player.Position)); Console.WriteLine("destination=" + ToString(p)); Throttle throttleLog = new Throttle(3, true); while (!terminated) { double dx = p.X - fface.Player.PosX; double dz = p.Z - fface.Player.PosZ; double h = Math.Atan2(-dz, dx); double dd = Math.Sqrt(dx * dx + dz * dz); double dh = h - fface.Player.PosH; if (dh < -Math.PI) dh = 2 * Math.PI + dh; if (dh > Math.PI) dh = 2 * Math.PI - dh; if (dd <= distanceToGoal) { // WriteLine("stopIt dd=" + dd + " distanceToGoal=" + distanceToGoal); // turnMe.stopIt(); break; } double directionError = 0.14; /* if (dd < 20) { directionError = 0.1+(dd / 100.0); } if (dd < 10) { directionError = 3*dd/10.0; } if (dd < 6) { directionError = Math.PI; } */ if (throttleLog.isReady()) { WriteLine("please face " + String.Format("{0:0.00}", h) + " dd = " + String.Format("{00:0.00}", dd) + " dh = " + String.Format("{00:0.00}", dh)); // WriteLine("directionError=" + directionError); } if ((-directionError < dh) && (dh < directionError)) { // turnMe.stopTurning(); } else { WriteLine("Turning dh="+dh); turnMe.stopIt(); Thread.Sleep(100); SetNPCPosH(fface._InstanceID, fface.Player.ID, (float)h); Thread.Sleep(100); if (fface.Player.ViewMode != ViewMode.FirstPerson) { fface.Windower.SendKeyPress(KeyCode.NP_Number5); Thread.Sleep(100); } //WriteLine("Turning Done"); } if (dd > distanceToGoal) { turnMe.startRunning(); } } if (terminated) { break; } } turnMe.stopIt(); }
public Waypoint(FFACE.Position position) { _position = position; }
/// <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 playerPosition = FFACE.Player.Position; // Update the path if we've changed out position. Rotating our heading does not // count as the player moving. if (playerPosition.X != _lastPosition.X || playerPosition.Z != _lastPosition.Z) { // Add the new waypoint. Config.Instance.Waypoints.Add(new Waypoint(playerPosition)); _lastPosition = playerPosition; } }