コード例 #1
0
ファイル: ToolSkillBiz.cs プロジェクト: zhaohengheng123/Heng
        /// <summary>
        /// 检查toolName是否存在
        /// </summary>
        /// <param name="toolName"></param>
        /// <returns></returns>
        public bool CheckToolsStatus(string toolName)
        {
            //移动鼠标到边上
            MoveToConer();
            string subPic = Singleton.GetInstance().PicRootDir + "tools\\" + toolName + ".png";

            if (!File.Exists(subPic))
            {
                log.Error("不存在路径" + subPic);
                return(false);
            }
            Bitmap       bm   = PicUtil.GetScreen(CenterPoint.X + 200, CenterPoint.Y + 40, 120, 200);
            List <Point> list = PicCorFinder.FindPicture(subPic, bm, Rectangle.Empty, 2);

            //没有被找到
            if (list.Count == 0)
            {
                return(false);
            }
            else
            {
                Point p1 = Singleton.GetInstance().dicWindows[WindowNum].Point;
                WindowAPI.MMouseMoveTo(0, p1.X + 540, p1.Y - 170);
                return(true);
            }
        }
コード例 #2
0
ファイル: BaseBiz.cs プロジェクト: zhaohengheng123/Heng
 /// <summary>
 /// 必须是静止状态才可调用
 /// </summary>
 public void MPutToPerson()
 {
     //线程休眠2秒,使得人物处于屏幕正中央!
     //TODO,需后续测试休眠时间,因为含图片计算等等耗费不少时间,所以初步预计一般2秒够了
     //移动的时候肯定不准了
     WindowAPI.MMouseMoveTo(0, CenterPoint.X, CenterPoint.Y);
     JiaoZhunMouse(true);
     Thread.Sleep(50);
 }
コード例 #3
0
ファイル: BaseBiz.cs プロジェクト: zhaohengheng123/Heng
        public void ActiveWindow()
        {
            Thread.Sleep(30);
            Point p1 = Singleton.GetInstance().dicWindows[WindowNum].Point;

            //窗口快速移动
            WindowAPI.MMouseMoveTo(0, p1.X + StringUtil.GetRandomNum(320, 8), p1.Y - StringUtil.GetRandomNum(508, 2));
            WindowAPI.MMouseClick(1);
        }
コード例 #4
0
 public void MMoveToRealCoor(int x, int y)
 {
     new GameCommonUtil().ThreadRest(2);
     PingBiPlayer();
     //初始化目标地址
     WindowAPI.MMouseMoveTo(0, CenterPoint.X + Singleton.GetInstance().GameBili *x, CenterPoint.Y + y * Singleton.GetInstance().GameBili);
     //校准偏差
     JiaoZhunMouse(true);
 }
コード例 #5
0
        /// <summary>
        /// 放到地图指定坐标TODO,少了个系数!!!
        /// </summary>
        /// <param name="randomXS"></param>
        private Point MPutToMayMapCenter(City city, GameCoordinate targetGc)
        {
            //20为误差阈值,其实阈值15已经很高了,不会超过20的!
            //计算预估坐标
            //TODO  15这个觉得没什么大问题,测试多次能正确放置
            int numX = (int)(city.MapMaxGameCoor.X / 15);
            int numY = (int)(city.MapMaxGameCoor.Y / 15);
            int x = 0; int y = 0;

            //如果4个点均是在内切20px范围的,直接转移进入
            if (targetGc.X > numX && (Math.Abs(city.MapMaxGameCoor.X - targetGc.X) > numX))
            {
                x = (int)((targetGc.X - city.MapCenterCoor.X) * city.XS) + CenterPoint.X;
            }
            else
            {
                if (targetGc.X <= numX)
                {
                    x = (int)((targetGc.X - city.MapCenterCoor.X) * city.XS) + CenterPoint.X + (int)((numX - targetGc.X) * city.XS);
                }
                else
                {
                    x = (int)((targetGc.X - city.MapCenterCoor.X) * city.XS) + CenterPoint.X - (int)((numX - city.MapMaxGameCoor.X + targetGc.X) * city.XS);
                }
            }


            if (targetGc.Y > numY && (Math.Abs(city.MapMaxGameCoor.Y - targetGc.Y) > numY))
            {
                y = CenterPoint.Y - (int)((targetGc.Y - city.MapCenterCoor.Y) * city.XS);
            }
            else
            {
                if (targetGc.Y <= numY)
                {
                    y = CenterPoint.Y - (int)((targetGc.Y - city.MapCenterCoor.Y) * city.XS) - (int)((numY - targetGc.Y) * city.XS);
                }
                else
                {
                    y = CenterPoint.Y - (int)((targetGc.Y - city.MapCenterCoor.Y) * city.XS) + (int)((numY - city.MapMaxGameCoor.Y + targetGc.Y) * city.XS);
                }
            }
            //mayPoint = new Point(CenterPoint.X + targetGc.X - city.MapCenterCoor.X, city.MapCenterCoor.Y - targetGc.Y + CenterPoint.Y);
            WindowAPI.MMouseMoveTo(0, x, y);
            Thread.Sleep(100);
            return(new Point(x, y));
        }
