static void npc() { string[] ids = npcArgument.Split(','); Throttle throttleLog = new Throttle(10, true); while (!terminated) { bool throttleLogIsReady = throttleLog.isReady(); if (throttleLogIsReady) { Console.WriteLine("player=" + ToString(fface.Player.Position)); Console.WriteLine("target=" + ToString(fface.Target.Position) + " " + String.Format("{0:X}", fface.Target.ID) + "\t" + fface.Target.Name); } foreach (string id in ids) { int i = Int32.Parse(id, System.Globalization.NumberStyles.HexNumber); if (throttleLogIsReady) Console.WriteLine("npc =" + ToString(fface.NPC.GetPosition(i)) + " " + String.Format("{0:X}", i) + " " + (fface.NPC.IsActive(i)?"O":"X") + " " + fface.NPC.Status(i) + "\t" + fface.NPC.Name(i)); TurnMe turnMe = new TurnMe(fface); while ((match("standing", fface.NPC.Status(i).ToString()) || match("fighting", fface.NPC.Status(i).ToString())) && fface.Player.ViewMode == FFACETools.ViewMode.FirstPerson && fface.NPC.IsActive(i)) { throttleLogIsReady = throttleLog.isReady(); double distanceToGoal = distanceArgument; if (terminated) break; FFACE.Position p = fface.NPC.GetPosition(i); if (match("fighting", fface.Player.Status.ToString())) { p = fface.Target.Position; } double dx = p.X - fface.Player.PosX; double dz = fface.Player.PosZ - p.Z; double h = Math.Atan2(dz, dx); double dd = Math.Sqrt(dx * dx + dz * dz); if (throttleLogIsReady) { Console.WriteLine("goal h=" + h + " dd=" + dd + " dest= " + p.X + "," + p.Z); } if (dd < distanceToGoal) { if (execParameter != null) { doExec(); } break; } double dh = h - fface.Player.PosH; if (dh < -Math.PI) dh = 2 * Math.PI + dh; if (dh > Math.PI) dh = 2 * Math.PI - dh; double distanceError = 0.15; bool goalFar = dd > distanceToGoal; if (!goalFar || (-distanceError < dh && dh < distanceError)) { } else { turnMe.stopIt(); Thread.Sleep(100); SetNPCPosH(fface._InstanceID, fface.Player.ID, (float)h); Thread.Sleep(100); } if (dd > distanceToGoal) { turnMe.startRunning(); } } turnMe.stopIt(); } } }
public Patrole(FFACETools.FFACE fface) { this.turnMe = new TurnMe(fface); this.fface = fface; }
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(); }