Пример #1
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));
        }