private WoWPoint PointToWoWPoint(HotspotRecorderPlugin.XYZ spot) { return new WoWPoint(spot.X, spot.Y, spot.Z); }
public void On_Update(HotspotRecorderPlugin.CustomEventArgs args) { //try //{ string fmt = "{0:0.000}, {1:0.000}, {2:0.000}"; targetlocation = args.targetlocation; targetname = args.targetname; targetentry = args.targetentry; isrepair = args.isrepair; mylocation = args.mylocation; CalculateClosestHotspot(); // Do a thread-safe update on the fields // (this routine (On_Update) is called by an external thread.) this.lblLocationNPC.Invoke((MethodInvoker)(() => lblLocationNPC.Text = (targetlocation == null ? "<target location>" : string.Format(fmt, targetlocation.X, targetlocation.Y, targetlocation.Z)))); this.lblLocationMe.Invoke((MethodInvoker)(() => lblLocationMe.Text = (mylocation == null ? "<my location>" : string.Format(fmt, mylocation.X, mylocation.Y, mylocation.Z)))); this.lblNPCName.Invoke((MethodInvoker)(() => lblNPCName.Text = (targetname == null ? "<target name>" : targetname))); if (queue.Count > 0) { int commandcnt = queue.Count; Cursor.Current = Cursors.WaitCursor; for (int i = 0; i < commandcnt; i++) { KeyValuePair<string, object> kvp = queue.Dequeue(); display("Executing queued command {0} of {1}", i + 1, commandcnt); switch (kvp.Key) { case "goto": autorun = true; HotspotRecorderPlugin.XYZ xyz = (HotspotRecorderPlugin.XYZ)kvp.Value; display("Go to {0:0.0000}, {1:0.0000}, {2:0.0000}", xyz.X, xyz.Y, xyz.Z); if (StyxWoW.Me == null) return; WoWPoint pt = new WoWPoint(xyz.X, xyz.Y, xyz.Z); while (autorun && StyxWoW.Me.Location.Distance(pt) >= 5 && (Styx.CommonBot.BotManager.Current.Name == "Grind Bot" || !StyxWoW.Me.Combat)) { CalculateClosestHotspot(); Navigator.MoveTo(pt); Thread.Sleep(500); } if (StyxWoW.Me.Combat && StyxWoW.Me.Mounted) Styx.CommonBot.Mount.Dismount(); break; case "run": autorun = true; List<HotspotRecorderPlugin.XYZ> list2 = (List<HotspotRecorderPlugin.XYZ>)kvp.Value; int startpt = Math.Max(closesthotspot, 0); List<int> indexes = new List<int>(); for (int j = startpt; j < list2.Count; j++) indexes.Add(j); for (int j = 0; j < startpt; j++) indexes.Add(j); for (int j = 0; j < indexes.Count; j++) { if (!autorun || (StyxWoW.Me.Combat && Styx.CommonBot.BotManager.Current.Name != "Grind Bot")) break; WoWPoint pt2 = PointToWoWPoint(list2[indexes[j]]); display("Running to point {0} {1}", indexes[j], list2[indexes[j]].ToString()); while (autorun && StyxWoW.Me.Location.Distance(pt2) >= 5 && (Styx.CommonBot.BotManager.Current.Name == "Grind Bot" || !StyxWoW.Me.Combat)) { CalculateClosestHotspot(); Navigator.MoveTo(pt2); Thread.Sleep(500); } } if (StyxWoW.Me.Combat && StyxWoW.Me.Mounted) Styx.CommonBot.Mount.Dismount(); break; case "CheckHotspots": List<HotspotRecorderPlugin.XYZ> list = (List<HotspotRecorderPlugin.XYZ>)kvp.Value; for (int j = 0; j < list.Count; j++) list[j].navigable = true; this.Invoke((MethodInvoker)(() => toolStripProgressBar1.Maximum = list.Count)); int badpts = 0; for (int j = 1; j < list.Count; j++) { this.Invoke((MethodInvoker)(() => toolStripProgressBar1.Value = j)); if (StyxWoW.Me == null) { // Do a fake check here. if (j % 10 == 0) { list[j].navigable = false; badpts++; } } else { // Do a real check here. if (!Styx.Pathing.Navigator.CanNavigateFully(PointToWoWPoint(list[j - 1]), PointToWoWPoint(list[j]))) { list[j].navigable = false; badpts++; } } } display("Done checking hotspots, {0} bad points found out of a total of {1}.", badpts, list.Count); checkedpoints = list; this.Invoke((MethodInvoker)(() => toolStripProgressBar1.Value = list.Count)); break; default: display("Unknown command {0}!", kvp.Key); break; } display("Done executing queued command {0} of {1}", i + 1, commandcnt); } Cursor.Current = Cursors.Default; } //} //catch (Exception ex) //{ // if (!(ex is System.Threading.ThreadAbortException)) // HandleError(ex); //} }
private string PointToString(string spottype, HotspotRecorderPlugin.XYZ spot) { string suffix = string.Empty; if (spottype.ToLower() == "blackspot") suffix = string.Format(@"Radius=""{0}""", this.txtBlackspotRadius.Text); string s = string.Format(culture, @"<{0} X=""{1:0.0000}"" Y=""{2:0.0000}"" Z=""{3:0.0000}"" {4} />", spottype, spot.X, spot.Y, spot.Z, suffix); return s; }
private string PointToVendorString(string vendorname, int entry, string vendortype, HotspotRecorderPlugin.XYZ spot) { string s = string.Format(culture, @"<Vendor Name=""{0}"" Entry=""{1}"" Type=""{2}"" X=""{3:0.0000}"" Y=""{4:0.0000}"" Z=""{5:0.0000}"" />", vendorname, entry, vendortype, spot.X, spot.Y, spot.Z); return s; }
private void GoTo(HotspotRecorderPlugin.XYZ xyz) { // Go to the specified point in WoW, on the next pulse. // Don't do it right away! You will probably fail with memory read errors. // Just stuff it in a queue, and wait for the next 'On_Update' to execute it. queue.Enqueue(new KeyValuePair<string, object>("goto", xyz)); }
private void Form1_Load(object sender, EventArgs e) { updateui = new HotspotRecorderPlugin.UpdateUIDelegate(On_Update); if (StyxWoW.Me == null) { // Create the plugin manually since we're testing in standalone mode. fakeplugin = new HotspotRecorderPlugin(); newThread = new System.Threading.Thread(fakeplugin.MessagePump); newThread.Start(); } HotspotRecorderPlugin.UpdateUI += updateui; timer1.Enabled = true; this.TopMost = true; this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height); this.Size = new Size(this.Width + 1, this.Height); }
private double FastDistance(HotspotRecorderPlugin.XYZ pt1, HotspotRecorderPlugin.XYZ pt2) { double x = pt2.X - pt1.X; double y = pt2.Y - pt1.Y; double z = pt2.Z - pt1.Z; return x * x + y * y + z * z; }
private double Distance(HotspotRecorderPlugin.XYZ pt1, HotspotRecorderPlugin.XYZ pt2) { double x = pt2.X - pt1.X; double y = pt2.Y - pt1.Y; double z = pt2.Z - pt1.Z; return Math.Sqrt(x * x + y * y + z * z); }
private void AddVendor(ListView lb, string vendorname, int entry, string vendortype, HotspotRecorderPlugin.XYZ spot) { try { if (spot == null) throw new Exception("Spot is null"); lb.Items.Add(PointToVendorString(vendorname, entry, vendortype, spot)); //int visibleItems = lb.ClientSize.Height / lb.ItemHeight; //lb.TopIndex = Math.Max(lb.Items.Count - visibleItems + 1, 0); ClearPoints(); } catch (Exception ex) { HandleError(ex); } }