Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pc"></param>
        public void JiaoZhunMouse(bool isAbsolute)
        {
            Point po = new Point();

            WindowAPI.GetCursorPos(out po);
            ResetPC();
            if (isAbsolute)
            {
                WindowAPI.MMouseMove(0, AbsolutePC[0], -AbsolutePC[1]);
            }
            else
            {
                WindowAPI.MMouseMove(0, RelativePC[0], -RelativePC[1]);
            }
        }
Пример #2
0
 /// <summary>
 /// 做了一堆容错,百度坑爹爹爹,相对稳定了
 /// </summary>
 /// <returns></returns>
 private void MPutToMap(City city, GameCoordinate targetGC_JQ, bool NeedGoThere)
 {
     try
     {
         Point po_nowdeskzuobiao = new Point();
         WindowAPI.GetCursorPos(out po_nowdeskzuobiao);
         //获取当前的游戏坐标
         GameCoordinate nowGameCoor = MapOcr(city, targetGC_JQ);
         int            x           = targetGC_JQ.X - nowGameCoor.X; //要移动的距离
         int            y           = targetGC_JQ.Y - nowGameCoor.Y; //要移动的距离
                                                                     //获取到理想的地址
         Point po_targetwdeskzuobiao = new Point((int)(po_nowdeskzuobiao.X + x * city.XS), (int)(po_nowdeskzuobiao.Y - y * city.XS));
         //前往该地址
         WindowAPI.MMouseMoveTo(0, po_targetwdeskzuobiao.X, po_targetwdeskzuobiao.Y);
         if (NeedGoThere)
         {
             WindowAPI.MMouseClick(1);
         }
         new GameCommonUtil().ThreadRest(2);
         //------------------
         //截图
         nowGameCoor = MapOcr(city, targetGC_JQ);
         if (nowGameCoor.X == -1)
         {
             Console.WriteLine("没颜色,重新来");
             throw new HengTimeOutException("没颜色,重新来");
         }
         if (Math.Abs(nowGameCoor.X - targetGC_JQ.X) < 3 && Math.Abs(nowGameCoor.Y - targetGC_JQ.Y) < 3)
         {
             Console.WriteLine("跳出");
             return;
         }
         Console.WriteLine("进入循环 x::" + Math.Abs(nowGameCoor.X - targetGC_JQ.X) + "y:" + Math.Abs(nowGameCoor.Y - targetGC_JQ.Y));
         //递归该方法
         MPutToMap(city, targetGC_JQ, NeedGoThere);
     }
     catch (HengTimeOutException ex)
     {
         throw new HengTimeOutException(ex.GetError());
     }
 }
Пример #3
0
        /// <summary>
        /// 根据桌面坐标获取返回当前坐标
        /// </summary>
        /// <param name="po"></param>
        /// <returns></returns>
        public GameCoordinate MapOcr(City city, GameCoordinate targetGC_JQ)
        {
            string words = "";
            int    isize = 3;

            string[]       strWords = { "0", "0" };
            GameCoordinate nowgc    = new GameCoordinate(0, 0);
            int            times    = 0;

            while (true)
            {
                if (times > 10)
                {
                    throw new HengTimeOutException("restart");
                }
                Point po_nowdeskzuobiao = new Point();
                WindowAPI.GetCursorPos(out po_nowdeskzuobiao);
                if (isize < 8)
                {
                    isize++;
                }
                try
                {
                    new GameCommonUtil().ThreadRest(2);
                    //获取到键盘的,然后截图大约是x-60 y-40 大小是120,80
                    Bitmap bm = PicUtil.GetScreen(po_nowdeskzuobiao.X - 50, po_nowdeskzuobiao.Y - 50, 100, 80);
                    // 处理坐标图像
                    // 1、截图
                    // 2、分析点图,黄色图片,减少变换量
                    // 3、颜色反转
                    // 4、放大图片
                    List <Point> lisp = PicCorFinder.FindColor(bm, "#FFFF00", Rectangle.Empty, 0);
                    if (lisp.Count == 0)
                    {
                        bm.Dispose();
                        return(new GameCoordinate(-1, -1));
                    }
                    bm = PicUtil.CaptureImage(bm, new Point(lisp[0].X - 10, lisp[0].Y - 8), 60, 25);
                    bm = PicUtil.ChangeColor(bm, Color.FromArgb(255, 255, 0));
                    //百度人工智能有一定错误率,主要95%集中在了,所以这边只要有,就放大图片重新识别,直到ok
                    Bitmap  bm2     = PicUtil.PicSized(bm, isize);
                    JObject jobject = PicUtil.BaiDuOCR(bm2);
                    JArray  jarr    = (JArray)jobject["words_result"];
                    //如果超出边界,移动移出来
                    if (jarr.Count == 0)
                    {
                        DoMove(targetGC_JQ);
                        bm2.Dispose();
                        bm.Dispose();
                        continue;
                    }
                    bm.Dispose();
                    bm2.Dispose();
                    bool flag = false;
                    for (int i = 0; i < jarr.Count; i++)
                    {
                        words = jarr[i]["words"].ToString();
                        flag  = StringUtil.IsNumber(words.Replace(",", ""));
                        if (flag)
                        {
                            break;
                        }
                    }
                    Console.WriteLine("words:" + words);
                    if (!words.Contains(',') || !flag)
                    {
                        //大概率没识别出来,就动下鼠标
                        Move11Step(city, targetGC_JQ, ref times);
                        continue;
                    }
                    strWords = words.Split(',');
                    nowgc    = new GameCoordinate(Convert.ToInt32(strWords[0]), Convert.ToInt32(strWords[1]));
                    //if (IsErrorRange(nowgc, targetGC_JQ, isize))
                    //{
                    //    //大概率没识别出来,就动下鼠标
                    //    Move11Step(city, targetGC_JQ, ref times);
                    //    continue;
                    //}
                    break;
                }
                catch (Exception)
                {
                    //大概率没识别出来,就动下鼠标
                    Move11Step(city, targetGC_JQ, ref times);
                    continue;
                }
            }
            return(nowgc);
        }