예제 #1
0
        /// <summary>
        /// 寻找图片
        /// </summary>
        /// <param name="dm"></param>
        /// <param name="res"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool FindPic(dmsoft dm, ResourceEnum res, out int x, out int y)
        {
            var resource = ResourceFactory.GetResource(res);

            return(FindPic(dm, resource, out x, out y));
        }
예제 #2
0
        /// <summary>
        /// 登录游戏
        /// </summary>
        /// <returns></returns>
        private bool Login()
        {
            var dm = DMFactory.Instance.CreateDMSoft();

            // 获取窗口句柄
            var hwnd  = 0;
            var retry = 0;

            while (hwnd == 0)
            {
                Thread.Sleep(1000);
                hwnd = dm.FindWindowByProcessId(m_process.Id, "", "");
                retry++;
                WxLog.Debug($"AppEntity.Login Get Process Hwnd Retry <{retry}> ProcessID <{m_process.Id}>");
                if (retry > 5)
                {
                    WxLog.Debug($"AppEntity.Login Fail To Get Process Hwnd Retry <{retry}>");
                    return(false);
                }
            }

            WxLog.Debug($"AppEntity.Login Hwnd <{hwnd}>");

            // 获取登录窗的句柄
            var hwndStr = string.Empty;

            retry = 0;
            while (string.IsNullOrEmpty(hwndStr))
            {
                Thread.Sleep(1000);
                hwndStr = dm.EnumWindowByProcessId(m_process.Id, "", "Internet Explorer_Server", 2);
                WxLog.Debug($"AppEntity.Login Get Login Hwnd Retry <{retry}> hwndstr <{hwndStr}>");
                retry++;
                if (retry > 5)
                {
                    WxLog.Debug($"AppEntity.Login Fail To Get Login Hwnd Retry <{retry}>");
                    return(false);
                }
            }

            WxLog.Debug($"AppEntity.Login Result <{hwndStr}>");
            dm.BindWindow(int.Parse(hwndStr), "gdi", "windows", "windows", 101);
            var resource = ResourceFactory.GetResource(ResourceEnum.EnterGame);

            // 确认窗口打开
            var findResult = -1;

            retry = 0;
            while (findResult == -1)
            {
                Thread.Sleep(500);
                findResult = dm.FindPicMem(415, 257, 535, 365, resource.Info, "101010", 0.95, 3, out var x, out var y);
                WxLog.Debug($"AppEntity.Login Ensure Open X <{x}> Y <{y}> result<{findResult}> retry<{retry}>");
                retry++;
                if (retry > 5)
                {
                    WxLog.Debug($"AppEntity.Login Fail To Ensure Open Retry <{retry}>");
                    return(false);
                }
            }

            // 输入账号
            dm.MoveTo(324, 258);
            dm.LeftClick();
            Thread.Sleep(100);
            dm.SendString(int.Parse(hwndStr), m_account);
            dm.MoveTo(234, 291);
            dm.LeftClick();
            Thread.Sleep(100);
            dm.SendString(int.Parse(hwndStr), m_password);

            // 点击登录
            Thread.Sleep(100);
            dm.MoveTo(482, 322);
            dm.LeftClick();

            // 等待登录成功
            findResult = -1;
            resource   = ResourceFactory.GetResource(ResourceEnum.LoginSuccess);
            retry      = 0;
            while (findResult == -1)
            {
                Thread.Sleep(500);
                findResult = dm.FindPicMem(0, 0, 535, 365, resource.Info, "101010", 0.95, 3, out var x, out var y);
                WxLog.Debug($"AppEntity.Login Success X <{x}> Y <{y}> result<{findResult}> retry<{retry}>");
                retry++;
                if (retry > 5)
                {
                    WxLog.Debug($"AppEntity.Login Fail To Wait Success Retry <{retry}>");
                    return(false);
                }
            }

            // 切换到双线区
            dm.MoveTo(137, 123);
            dm.LeftClick();
            Thread.Sleep(100);
            dm.LeftClick();
            Thread.Sleep(100);
            dm.LeftClick();
            Thread.Sleep(100);
            dm.LeftClick();
            Thread.Sleep(100);

            // 开始寻找指定区服 523,226
            findResult = -1;
            resource   = ResourceFactory.GetResource(ResourceEnum.TargetServer);
            retry      = 0;
            while (findResult == -1)
            {
                findResult = dm.FindPicMem(0, 0, 535, 365, resource.Info, "101010", 0.95, 3, out var x, out var y);
                if (findResult == -1)
                {
                    dm.MoveTo(523, 226);
                    dm.WheelDown();
                    WxLog.Debug($"MainEntity.Login Find Target Server <{findResult}> retry<{retry}>");
                    Thread.Sleep(200);
                }
                else
                {
                    dm.MoveTo(int.Parse(x.ToString()), int.Parse(y.ToString()));
                    dm.LeftClick();
                    WxLog.Debug($"MainEntity.Login Find TargetServer Success X <{x}> Y <{y}> result<{findResult}>");
                }

                retry++;
                if (retry > 50)
                {
                    WxLog.Debug($"MainEntity.Login Fail To Find TargetServer Retry <{retry}>");
                    return(false);
                }
            }

            return(true);
        }