asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
src/RichCreator/Jobs/WeGameJob.cs
@@ -34,20 +34,44 @@
            Process.Start(this.Config.TGPDaemonPath);
            G.Instance.InfoWriter("等待We Game运行");
            ZTRectangle weGameRect = ZTRectangle.Empty;
            ZTRectangle changeLoginMethodButtonRect = ZTRectangle.Empty;
            ZTRectangle changeMethodRect = ZTRectangle.Empty;
            bool result = false;
            //查找游戏并设为帐号密码登陆
            Int32 counter = 3;
            while (counter>0)
            {
                bool isQQFast = false;
            //查找游戏
            bool result = FindWeGame(cancellationToken, 5 * 60, out weGameRect,out changeLoginMethodButtonRect);
                result = FindWeGame(out isQQFast, cancellationToken, 5 * 60, out weGameRect, out changeMethodRect);
            if (!result)
            {
                G.Instance.InfoWriter("查找游戏失败");
                return ZTResult.Failed;
            }
            G.Instance.InfoWriter("WeGame于:" + weGameRect.ToString() + ",切换按钮于:" + changeLoginMethodButtonRect.ToString());
                if (isQQFast)
                {
                    //qq快速登陆
                    G.Instance.InputControl.MoveToAndClick(changeMethodRect.GetCenterPoint());
                    Thread.Sleep(500);
                }
                else
                {
                    break;
                }
                counter--;
            }
            G.Instance.InfoWriter("WeGame于:" + weGameRect.ToString() + ",切换按钮于:" + changeMethodRect.ToString());
            
            //登陆
            result = LoginWeGame(cancellationToken, 30, weGameRect, changeLoginMethodButtonRect);
            result = LoginWeGame(cancellationToken, 30, weGameRect, changeMethodRect);
            if (!result)
            {
                G.Instance.InfoWriter("登陆失败");
@@ -56,10 +80,10 @@
            G.Instance.InfoWriter("WeGame登陆成功");
            
            //登陆DNF游戏
            result = LoginDNF(cancellationToken, 30);
            result = LoginDNF(cancellationToken, 30,weGameRect);
            if (!result)
            {
                G.Instance.InfoWriter("DNF未成功打开");
                G.Instance.InfoWriter("DNF启动未成功");
                return ZTResult.Failed;
            }
            G.Instance.InfoWriter("开始启动DNF游戏");
@@ -77,15 +101,16 @@
        /// <param name="loginMethod">当前登陆方式,0:QQ快速登陆,1:码密登陆</param>
        /// <param name="changeLMButtonRectangle">切换登陆方式按钮区域</param>
        /// <returns></returns>
        private bool FindWeGame(CancellationToken cancelToken, Int64 timeoutSecond, out ZTRectangle wegameRect, out ZTRectangle changeButtonRect)
        private bool FindWeGame(out bool isQQFastLogin,CancellationToken cancelToken, Int64 timeoutSecond, out ZTRectangle wegameRect, out ZTRectangle changeButtonRect)
        {
            ZTRectangle weGameRect = ZTRectangle.Empty;
            ZTRectangle changeLoginMethodButtonRect = ZTRectangle.Empty;
            bool isfl = false;
            bool result=FuncUtils.TimeoutCancelableWrap((Int32)timeoutSecond * 1000, cancelToken, () => {
                return WeGameCVHelper.IsLoginPage(out weGameRect, out changeLoginMethodButtonRect);
                return WeGameCVHelper.IsLoginPage(out isfl,out weGameRect, out changeLoginMethodButtonRect);
            });
            isQQFastLogin = isfl;
            wegameRect = weGameRect;
            changeButtonRect = changeLoginMethodButtonRect;
            return result;
@@ -132,7 +157,7 @@
        /// <param name="timeoutSecond"></param>
        /// <param name="dnfItemRect"></param>
        /// <returns></returns>
        private bool LoginDNF(CancellationToken cancelToken, Int64 timeoutSecond)
        private bool LoginDNF(CancellationToken cancelToken, Int64 timeoutSecond,ZTRectangle wegameRect)
        {
            ZTRectangle findRect = ZTRectangle.Empty;
            ZTRectangle pRect = ZTRectangle.Empty;
@@ -148,6 +173,7 @@
            {
                G.Instance.InfoWriter("未找到主页按钮");
                return false;
                //todo:发通知
            }
            G.Instance.InfoWriter("主页按钮已找到");
            G.Instance.InputControl.MoveToAndClick(unselectHomeButtonRect.GetCenterPoint());
@@ -161,38 +187,88 @@
            {
                G.Instance.InfoWriter("未找到DNF项");
                return false;
                //todo:发通知
            }
            G.Instance.InfoWriter("Dnf项已找到");
            G.Instance.InputControl.MoveToAndClick(dnfItemRect.GetCenterPoint());
            //是否需要更新
            ZTRectangle updateButtonRect = ZTRectangle.Empty;
            result = FuncUtils.TimeoutCancelableWrap(3000, cancelToken, () => {
                return WeGameCVHelper.FindUpdateButton(out updateButtonRect);
            });
            if (result)
            {
                G.Instance.InfoWriter("需要更新请更新后再运行");
                G.Instance.InputControl.MoveToAndClick(updateButtonRect.GetCenterPoint());
                return false;
            }
            //开始游戏按钮
            ZTRectangle startGameButtonRect = ZTRectangle.Empty;
            //是否需要更新,如需要则更新
            ZTRectangle buttonRect = ZTRectangle.Empty;
            bool isUpdate = false;
            result = FuncUtils.TimeoutCancelableWrap((Int32)timeoutSecond * 1000, cancelToken, () => {
                return WeGameCVHelper.FindStartGameButton(out startGameButtonRect);
                return FindGameButton(out buttonRect, out isUpdate);
            });
            if (!result)
            {
                G.Instance.InfoWriter("未找到开始游戏按钮");
                G.Instance.InfoWriter("未找到开始或升级游戏按钮");
                return false;
            }
            G.Instance.InfoWriter("开始游戏按钮已找到");
            G.Instance.InputControl.MoveToAndClick(startGameButtonRect.GetCenterPoint());
            if (isUpdate)
            {
                //更新
                G.Instance.InputControl.MoveToAndClick(buttonRect.GetCenterPoint());
                G.Instance.InfoWriter("需要更新,更新超时时长为30分钟");
                result = FuncUtils.TimeoutCancelableWrap(30 * 60 * 1000, cancelToken, () => {
                    G.Instance.InputControl.MoveTo(0, 0, false, false, false);
                    if (FindGameButton(out buttonRect, out isUpdate))
                    {
                        if (isUpdate)
                        {
                            //如果没点上更新按钮则再点一次
                            G.Instance.InputControl.MoveToAndClick(buttonRect.GetCenterPoint());
                        }
                        else
                        {
            return true;
        }
                    }
                    return false;
                });
                if (!result)
                {
                    G.Instance.InfoWriter("更新未成功,请手动更新");
                    //todo:发通知
                    return false;
                }
            }
            G.Instance.InfoWriter("开始游戏");
            G.Instance.InputControl.MoveToAndClick(buttonRect.GetCenterPoint());
            return true;
        }
        /// <summary>
        /// 查找游戏按钮
        /// </summary>
        /// <param name="buttonRect"></param>
        /// <returns></returns>
        private bool FindGameButton(out ZTRectangle buttonRect,out bool isUpdate)
        {
            buttonRect = ZTRectangle.Empty;
            isUpdate = false;
            Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
            if (WeGameCVHelper.FindUpdateButton(out buttonRect, image))
            {
                isUpdate = true;
                return true;
            }
            if (WeGameCVHelper.FindStartGameButton(out buttonRect, image))
            {
                isUpdate = false;
                return true;
            }
            return false;
        }
        #region Tools
        /// <summary>