| | |
| | | using System.Windows.Controls; |
| | | using ZTImage.Configuration; |
| | | using ZTImage.Log; |
| | | using RichCreator.Utility.Maps; |
| | | using RichCreator.Dnf; |
| | | using System.Windows.Interop; |
| | | using RichCreator.Maps.Kalete; |
| | | using ZTImage.Collections; |
| | | using System.Collections.Generic; |
| | | |
| | | namespace RichCreator |
| | | { |
| | |
| | | /// <param name="e"></param> |
| | | private void Run_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | Int32 taskIndex = this.taskName.SelectedIndex; |
| | | MapType mapType = (MapType)this.taskName.SelectedIndex; |
| | | if (mapType == MapType.TestSpeed) |
| | | { |
| | | //测速 |
| | | G.Instance.InfoWriter("开始测速"); |
| | | TestSpeed(); |
| | | return; |
| | | } |
| | | else if (mapType == MapType.TestSkill) |
| | | { |
| | | //测技能 |
| | | G.Instance.InfoWriter("开始测技能"); |
| | | TestSkill(); |
| | | return; |
| | | } |
| | | else if (mapType == MapType.ReadRolePosition) |
| | | { |
| | | //读取角色位置 |
| | | G.Instance.InfoWriter("开始测角色位置"); |
| | | ReadRolePosition(); |
| | | return; |
| | | } |
| | | else if (mapType == MapType.TestToNextDoor) |
| | | { |
| | | //测试进入下一关的门 |
| | | G.Instance.InfoWriter("开始测进门"); |
| | | TestToNextDoor(); |
| | | return; |
| | | } |
| | | |
| | | if (isRunning) |
| | | { |
| | | monitor.Stop(); |
| | |
| | | } |
| | | G.Instance.DebugWriter("硬件检测通过"); |
| | | |
| | | this.monitor = new JobMonitor(taskIndex); |
| | | this.monitor = new JobMonitor(mapType); |
| | | monitor.Start(); |
| | | |
| | | startTaskUI(); |
| | |
| | | return DnfCVHelper.FindRole(hsvImage, new ZTRectangle(0, 0, 1280, 720)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 测速 |
| | | /// </summary> |
| | | private void TestSpeed() |
| | | { |
| | | ZTRectangle gameRect = ZTRectangle.Empty; |
| | | WindowUtils.GetDnfRect(out gameRect); |
| | | Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(gameRect.End.X - gameRect.Start.X + 1, gameRect.End.Y - gameRect.Start.Y + 1); |
| | | Task.Run(() => |
| | | { |
| | | WindowUtils.SetDnfToTop(); |
| | | Thread.Sleep(1000); |
| | | Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage(); |
| | | CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv); |
| | | ZTPoint start = DnfCVHelper.FindRole(hsvImage, gameRect); |
| | | |
| | | |
| | | G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, HIDCode.LeftArrow); |
| | | Thread.Sleep(30); |
| | | G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false); |
| | | Thread.Sleep(30); |
| | | G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, HIDCode.LeftArrow); |
| | | Thread.Sleep(800); |
| | | G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false); |
| | | |
| | | //G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, HIDCode.DownArrow); |
| | | //Thread.Sleep(1000); |
| | | //G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false); |
| | | |
| | | |
| | | |
| | | //G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false, HIDCode.LeftArrow); |
| | | //Thread.Sleep(1000); |
| | | //G.Instance.InputControl.PutDown(false, false, false, false, false, false, false, false); |
| | | |
| | | |
| | | image = ScreenCapture.Instance.CaptureScreenReturnImage(); |
| | | CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv); |
| | | ZTPoint end = DnfCVHelper.FindRole(hsvImage, gameRect); |
| | | |
| | | |
| | | G.Instance.InfoWriter($"from:{start},to:{end},distanceX:{end.X - start.X},distanceY:{end.Y - start.Y}"); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 测技能 |
| | | /// </summary> |
| | | private void TestSkill() |
| | | { |
| | | ZTRectangle gameRect = ZTRectangle.Empty; |
| | | WindowUtils.GetDnfRect(out gameRect); |
| | | Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(gameRect.End.X - gameRect.Start.X + 1, gameRect.End.Y - gameRect.Start.Y + 1); |
| | | Task.Run(() => { |
| | | WindowUtils.SetDnfToTop(); |
| | | Thread.Sleep(10); |
| | | |
| | | KaleteMap map = new KaleteMap(gameRect, CancellationToken.None); |
| | | Int32 lastHouseIndex = -1; |
| | | Int32 houseIndex = -1; |
| | | |
| | | while (true) |
| | | { |
| | | Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage(); |
| | | if (map.MiniMap.GetCurrentHouseIndex(out houseIndex, image)) |
| | | { |
| | | if (houseIndex != lastHouseIndex) |
| | | { |
| | | G.Instance.InfoWriter($"entry house:{houseIndex}"); |
| | | lastHouseIndex = houseIndex; |
| | | //发技能 |
| | | map.EntryHousePrework(houseIndex, lastHouseIndex); |
| | | } |
| | | } |
| | | Thread.Sleep(500); |
| | | } |
| | | |
| | | G.Instance.InfoWriter($"测试技能发放完成"); |
| | | }); |
| | | } |
| | | |
| | | private ZTPoint rolePosition = ZTPoint.Empty; |
| | | |
| | | /// <summary> |
| | | /// 读取角色位置 |
| | | /// </summary> |
| | | private void ReadRolePosition() |
| | | { |
| | | ZTRectangle gameRect = ZTRectangle.Empty; |
| | | WindowUtils.GetDnfRect(out gameRect); |
| | | Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(gameRect.End.X - gameRect.Start.X + 1, gameRect.End.Y - gameRect.Start.Y + 1); |
| | | Task.Run(() => { |
| | | WindowUtils.SetDnfToTop(); |
| | | Thread.Sleep(1000); |
| | | Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage(); |
| | | CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv); |
| | | rolePosition = DnfCVHelper.FindRole(hsvImage, gameRect); |
| | | |
| | | |
| | | G.Instance.InfoWriter($"角色位置读取成功:{rolePosition}"); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 测试进入下一关的门 |
| | | /// </summary> |
| | | private void TestToNextDoor() |
| | | { |
| | | HouseInfo house = new HouseInfo(0, MapType.Kalete, false, null); |
| | | |
| | | ZTRectangle gameRect = ZTRectangle.Empty; |
| | | WindowUtils.GetDnfRect(out gameRect); |
| | | Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(gameRect.End.X - gameRect.Start.X, gameRect.End.Y - gameRect.Start.Y ); |
| | | Task.Run(() => { |
| | | WindowUtils.SetDnfToTop(); |
| | | Thread.Sleep(10); |
| | | |
| | | Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage(); |
| | | image.ROI = new System.Drawing.Rectangle(gameRect.Start.X, gameRect.Start.Y, gameRect.End.X - gameRect.Start.X, gameRect.End.Y - gameRect.Start.Y); |
| | | CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv); |
| | | image.ROI = System.Drawing.Rectangle.Empty; |
| | | |
| | | //定位点 |
| | | ParametersPoint locationCoor = DnfCVHelper.GetLocationPoint(image, gameRect); |
| | | if (locationCoor.Equals(ParametersPoint.Empty)) |
| | | { |
| | | //找不到定位点 |
| | | G.Instance.InfoWriter("找不到定位点"); |
| | | return; |
| | | } |
| | | |
| | | ZTPoint rolePosition = DnfCVHelper.FindRole(hsvImage, gameRect); |
| | | ZTPoint start=house.ScreenToMapCoordinate(rolePosition, locationCoor); |
| | | |
| | | |
| | | |
| | | DnfRole role = new DnfRole(gameRect); |
| | | |
| | | Int32 doorIndex = 0; |
| | | List<ZTPoint> paths=house.FindDoorPath(out doorIndex,start); |
| | | ZTPoint last = start; |
| | | for (int i = 0; i < paths.Count; i++) |
| | | { |
| | | //移动 |
| | | ZTPoint distance = paths[i].Sub(last); |
| | | last = paths[i]; |
| | | role.SyncMove(distance); |
| | | } |
| | | |
| | | |
| | | |
| | | G.Instance.InfoWriter($"测试进入下一关的门完成"); |
| | | }); |
| | | } |
| | | |
| | | |
| | | #region 测试硬件 |
| | | //测试硬件的中间变量 |
| | |
| | | private bool TestHardware() |
| | | { |
| | | testTempVar = false; |
| | | ZTPoint btnPosition = ZTPoint.Empty; |
| | | ZTPoint txtPosition = ZTPoint.Empty; |
| | | Utility.Structs.ZTPoint btnPosition = Utility.Structs.ZTPoint.Empty; |
| | | Utility.Structs.ZTPoint txtPosition = Utility.Structs.ZTPoint.Empty; |
| | | using (ManualResetEvent mre = new ManualResetEvent(false)) |
| | | { |
| | | //等待读取位置成功 |
| | |
| | | private ZTPoint GetElementClickPosition(Control element) |
| | | { |
| | | Point t = element.PointToScreen(new Point(0, 0)); |
| | | ZTPoint t1 = new ZTPoint((Int32)(t.X + element.ActualWidth / 2), (Int32)(t.Y + element.ActualHeight / 2)); |
| | | Utility.Structs.ZTPoint t1 = new Utility.Structs.ZTPoint((Int32)(t.X + element.ActualWidth / 2), (Int32)(t.Y + element.ActualHeight / 2)); |
| | | return t1; |
| | | } |
| | | #endregion |
| | |
| | | isRunning = false; |
| | | })); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | private int hotKeyID = 2839; |
| | | /// <summary> |
| | | /// 热键消息 |
| | | /// </summary> |
| | | const int WindowsMessageHotkey = 786; |
| | | |
| | | private void Window_Loaded(object sender, RoutedEventArgs e) |
| | | { |
| | | //注册热键 |
| | | IntPtr intPtr = (new WindowInteropHelper(this)).Handle; |
| | | if (!SystemHotKey.RegHotKey(intPtr, hotKeyID, SystemHotKey.KeyModifiers.None, System.Windows.Forms.Keys.Home)) |
| | | { |
| | | MessageBox.Show("热键不可用,其它应用已经占用热键"); |
| | | } |
| | | else |
| | | { |
| | | ComponentDispatcher.ThreadPreprocessMessage += (ref MSG Message, ref bool Handled) => |
| | | { |
| | | // 判断是否热键消息 |
| | | if (Message.message == WindowsMessageHotkey) |
| | | { |
| | | // 获取热键id |
| | | var id = Message.wParam.ToInt32(); |
| | | // 执行热键回调方法(执行时需要判断是否与注册的热键匹配) |
| | | if (id == hotKeyID) |
| | | { |
| | | Run_Click(this, new RoutedEventArgs()); |
| | | } |
| | | |
| | | } |
| | | }; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | private void Window_Unloaded(object sender, RoutedEventArgs e) |
| | | { |
| | | //注销热键 |
| | | IntPtr intPtr = (new WindowInteropHelper(this)).Handle; |
| | | SystemHotKey.UnRegHotKey(intPtr, hotKeyID); |
| | | } |
| | | } |
| | | } |