using RichCreator.Utility.Captures; using RichCreator.Utility.CV; using RichCreator.Utility.InputControl; using RichCreator.Utility.Structs; using RichCreator.Utility.Utilitys; using Emgu.CV; using Emgu.CV.Structure; using RichCreator.Utilitys; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace RichCreator.Jobs { public class WeGameJob:JobBase { public WeGameJob(RichCreatorConfig config,string userName,string password):base(config) { this.UserName = userName; this.Password = password; } private string UserName; private string Password; public override ZTResult Do(CancellationToken cancellationToken,Int32 runningStep) { Process.Start(this.Config.TGPDaemonPath); G.Instance.InfoWriter("等待We Game运行"); ZTRectangle weGameRect = ZTRectangle.Empty; ZTRectangle changeLoginMethodButtonRect = ZTRectangle.Empty; //查找游戏 bool result = FindWeGame(cancellationToken, 5 * 60, out weGameRect,out changeLoginMethodButtonRect); if (!result) { G.Instance.InfoWriter("查找游戏失败"); return ZTResult.Failed; } G.Instance.InfoWriter("WeGame于:" + weGameRect.ToString() + ",切换按钮于:" + changeLoginMethodButtonRect.ToString()); //登陆 result = LoginWeGame(cancellationToken, 30, weGameRect, changeLoginMethodButtonRect); if (!result) { G.Instance.InfoWriter("登陆失败"); return ZTResult.Failed; } G.Instance.InfoWriter("WeGame登陆成功"); //登陆DNF游戏 result = LoginDNF(cancellationToken, 30); if (!result) { G.Instance.InfoWriter("DNF未成功打开"); return ZTResult.Failed; } G.Instance.InfoWriter("开始启动DNF游戏"); return ZTResult.Success; } /// /// 查找we game运行框 /// /// 取消令牌 /// 超时时间,秒 /// 程序区域 /// 当前登陆方式,0:QQ快速登陆,1:码密登陆 /// 切换登陆方式按钮区域 /// private bool FindWeGame(CancellationToken cancelToken, Int64 timeoutSecond, out ZTRectangle wegameRect, out ZTRectangle changeButtonRect) { ZTRectangle weGameRect = ZTRectangle.Empty; ZTRectangle changeLoginMethodButtonRect = ZTRectangle.Empty; bool result=FuncUtils.TimeoutCancelableWrap((Int32)timeoutSecond * 1000, cancelToken, () => { return WeGameCVHelper.IsLoginPage(out weGameRect, out changeLoginMethodButtonRect); }); wegameRect = weGameRect; changeButtonRect = changeLoginMethodButtonRect; return result; } /// /// 登陆WeGame /// /// wegame登陆框区域 /// 切换模式区域 /// private bool LoginWeGame(CancellationToken cancelToken, Int64 timeoutSecond, ZTRectangle weGameRect, ZTRectangle changButtonRect) { Utility.Structs.ZTPoint basePoint = changButtonRect.GetCenterPoint(); Utility.Structs.ZTPoint userPoint = new Utility.Structs.ZTPoint(basePoint.X, basePoint.Y - 148); Utility.Structs.ZTPoint pwdPoint = new Utility.Structs.ZTPoint(basePoint.X, basePoint.Y - 118); Utility.Structs.ZTPoint loginPoint = new Utility.Structs.ZTPoint(basePoint.X, basePoint.Y - 42); //输入用户名 G.Instance.InputControl.MoveToAndClick(userPoint); DeleteAllChar(10); G.Instance.InputControl.InputString(this.UserName); //输入密码 G.Instance.InputControl.MoveToAndClick(pwdPoint); DeleteAllChar(2); G.Instance.InputControl.InputString(this.Password); //点击登陆 G.Instance.InputControl.MoveToAndClick(loginPoint); return true; } /// /// 查找DNF项的区域 /// /// /// /// /// private bool LoginDNF(CancellationToken cancelToken, Int64 timeoutSecond) { ZTRectangle findRect = ZTRectangle.Empty; ZTRectangle pRect = ZTRectangle.Empty; G.Instance.InputControl.MoveTo(0, 0, false, false, false); //选中主页 ZTRectangle unselectHomeButtonRect = ZTRectangle.Empty; bool result = FuncUtils.TimeoutCancelableWrap((Int32)timeoutSecond * 1000, cancelToken, () => { return WeGameCVHelper.FindUnselectHome(out unselectHomeButtonRect); }); if (!result) { G.Instance.InfoWriter("未找到主页按钮"); return false; } G.Instance.InfoWriter("主页按钮已找到"); G.Instance.InputControl.MoveToAndClick(unselectHomeButtonRect.GetCenterPoint()); //选中DNF项 ZTRectangle dnfItemRect = ZTRectangle.Empty; result = FuncUtils.TimeoutCancelableWrap((Int32)timeoutSecond * 1000, cancelToken, () => { return WeGameCVHelper.FindDnfItem(out dnfItemRect); }); if (!result) { G.Instance.InfoWriter("未找到DNF项"); return false; } 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; result = FuncUtils.TimeoutCancelableWrap((Int32)timeoutSecond * 1000, cancelToken, () => { return WeGameCVHelper.FindStartGameButton(out startGameButtonRect); }); if (!result) { G.Instance.InfoWriter("未找到开始游戏按钮"); return false; } G.Instance.InfoWriter("开始游戏按钮已找到"); G.Instance.InputControl.MoveToAndClick(startGameButtonRect.GetCenterPoint()); return true; } #region Tools /// /// 删除左右指定数量的字符 /// /// private void DeleteAllChar(int count) { for (int i = 0; i < count; i++) { G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Delete); G.Instance.InputControl.PressKey(false, false, false, false, false, false, false, false, HIDCode.Backspace); } } #endregion } }