public void Execute(object parameter) { if (null == m_execute) { return; } if (!CanExecute(parameter)) { return; } if (!m_isAsync) { m_execute(parameter); return; } Task.Run(() => { try { m_execute(parameter); } catch (Exception ex) { WxLog.Debug($"WxCommand.Execute {ex}"); } }); }
/// <summary> /// 获取军令数量 /// </summary> /// <param name="dmGuid"></param> /// <returns></returns> public static int GetPoint(string dmGuid) { // 首先跳转到主界面 WlyViewMgr.GoTo(dmGuid, WlyViewType.场景_主界面); var pointRect = new WxRect(119, 106, 163, 123); var words = string.Empty; var wait = FlowLogicHelper.RepeatRun(() => { words = DMService.Instance.GetWords(dmGuid, pointRect, "f3f3da-202020"); return(!string.IsNullOrEmpty(words)); }, TimeSpan.FromSeconds(20)); if (!wait) { throw new InvalidOperationException("无法获取军令信息"); } var result = int.TryParse(words.Split('/')[0], out var point); if (!result) { WxLog.Debug($"WlyUtilityBiz.GetPoint <{words}>"); return(0); } return(point); }
/// <summary> /// 在指定范围内寻找图片 /// </summary> /// <param name="dmGuid"></param> /// <param name="key">资源键值</param> /// <param name="rect"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public bool FindPic(string dmGuid, object key, WxRect rect, out int x, out int y) { if (!m_picResources.ContainsKey(key)) { x = -1; y = -1; WxLog.Debug($"DMService.FindPic No Pic Resource With Key <{key}>"); return(false); } var dm = GetDM(dmGuid); var resource = m_picResources[key]; var result = dm.FindPicMem(rect.Left, rect.Top, rect.Right, rect.Bottom, resource.Info, "202020", 0.8, 0, out var xx, out var yy); if (result > -1) { x = (int)xx; y = (int)yy; return(true); } x = -1; y = -1; return(false); }
/// <summary> /// 使用 sql 语句与参数查询数据库 /// </summary> /// <param name="sqlString"></param> /// <param name="parameters"></param> /// <returns></returns> public override DataSet Query(string sqlString, IEnumerable <object> parameters) { try { // 构建命令 MySqlCommand cmd = new MySqlCommand { CommandText = sqlString, Connection = m_connection }; if (parameters != null) { foreach (var value in parameters) { cmd.Parameters.Add(new MySqlParameter { Value = value }); } } // 获取数据 MySqlDataAdapter adapter = new MySqlDataAdapter(cmd); var dataSet = new DataSet(); lock (m_executeLocker) { adapter.Fill(dataSet); } return(dataSet); } catch (Exception ex) { WxLog.Debug($"MySqlDatabase.Query \n\tsql<{sqlString}>\n\tex<{ex}>"); return(null); } }
/// <summary> /// 创建账号,写入数据库 /// </summary> /// <param name="user"></param> /// <param name="psw"></param> private void CreateAccount(string user, string psw) { var sql = "insert into AccountInfo(UID, Account, Psw, LastLoginTime) values (?, ?, ?, ?);"; var uid = MathHelper.GetNewGuid(); var result = m_mySqlDatabase.Execute(sql, new object[] { uid, user, psw, DateTime.MinValue }); WxLog.Debug($"RegEntity.CreateAccount <{user} | {psw}> Result<{result}>"); }
public void Start() { m_accountInfo = MainAccountInfo.LoadAccount(m_mainFile); if (!File.Exists(m_mainFile)) { m_accountInfo.Save(); } m_mainEntity = new MainEntity(m_accountInfo); MainTaskMgr.Instance.InitEntityTasks(m_mainEntity); m_mainEntity.DescriptionChanged += MainEntityOnDescriptionChanged; m_mainEntity.Start(); foreach (var t in WxHelper.GetEnumValues <WlySwitchType>()) { var info = m_accountInfo.GetSwitchInfo(t); var wrapper = new WlyTaskSwitchWrapper(info); wrapper.Changed += WrapperOnChanged; Switches.Add(wrapper); } // 主账号监测 m_cancellationTokenSource = new CancellationTokenSource(); var token = m_cancellationTokenSource.Token; Task.Run(() => { while (!token.IsCancellationRequested) { try { Thread.Sleep(TimeSpan.FromMinutes(1)); if (!m_mainEntity.Run) { WxLog.Debug($"WlyAutoVM.Start 对主账号进行重置 <{DateTime.Now}>"); m_mainEntity.Stop(); m_mainEntity.DescriptionChanged -= MainEntityOnDescriptionChanged; MainEntity = new MainEntity(m_accountInfo); MainTaskMgr.Instance.InitEntityTasks(m_mainEntity); m_mainEntity.DescriptionChanged += MainEntityOnDescriptionChanged; m_mainEntity.Start(); } } catch (Exception ex) { WxLog.Error($"WlyAutoVM.Start Error <{ex}>"); } } WxLog.Debug($"WlyAutoVM.Start Stop On <{ResetTime}>"); }, token); //StartSubCmdExecute(this); }
/// <summary> /// 根据数据库类型创建对应数据库实体 /// </summary> /// <param name="type">数据库类型</param> /// <returns></returns> /// <exception cref="WxException">不支持的数据库类型.</exception> public IWxDatabase CreateDatabase(WxDatabaseType type) { WxLog.Debug($"WxDatabasePlugin.CreateDatabase \t<{type}>"); switch (type) { case WxDatabaseType.MySql: return(new MySqlDatabase()); default: return(null); } }
static ResourceFactory() { var assembly = typeof(ResourceFactory).Assembly; foreach (var res in assembly.GetManifestResourceNames()) { WxLog.Debug($"ResourceFactory.ResourceFactory Res <{res}>"); var stream = assembly.GetManifestResourceStream(res); var resource = new BizResouce(res, stream); m_dict.TryAdd(resource.Name, resource); } }
/// <summary> /// 开始运行脚本 /// </summary> private void StartGame() { if (m_process != null) { m_process.Close(); m_process.Kill(); m_process = null; } m_process = Process.Start(new ProcessStartInfo { UseShellExecute = false, FileName = m_programPath }); var result = Login(); if (!result) { // 启动失败,等待重启 State = RunningState.Stopped; return; } // 设置开始时间 StartTime = DateTime.Now; // 获取新窗口句柄 m_dmsoft = DMFactory.Instance.CreateDMSoft(); while (true) { var handle = m_dmsoft.EnumWindowByProcessId(m_process.Id, "", "MacromediaFlashPlayerActiveX", 2); WxLog.Debug($"AppEntity.StartGame Handl <{handle}>"); var hs = handle.Split(','); foreach (var h in hs) { try { var it = int.Parse(h); m_dmsoft.BindWindow(it, "gdi", "windows", "windows", 101); var title = m_dmsoft.GetWindowClass(it); WxLog.Debug($"AppEntity.StartGame {title}"); } catch { } } Thread.Sleep(10000); } }
/// <summary> /// 构建大漠插件实体 /// </summary> /// <returns></returns> public dmsoft CreateDMSoft() { while (true) { var dm = new dmsoft(); var result = dm.Reg(m_code, ""); if (result == 1) { return(dm); } WxLog.Debug($"DMFactory.CreateDMSoft Result <{result}> ReCreate"); Thread.Sleep(1000); } }
/// <summary> /// 关闭聊天窗 /// </summary> private void CloseChat() { while (true) { var result = DMFactory.Instance.FindPic(m_dm, ResourceEnum.CloseChat, out var x, out var y); if (result) { WxLog.Debug($"MainEntity.CloseChat Location:{x},{y}"); m_dm.MoveTo(x + 5, y + 5); m_dm.LeftClick(); Thread.Sleep(100); } WxLog.Debug($"MainEntity.CloseChat Finish"); break; } }
/// <summary> /// 连接数据库 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="ip"></param> /// <param name="dbname"></param> /// <returns></returns> public override bool Connect(string username, string password, string ip, string dbname) { try { m_connectionString = $"server={ip};User Id={username};password={password};Database={dbname}"; m_connection = new MySqlConnection(m_connectionString); m_connection.Open(); WxLog.Debug($"MySqlDatabase.Connect \t<{m_connectionString}>"); // 初始化命令队列线程 var cmdQueueThread = new Thread(HandleCmdQueue); cmdQueueThread.Start(); WxLog.Debug("MySqlDatabase.Connect CmdQueueThead Start!"); return(true); } catch (Exception ex) { WxLog.Debug($"MySqlDatabase.Connect \t<{ex}>"); return(false); } }
protected override void InternalBackupWorkThread() { // 小号无其他任务则直接停止 WxLog.Debug($"SubEntity.InternalBackupWorkThread No More Tasks <{Account}>"); var time = WlyUtilityBiz.GetRefreshTime(); foreach (var runner in TaskList.ToList()) { var info = AccountInfo.GetTaskInfo(runner.Task.ID); if (info.NextRunTime < time) { time = info.NextRunTime; } } m_subAccountInfo.NextLoginTime = time; WxLog.Debug($"SubEntity.InternalBackupWorkThread Name<{m_subAccountInfo.Name}> " + $"NextLoginTime<{m_subAccountInfo.NextLoginTime:yyyy-MM-dd HH:mm:ss}>"); m_subAccountInfo.Save(); Stop(); }
/// <summary> /// 框架服务初始化 /// 启动日志服务 /// </summary> public void Init() { WxLog.Debug($"WxFrameworkService.Init Start!"); WxLog.Debug($"WxFrameworkService.Init Finish!"); }
private void WxLog_Test_Debug() { WxLog.Debug("Test"); }
protected override void InternalAfterLogin() { SubTaskMgr.Instance.InitEntityTasks(this); m_loginFlag = true; if (!m_subAccountInfo.Check) { var wait = FlowLogicHelper.RepeatRun(() => { var view = WlyViewMgr.GetView(WlyViewType.略_防沉迷验证); var view1 = WlyViewMgr.GetView(WlyViewType.略_跳过); return(DMService.Instance.FindPic(DMGuid, WlyPicType.择国家, WlyUtilityBiz.GameWndRect) || view.IsCurrentView(DMGuid) || view1.IsCurrentView(DMGuid)); }, TimeSpan.FromSeconds(30)); if (wait && DMService.Instance.FindPic(DMGuid, WlyPicType.择国家, WlyUtilityBiz.GameWndRect)) { CreateRole(AutoPlayerVM.Instance.GetAvailableName()); } } WxLog.Debug($"SubEntity.InternalAfterLogin AutoPlay Start <{m_subAccountInfo.Name}>"); // 先检测主公等级 var level = WlyUtilityBiz.GetMainLevel(DMGuid); if (level > m_subAccountInfo.Level) { WlyMainLevelMgr.Upgrade(DMGuid); m_subAccountInfo.Level = level; m_subAccountInfo.Save(); } // 检测银币数量是否到达上限 var result = WlyUtilityBiz.GetPercent(DMGuid, new WxRect(133, 26, 217, 47), "f3f3da-000000", out var percent); if (!result) { throw new InvalidOperationException("Cannot Get Money Amount"); } // 银币超过上限了,想尽办法进行使用 if (percent >= 0.9) { GetEuqipments(); UpgradeEquipments(); } // 如果可以捐国政了,则捐国政 var now = DateTime.Now; var timeNotOK = (now.DayOfWeek == DayOfWeek.Sunday) && (now.Hour >= 4) && (now.Hour < 21); if ((percent >= 0.5) && (m_subAccountInfo.GetBuildingInfo(WlyBuildingType.主城).Level >= 130) && !timeNotOK) { // 捐款2600万获取100政绩 WlyViewMgr.GoTo(DMGuid, WlyViewType.场景_国政); // 点开内政 var wait = FlowLogicHelper.RepeatRun(() => { DMService.Instance.LeftClick(DMGuid, new WxPoint(95, 42)); if (DMService.Instance.FindStr(DMGuid, new WxRect(483, 100, 516, 120), "国政", WlyColor.Normal)) { return(true); } Thread.Sleep(500); return(false); }, TimeSpan.FromSeconds(10)); if (!wait) { throw new InvalidOperationException(); } // 捐款铸造 DMService.Instance.LeftClick(DMGuid, new WxPoint(560, 270)); DMService.Instance.LeftClick(DMGuid, new WxPoint(613, 438)); DMService.Instance.SendString(DMGuid, WndHwnd, "50000000"); wait = FlowLogicHelper.RepeatRun(() => { if (WlyUtilityBiz.GetAmount(DMGuid, new WxRect(577, 429, 671, 447), "e7e7fd-000000", out var amount)) { return(true); } Thread.Sleep(500); return(false); }, TimeSpan.FromSeconds(10)); if (!wait) { throw new InvalidOperationException(); } DMService.Instance.LeftClick(DMGuid, new WxPoint(739, 438)); } // 如果可以进行开发,则马上开发并立刻结束 //if (DevelopTime < DateTime.Now) //{ // WlyUtilityBiz.GetAmount(DMGuid, new WxRect(133, 26, 217, 47), "f3f3da-000000", out var amount); // if (amount > 500000) // { // DevelopCity(); // //Stop(); // } //} }
public void TestMethodA(TestEntityA A) { ResultA = A; WxLog.Debug($"TestMethodBussiness.TestMethodA{A.GetType().FullName}"); }
private void TestMethod(TestEntityB B) { ResultB = B; WxLog.Debug($"TestMethodBussiness.TestMethod {B.GetType().FullName}"); }
/// <summary> /// 挂机线程 /// </summary> private void AutoPlayThread() { m_run = true; m_final = true; m_isDevelop = false; var errorCount = 0; // 最外层死循环,进程守护 while (m_run) { try { // 登录 OnDescriptionChanged($"开始登录 {Account}"); DMGuid = string.Empty; WlyUtilityBiz.Login(this); // 绑定游戏窗口 BindGameWnd(); InternalAfterLogin(); // 登录成功,等待登录完成 OnDescriptionChanged("等待加载完成"); WlyViewMgr.GoTo(DMGuid, WlyViewType.场景_主界面, TimeSpan.FromSeconds(2)); // 开始挂机 m_aliveTime = DateTime.Now; while (m_run) { if (DMService.Instance.GetWindowState(DMGuid, WndHwnd, 0) == 0) { WxLog.Error($"WlyEntity.AutoPlayThread 游戏窗口不存在"); break; } WlyTaskRunner runner = null; // 检测是否有可以运行的日常任务 if (m_dailyList.Any() && (m_dailyList.First().StartTime < DateTime.Now)) { runner = m_dailyList.First(); OnDescriptionChanged(runner.Task.MainTitle); CurrentRunner = runner; var info = runner.Task.Run(this); WxLog.Debug($"WlyEntity.AutoPlayThread Name <{this}> Run <{runner.Task}> Result <{info}>"); // 无论结果,先进行保存 SaveTaskInfo(info); RemoveTaskRunner(runner); if (!info.IsComplete) { // 未完成的任务重新加入,等待下一次运行 AddTask(runner.Task, info.NextRunTime); } m_aliveTime = DateTime.Now; continue; } // 检测是否有可以运行的主线任务 runner = m_mainList.FirstOrDefault(o => o.StartTime < DateTime.Now); if (runner != null) { OnDescriptionChanged(runner.Task.MainTitle); CurrentRunner = runner; var info = runner.Task.Run(this); // 无论结果,先进行保存 SaveTaskInfo(info); RemoveTaskRunner(runner); if (!info.IsComplete) { // 未完成的任务重新加入,等待下一次运行 AddTask(runner.Task, info.NextRunTime); } m_aliveTime = DateTime.Now; continue; } CurrentRunner = null; // 运行空闲任务 InternalBackupWorkThread(); // 超时重启 if (DateTime.Now - m_aliveTime > m_restartInterval) { break; } } while (m_finalList.Any(o => o.StartTime < DateTime.Now)) { var runner = m_finalList.FirstOrDefault(o => o.StartTime < DateTime.Now); if (runner == null) { break; } OnDescriptionChanged(runner.Task.MainTitle); CurrentRunner = runner; var info = runner.Task.Run(this); WxLog.Debug($"WlyEntity.AutoPlayThread Name <{this}> Run <{runner.Task}> Result <{info}>"); // 无论结果,先进行保存 SaveTaskInfo(info); m_finalList.Remove(runner); if (!info.IsComplete) { // 未完成的任务重新加入,等待下一次运行 AddTask(runner.Task, info.NextRunTime); } m_aliveTime = DateTime.Now; } m_final = false; } catch (InvalidOperationException ex) { WxLog.Error($"WlyEntity.InternalBackupWorkThread Error {ex}"); errorCount++; InternalHandleError(errorCount); //CaptureError(ex); } catch (Exception ex) { WxLog.Error($"WlyEntity.AutoPlayThread Error <{ex}>"); } finally { CloseProcess(); } } WxLog.Debug($"WlyEntity.AutoPlayThread Stopped, Hwnd <{WndHwnd}>, Run <{Run}>"); OnStopped(); }
/// <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); }
/// <summary> /// 登录到服务器 /// </summary> /// <returns>返回null表示登录失败,需要重新尝试</returns> public static void Login(WlyEntity entity) { // 登录并发保护 lock (_loginLocker) { var guid = DMService.Instance.CreateDMSoft(); var hwndStr = string.Empty; // 程序保护 var fileInfo = new FileInfo(ProgramPath); if (fileInfo.Length < 10240) { File.Delete(ProgramPath); File.Copy(BaseProgramPath, ProgramPath); } // 启动程序 var process = Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = ProgramPath }); try { // 获取窗口句柄,进程有时不会立即打开,做一个循环获取,保证成功率 Thread.Sleep(400); if (!FlowLogicHelper.RepeatRun(() => { hwndStr = DMService.Instance.EnumWindowByProcessId(guid, process.Id, "", "Internet Explorer_Server", 2); if (string.IsNullOrEmpty(hwndStr)) { Thread.Sleep(300); return(false); } return(true); }, TimeSpan.FromSeconds(5))) { throw new InvalidOperationException("打开游戏进程失败"); } // 绑定窗口,开始登录 var loginHwnd = int.Parse(hwndStr); DMService.Instance.BindWindow(guid, loginHwnd); // 确认登录界面完全显示 if (!FlowLogicHelper.RepeatRun(() => { if (!DMService.Instance.FindPic(guid, WlyPicType.进入游戏, GameWndRect)) { Thread.Sleep(500); return(false); } return(true); }, TimeSpan.FromSeconds(5))) { WxLog.Debug($"WlyUtilityBiz.Login Cannot Find Login Wnd <{loginHwnd}>"); throw new InvalidOperationException("登录界面不显示"); } // 输入账号 var accountPoint = new WxPoint(324, 258); DMService.Instance.LeftDoubleClick(guid, accountPoint, 200); DMService.Instance.SendString(guid, loginHwnd, entity.Account); Thread.Sleep(200); // 输入密码 var pswPoint = new WxPoint(234, 291); DMService.Instance.LeftDoubleClick(guid, pswPoint, 200); DMService.Instance.SendString(guid, loginHwnd, entity.Password); Thread.Sleep(200); // 点击登录,等待登录成功 var loginPoint = new WxPoint(482, 322); if (!FlowLogicHelper.RepeatRun(() => { if (!DMService.Instance.FindPic(guid, WlyPicType.登录成功, GameWndRect)) { if (DMService.Instance.FindPic(guid, WlyPicType.进入游戏, GameWndRect)) { DMService.Instance.LeftClick(guid, loginPoint); } Thread.Sleep(500); return(false); } return(true); }, TimeSpan.FromSeconds(5))) { throw new InvalidOperationException("Need Restart"); } DMService.Instance.LeftClick(guid, new WxPoint(230, 159)); DMService.Instance.SendString(guid, loginHwnd, "6117"); Thread.Sleep(400); DMService.Instance.LeftClick(guid, new WxPoint(365, 158)); entity.EntityProcess = process; } catch { if (process != null) { process.Kill(); process.Dispose(); } throw; } finally { DMService.Instance.ReleaseDMSoft(guid); } } }
/// <summary> /// 寻找首攻 /// </summary> private void FindFirstAttack() { var startTime = DateTime.Now; while (true) { if (DateTime.Now - startTime > TimeSpan.FromMinutes(2)) { return; } var findResult = m_dm.FindStr(100, 470, 277, 550, "(首", "fff71c-000000|fcffa9-000000", 1, out var _, out var _); if (findResult == -1) { Thread.Sleep(100); continue; } // 寻找到首攻,加入队伍 WxLog.Debug($"MainEntity.FindFirstAttack Find First Attack {findResult}"); findResult = m_dm.FindStr(100, 470, 277, 550, "加", "00ff00-000000", 1, out var x, out var y); if (findResult == -1) { Thread.Sleep(100); continue; } // 点击加入队伍 WxLog.Debug($"MainEntity.FindFirstAttack Click:{x},{y}"); m_dm.MoveTo((int)x + 5, (int)y + 5); m_dm.LeftClick(); findResult = -1; var retry = 0; while (findResult == -1) { // 确认自己在队伍中 findResult = m_dm.FindStr(370, 198, 517, 219, "(首攻)", "ffffb0-000000", 1, out var _, out var _); if (findResult == -1) { retry++; if (retry > 30) { break; } Thread.Sleep(100); } } findResult = m_dm.FindStr(632, 206, 807, 449, "海潮", "e9e7cf-000000", 1, out var _, out var _); if (findResult == -1) { Thread.Sleep(100); continue; } // 给首攻五秒钟时间 Thread.Sleep(5000); return; } }
public void Stop() { WxLog.Debug($"WlyAutoVM.Stop <{DateTime.Now}>"); m_cancellationTokenSource.Cancel(false); }
/// <summary> /// 工作线程 /// </summary> /// <param name="index"></param> private void WorkThread(int index) { var dm = DMFactory.Instance.CreateDMSoft(); // 获取登录窗的句柄 var hwndStr = string.Empty; while (string.IsNullOrEmpty(hwndStr)) { Thread.Sleep(1000); hwndStr = dm.EnumWindowByProcessId(m_process.Id, "", "Internet Explorer_Server", 2); WxLog.Debug($"AppEntity.Login Get Login Hwnd hwndstr <{hwndStr}>"); } var hwnd = int.Parse(hwndStr); DMFactory.Instance.BindWindow(dm, hwnd); var rand = new Random(); // 开始进入注册线程 while (true) { var account = GetRandomStr(rand.Next(6, 9)); var psw = GetRandomStr(rand.Next(6, 9)); WxLog.Debug($"RegEntity.WorkThread Account <{account}> Password <{psw}>"); // 点击新用户注册 while (true) { var result = DMFactory.Instance.FindPic(dm, ResourceEnum.RegUncheck, out var x, out var y); if (result) { dm.MoveTo(x, y); dm.LeftClick(); Thread.Sleep(100); } else { break; } } // 确认切换成功 var retry = 0; while (true) { var result = DMFactory.Instance.FindPic(dm, ResourceEnum.RegChecked, out var _, out var _); if (result) { break; } retry++; Thread.Sleep(100); if (retry > 20) { break; } } // 输入注册信息 dm.MoveTo(323, 257); dm.LeftClick(); dm.SendString(hwnd, account); Thread.Sleep(500); dm.MoveTo(300, 290); dm.LeftClick(); dm.SendString(hwnd, psw); Thread.Sleep(500); dm.MoveTo(300, 330); dm.LeftClick(); dm.SendString(hwnd, psw); Thread.Sleep(500); // 点击进入游戏 dm.MoveTo(478, 323); dm.LeftClick(); Thread.Sleep(2000); // 确认账号有效 var r = DMFactory.Instance.FindPic(dm, ResourceEnum.ErrorInfo, out var _, out var _); if (r) { WxLog.Debug($"RegEntity.WorkThread Error Account {account}"); break; } // 确认登录成功 r = DMFactory.Instance.FindPic(dm, ResourceEnum.LoginSuccess, out var _, out var _); if (r) { // 账号信息写入数据库 CreateAccount(account, psw); // 注销 dm.MoveTo(377, 11); dm.LeftClick(); Thread.Sleep(2000); } else { break; } } m_process.Kill(); m_process.Close(); m_process.Dispose(); Run = false; }
/// <summary> /// 开启挂机 /// </summary> private void BeginAutoPlay() { m_startTime = DateTime.Now; m_dm = DMFactory.Instance.CreateDMSoft(); var dictPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "resource", "WLYWord.txt"); var setResult = m_dm.SetDict(0, dictPath); WxLog.Debug($"MainEntity.BeginAutoPlay SetDict {dictPath} Result:<{setResult}>"); var retry = 0; while (true) { m_wndHandle = m_dm.FindWindowByProcessId(m_process.Id, "ActiveX", ""); var state = m_dm.GetWindowState(m_wndHandle, 2); if (state == 0) { Thread.Sleep(1000); continue; } DMFactory.Instance.BindWindow(m_dm, m_wndHandle); var result = DMFactory.Instance.FindPic(m_dm, ResourceEnum.InGameCheck, out var _, out var _); if (result) { break; } // 超过30秒重新启动 retry++; if (retry > 30) { WxLog.Debug($"MainEntity.BeginAutoPlay Cannot Find InGameTag {retry}"); return; } Thread.Sleep(1000); } WxLog.Debug($"MainEntity.BeginAutoPlay Find InGameTag Success {m_wndHandle}"); m_dm.MoveTo(815, 178); m_dm.LeftClick(); Thread.Sleep(1000); m_dm.LeftClick(); Thread.Sleep(1000); // 内层死循环,周期性重启 while (m_run) { //回到主城界面 GoBack(); // 收起聊天框 CloseChat(); // 检测擂台站报名 //SignUpFight(); FindFirstAttack(); //Thread.Sleep(30000); if (DateTime.Now - m_startTime > TimeSpan.FromMinutes(10) || (DateTime.Now.Minute == 0 && m_startTime.Minute != 0)) { // 10分钟启动一次 WxLog.Debug($"MainEntity.BeginAutoPlay Restart {DateTime.Now}"); return; } } }