Example #1
0
        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);
            //}
        }
Example #2
0
        private void AutoGenerateHotspot()
        {
            int spacing = 20;
            if (!(Int32.TryParse(txtSpacing.Text, out spacing)))
            {
                display("Hotspot spacing must be a numeric integer!");
                return;
            }

            if (oldloc == null)
            {
                oldloc = mylocation;
                return;
            }

            double dist = Distance(mylocation, oldloc);
            if (dist > spacing)
            {
                AddSpot(lstHotSpots, "Hotspot", mylocation);
                oldloc = mylocation;
            }
        }