コード例 #6
0
        /// <summary>
        /// 获取所需用时
        /// </summary>
        /// <param name="cityName"></param>
        /// <returns></returns>
        public int GetWalkSeconds(string cityName)
        {
            WindowAPI.MMouseMoveTo(0, 0, 0);
            Point  p1 = Singleton.GetInstance().dicWindows[WindowNum].Point;
            Bitmap bm = PicUtil.GetScreen(p1.X, p1.Y - 480, 640, 480);
            //数点的个数,100px与等于15秒,ZZ100px约等于10点,1个点的时间2.3倍
            //平均每个点为3.5/XS
            City city = new City()
            {
                CityName       = cityName,
                MapMaxGameCoor = new GameCoordinate(191, 119),
                MapSize        = new int[2] {
                    441, 276
                }
            };
            List <Point> list = PicCorFinder.FindPicture(Singleton.GetInstance().PicRootDir + "wp.png", bm, Rectangle.Empty, 2, 0.9, true);

            //额外加出3个点,防止几类情况 1、最后个棋子的挡住1个+自己一个2、大红点挡住一个
            return((int)((list.Count + 3) * 3.5 / city.XS));
        }
コード例 #7
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());
     }
 }
コード例 #8
0
ファイル: ToolSkillBiz.cs プロジェクト: zhaohengheng123/Heng
 private void MoveToConer()
 {
     WindowAPI.MMouseMoveTo(0, 0, 0);
 }
