/// <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); } }
/// <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)); }
/// <summary> /// 检查Dialog打开状态 /// </summary> /// <param name="dialogName"></param> /// <returns></returns> public bool CheckDialogStatus(string dialogName) { //移动鼠标到边上 MoveToConer(); string subPic = Singleton.GetInstance().PicRootDir + "dialog\\" + dialogName + ".png"; if (!File.Exists(subPic)) { log.Error("不存在路径" + subPic); return(false); } Bitmap bm = PicUtil.GetScreen(CenterPoint.X, CenterPoint.Y - 240, 320, 240); List <Point> list = PicCorFinder.FindPicture(subPic, bm, Rectangle.Empty, 2); //没有被找到 if (list.Count == 0) { return(false); } else { return(true); } }
/// <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); }
///// <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)); }