Example #1
0
        /// <summary>
        /// 获取偏差值,最终都可以用加这个偏差,到一个精准位置,进入每个地图要重新计算偏差
        /// </summary>
        /// <param name="windowNum"></param>
        /// <returns></returns>
        public int[] GetPC(int windowNum)
        {
            Point p      = Singleton.GetInstance().dicWindows[windowNum].Point;
            Point liLunP = new Point();

            WindowAPI.GetCursorPos(out liLunP);
            //Console.WriteLine("理论点位" + liLunP.X + "," +liLunP.Y);
            WindowAPI.MMouseMoveTo(0, liLunP.X, liLunP.Y);
            Point p1 = new Point(liLunP.X - 75, liLunP.Y - 75);

            Thread.Sleep(100);
            Bitmap       bm    = PicUtil.GetScreen(p1.X, p1.Y, 150, 150);
            List <Point> listp = new List <Point>();

            try
            {
                listp = PicCorFinder.FindPicture(Singleton.GetInstance().PicRootDir + "ms.png", bm, Rectangle.Empty, 0, 0.6);
                if (listp.Count == 0)
                {
                    listp = PicCorFinder.FindPicture(Singleton.GetInstance().PicRootDir + "ms2.png", bm, Rectangle.Empty, 0, 0.6);
                }
            }
            catch (Exception ex)
            {
                log.Error("解析偏差时图片解析错误:" + DateTime.Now.ToString("yyyyMMddHHmmss") + ex);
                bm.Save(Singleton.GetInstance().PicRootDir + "ErrorPic/GetPC/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png");
                return(GetPC(windowNum));
            }
            bm.Dispose();
            if (listp.Count == 0)
            {
                Console.WriteLine("查找失败");
                return(GetPC(windowNum));
            }
            else
            {
                int min  = 10000;
                int pcx1 = 0;
                int pcy1 = 0;
                for (int i = 0; i < listp.Count; i++)
                {
                    //找到点位
                    int pcx = 75 - (listp[i].X - 20);
                    int pcy = 75 - (listp[i].Y - 20);
                    if (pcx + pcy <= min)
                    {
                        min  = pcx + pcy;
                        pcx1 = pcx;
                        pcy1 = pcy;
                    }
                    if (i > 0)
                    {
                        Console.WriteLine("找到记录2次++");
                    }
                }
                return(new int[2] {
                    pcx1, pcy1
                });
            }
        }
Example #2
0
        public void PutToPosition(int windowNum, int plusX, int minusY, int randomX, int randomY)
        {
            Random ra     = new Random();
            int    rx     = ra.Next(-1 * randomX, randomX);
            int    ry     = ra.Next(-1 * randomY, randomY);
            Point  p      = Singleton.GetInstance().dicWindows[windowNum].Point;
            Point  liLunP = new Point(p.X + plusX, p.Y - minusY);

            //Console.WriteLine("理论点位" + liLunP.X + "," +liLunP.Y);
            WindowAPI.MMouseMoveTo(0, liLunP.X, liLunP.Y);
            Point p1 = new Point(liLunP.X - 75, liLunP.Y - 75);

            Thread.Sleep(100);
            Bitmap bm = PicUtil.GetScreen(p1.X, p1.Y, 150, 150);
            //bm.Save("D://pic/" + a + ".png");
            List <Point> listp = PicCorFinder.FindPicture(Singleton.GetInstance().PicRootDir + "ms.png", bm, Rectangle.Empty, 0, 0.6);

            bm.Dispose();
            if (listp.Count == 0)
            {
                Console.WriteLine("查找失败");
                Point rp = GetWinRandomPoint();
                WindowAPI.MMouseMoveTo(0, rp.X, rp.Y);
                PutToPosition(windowNum, plusX, minusY, randomX, randomY);
            }
            else
            {
                int min  = 10000;
                int pcx1 = 0;
                int pcy1 = 0;
                for (int i = 0; i < listp.Count; i++)
                {
                    //找到点位
                    int pcx = 75 - (listp[i].X - 20);
                    int pcy = 75 - (listp[i].Y - 20);
                    if (pcx + pcy <= min)
                    {
                        min  = pcx + pcy;
                        pcx1 = pcx;
                        pcy1 = pcy;
                    }
                    if (i > 0)
                    {
                        Console.WriteLine("找到记录2次++");
                    }
                }
                Point RealP = new Point(liLunP.X + pcx1 + rx, liLunP.Y + pcy1 + ry);
                WindowAPI.MMouseMoveTo(0, RealP.X, RealP.Y);
            }
        }
Example #3
0
        public Point GetGameCursorPosition(int windowNum)
        {
            Point        p1    = Singleton.GetInstance().dicWindows[windowNum].Point;
            Bitmap       bm    = PicUtil.GetScreen(p1.X, p1.Y - 480, 640, 480);
            List <Point> listp = PicCorFinder.FindPicture(Singleton.GetInstance().PicRootDir + "ms.png", bm, Rectangle.Empty, 0);

            bm.Dispose();
            if (listp.Count == 0)
            {
                return(new Point(0, 0));
            }
            else
            {
                return(listp[0]);
            }
        }
Example #4
0
        /// <summary>
        /// 是否dialog已经打开,任意dialog
        /// </summary>
        /// <returns></returns>
        public bool HasDialogExist(int WindowNum, out Point po)
        {
            WindowAPI.MMouseMoveTo(0, 0, 0);
            po = new Point(0, 0);
            Point         point       = Singleton.GetInstance().dicWindows[WindowNum].Point;
            Bitmap        bm          = PicUtil.GetScreen(point.X, point.Y - 480, 640, 480);
            string        subPic      = Singleton.GetInstance().PicRootDir + "dialog\\对话框.png";
            string        subPic2     = Singleton.GetInstance().PicRootDir + "dialog\\对话框2.png";
            List <string> listsubPic2 = new List <string>();

            listsubPic2.Add(subPic);
            listsubPic2.Add(subPic2);
            for (int i = 0; i < listsubPic2.Count; i++)
            {
                List <Point> listPo = PicCorFinder.FindPicture(subPic, bm, Rectangle.Empty, 10);
                if (listPo.Count > 0)
                {
                    po = listPo[0];
                    return(true);
                }
            }
            return(false);
        }