public void How2Dialog(MapCoordinate coor, int windowNum) { //获取当前地图 MoveBiz wbiz = new MoveBiz(windowNum); GameCommonUtil biz = new GameCommonUtil(); MapCoordinate nCoor = wbiz.GetNowMap(); bool flag = biz.CheckIsCloseToNPC(nCoor, coor); if (!flag) { //TODO,记录错误 return; } wbiz.PointPutToGameCoor(coor.coor); //先按F9,在Alt+H wbiz.PingBiPlayer(); WindowAPI.MMouseClick(1); Thread.Sleep(200); //checkDialog //Bitmap bm = PicUtil.GetScreen(); Point po = new Point(); //进入对话框了 if (!biz.HasDialogExist(windowNum, out po)) { Random ra = new Random(); int num = ra.Next(-1, 2); //没进入对话框 wbiz.MMoveRealCoor(num, num); How2Dialog(coor, windowNum); } }
/// <summary> /// 放到地图指定坐标, /// </summary> /// <param name="randomXS"></param> public void MPutToMapCoor(GameCoordinate targetGc, bool NeedGoThere) { Point po_nowdeskzuobiao = new Point(); string cityName = GetNowMap().CityName; City city = new City() { CityName = cityName, MapMaxGameCoor = new GameCoordinate(191, 119), MapSize = new int[2] { 441, 276 } }; po_nowdeskzuobiao = MPutToMayMapCenter(city, targetGc); if (NeedGoThere) { WindowAPI.MMouseClick(1); } try { MPutToMap(city, targetGc, NeedGoThere); } catch (HengTimeOutException ex) { if (ex.GetError() == "restart") { MPutToMapCoor(targetGc, NeedGoThere);//todo思考问题是否有 } } }
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); }
/// <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()); } }
///// <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)); }