コード例 #9
0
        ///// <summary>
        ///// 过时方法
        ///// </summary>
        ///// <param name="listgc"></param>
        ///// <returns></returns>
        //[Obsolete]
        //private bool CheckJiaoZhunStatus(List<GameCoordinate> listgc)
        //{
        //    GameCoordinate gc_3 = new GameCoordinate();
        //    GameCoordinate gc_2 = new GameCoordinate();
        //    int resize = 11;
        //    if (listgc.Count > 2)
        //    {
        //        if (listgc.Count == 4)
        //        {
        //            resize = 3;
        //        }
        //        else
        //        {
        //            resize = 6;
        //        }
        //        //取得最近的2次
        //        gc_3 = listgc[listgc.Count - 1];
        //        gc_2 = listgc[listgc.Count - 2];
        //        GameCoordinate gc_1 = listgc[listgc.Count - 3];
        //        if (gc_3.X == gc_2.X && gc_3.Y == gc_2.Y)
        //        {
        //            if (gc_1.X == gc_2.X && gc_1.Y == gc_2.Y)
        //            {
        //                //都没动的话很有问题了,肯定到了什么阻挡物了,比如一些特别的东西,阻止掉继续矫正的势头!
        //                return true;
        //            }
        //        }
        //    }
        //    else
        //    {
        //        gc_3 = listgc[listgc.Count - 1];
        //        gc_2 = listgc[listgc.Count - 2];
        //    }
        //    //比较gc3,gc2,坐标差太大了,肯定不是平路了,所以去搞他一下
        //    if (Math.Abs(gc_3.X - gc_2.X) > 3 || Math.Abs(gc_3.Y - gc_2.Y) > 3)
        //    {
        //        return true;
        //    }
        //    #region 正规校验开始
        //    bool xok = false;
        //    bool yok = false;
        //    //等于0,鼠标过于靠左
        //    if (gc_3.X - gc_2.X == 1)
        //    {
        //        //x轴无问题的!
        //        xok = true;
        //    }
        //    else
        //    {
        //        this.CenterPoint = new Point(this.CenterPoint.X - resize * (gc_3.X - (gc_2.X + 1)), this.CenterPoint.Y);
        //    }
        //    if (gc_3.Y - gc_2.Y == 1)
        //    {
        //        //y轴无问题的!
        //        yok = true;
        //    }
        //    else
        //    {
        //        this.CenterPoint = new Point(this.CenterPoint.X, this.CenterPoint.Y + resize * (gc_3.Y - (gc_2.Y + 1)));
        //    }
        //    if (xok && yok)
        //    {
        //        return true;
        //    }
        //    return false;
        //    #endregion
        //}

        ///// <summary>
        ///// 校准位置,走一步截图,测试下
        ///// </summary>
        //[Obsolete]
        //public bool JiaoZhunPosition()
        //{
        //    List<GameCoordinate> listgc = new List<GameCoordinate>();
        //    GameCoordinate gc = GetNowMap().coor;
        //    listgc.Add(gc);
        //    bool flag = false;
        //    //最多进行3次校正,递归有点疯狂的
        //    for (int i = 0; i < 4; i++)
        //    {
        //        MMoveRealCoor(1, 1);
        //        GameCoordinate gc2 = GetNowMap().coor;
        //        listgc.Add(gc2);
        //        //比较gc和gc2
        //        flag = CheckJiaoZhunStatus(listgc);
        //        if (flag)
        //        {
        //            break;
        //        }
        //    }
        //    return flag;
        //}

        #endregion



        /// <summary>
        /// 做了一堆容错,相对稳定了,获取目前所在区域
        /// 确认,必须在开始调用的!dialog打开前!!
        /// </summary>
        /// <returns></returns>
        public MapCoordinate GetNowMap()
        {
            WindowAPI.MMouseMoveTo(0, 0, 0);//移开防止挡住地图视线
            string zuobiao = "";

            while (true)
            {
                //获取当前窗口
                Point  point = Singleton.GetInstance().dicWindows[WindowNum].Point;
                Bitmap bm    = PicUtil.GetScreen(point.X + 15, point.Y - 454, 120, 16);
                //百度人工智能有一定错误率,主要95%集中在了,所以这边只要有,就放大图片重新识别,直到ok
                for (int i = 6; i < 15; i++)
                {
                    Bitmap  bm2 = PicUtil.PicSized(bm, i);
                    JObject j   = PicUtil.BaiDuOCR(bm2);
                    bm2.Dispose();
                    zuobiao = j["words_result"][0]["words"].ToString();
                    if (zuobiao.Contains(","))
                    {
                        break;
                    }
                    else
                    {
                        #region ,不容易被识别,做了一堆容错
                        string zuobiaocoor = zuobiao.Split('[')[1].Trim(']').Trim();
                        //2位的,肯定中间是,
                        if (zuobiaocoor.Length == 2)
                        {
                            zuobiaocoor = zuobiaocoor.Substring(0, 1) + "," + zuobiaocoor.Substring(1, 1);
                        }
                        else if (zuobiaocoor.Length == 3)
                        {
                            continue;
                        }
                        else if (zuobiaocoor.Length == 4)
                        {
                            //,如果在第二个,则第二位不应  如果是6766
                            if (Convert.ToInt32(zuobiaocoor.Substring(1, 1)) > 3)//则绝不可能分在第1个
                            {
                                //考虑分第3个,
                                if (Convert.ToInt32(zuobiaocoor.Substring(0, 1)) > 5)//绝不可能大于5
                                {
                                    zuobiaocoor = zuobiaocoor.Substring(0, 2) + "," + zuobiaocoor.Substring(2, 2);
                                }
                            }
                        }
                        else if (zuobiaocoor.Length == 5)                         //绝对是从第二个分
                        {
                            if (Convert.ToInt32(zuobiaocoor.Substring(2, 1)) > 3) //如果大于3,肯定分
                            {
                                if (Convert.ToInt32(zuobiaocoor.Substring(0, 1)) <= 5)
                                {
                                    zuobiaocoor = zuobiaocoor.Substring(0, 3) + "," + zuobiaocoor.Substring(3, 2);
                                }
                            }
                            else
                            {
                                if (Convert.ToInt32(zuobiaocoor.Substring(0, 1)) > 5)
                                {
                                    zuobiaocoor = zuobiaocoor.Substring(0, 2) + "," + zuobiaocoor.Substring(2, 3);
                                }
                            }
                        }
                        else
                        {
                            zuobiaocoor = zuobiaocoor.Substring(0, 3) + "," + zuobiaocoor.Substring(3, 3);
                        }
                        #endregion
                        if (!StringUtil.IsNumber(zuobiaocoor.Replace(",", "")))
                        {
                            continue;
                        }
                        zuobiao = zuobiao.Split('[')[0] + "[" + zuobiaocoor + "]";
                    }
                }
                if (!zuobiao.Contains(","))
                {
                    //TODO,关闭所有栏目,确认,必须在开始调用的!
                    MMoveRealCoor(2, 2);//随便走个几步
                    WindowAPI.MMouseClick(1);
                    bm.Dispose();
                }
                else
                {
                    bm.Dispose();
                    break;
                }
            }
            return(StringUtil.AnalyzeMapStr(zuobiao));
        }