Browse Source

重复战斗

Jeff Wang 1 year ago
parent
commit
6dae30192c

+ 69 - 0
GameAssist/GameAssist/CAction.cpp

@@ -1265,6 +1265,75 @@ SRAND(80,120);
 		return 0;
 	}
 
+	void CAction::StartRepeat()
+	{
+		m_hBattleJYEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+		if (m_hBattleJYEvent == NULL) {
+			_tprintf_s(_T("创建事件失败\n"));
+			return;
+
+		}
+
+		m_hBattleJY = CreateThread(NULL, 0, RepeatThread, this, 0, NULL);
+		if (m_hBattleJY == NULL) {
+			_tprintf_s(_T("创建线程失败\n"));
+
+			if (m_hBattleJYEvent) {
+				SetEvent(m_hBattleJYEvent);
+				CloseHandle(m_hBattleJYEvent);
+				m_hBattleJYEvent = NULL;
+
+			}
+		}
+	}
+
+	void CAction::StopRepeat()
+	{
+		// 设置事件有信号;
+		if (m_hBattleJYEvent)
+			SetEvent(m_hBattleJYEvent);
+
+		// 等待线程结束;
+		if (m_hBattleJY) {
+			WaitForSingleObject(m_hBattleJY, INFINITE);
+			CloseHandle(m_hBattleJY);
+			m_hBattleJY = NULL;
+		}
+
+		// 关闭事件句柄;
+		if (m_hBattleJYEvent) {
+			CloseHandle(m_hBattleJYEvent);
+			m_hBattleJYEvent = NULL;
+		}
+	}
+
+	DWORD __stdcall CAction::RepeatThread(LPVOID lpParam)
+	{
+		CAction* pAction = (CAction*)lpParam;
+		do
+		{
+			BOOL bFirst = TRUE;
+			while (pAction->IsFighting())
+			{
+				if (pAction->IsWattingAttack(-1))
+				{
+					SRAND(50, 150);
+					pAction->SendKey(VK_A, FALSE, TRUE);
+				}
+				Sleep(50);
+			}
+
+			if (pAction->IsSPBelowSafeValue(TRUE, TRUE, 10))
+			{
+				// 右键;
+				pAction->MouseMove({ (GameAssist::g_rcRoleIdleSP.right + GameAssist::g_rcRoleIdleSP.left) / 2, (GameAssist::g_rcRoleIdleSP.bottom + GameAssist::g_rcRoleIdleSP.top) / 2 });
+				pAction->MouseRClick({ (GameAssist::g_rcRoleIdleSP.right + GameAssist::g_rcRoleIdleSP.left) / 2, (GameAssist::g_rcRoleIdleSP.bottom + GameAssist::g_rcRoleIdleSP.top) / 2 });
+			}
+		} while (WaitForSingleObject(pAction->m_hBattleJYEvent, 100) == WAIT_TIMEOUT);
+
+		return 0;
+	}
+
 	void LoadMetaGraph()
 	{
 		// 解析xml;

+ 4 - 0
GameAssist/GameAssist/CAction.h

@@ -156,6 +156,10 @@ public:
 		void StartSkill();
 		void StopSkill();
 		static DWORD WINAPI SkillThread(LPVOID lpParam);
+
+		void StartRepeat();
+		void StopRepeat();
+		static DWORD WINAPI RepeatThread(LPVOID lpParam);
 	};
 
 };

+ 1 - 24
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -547,33 +547,10 @@ void CGameAssistDlg::OnBnClickedButton10() // Alt+A
 	if (pGameInfo && pGameInfo->pAction)
 	{
 		GameAssist::CAction* pAction = (GameAssist::CAction*)pGameInfo->pAction;
-		while (true)
-		{
-			BOOL bFirst = TRUE;
-			while (pAction->IsFighting())
-			{
-				if (pAction->IsWattingAttack(-1))
-				{
-					SRAND(250, 350);
-					pAction->SendKey(VK_A, FALSE, TRUE);
-				}
-				Sleep(650);
-			}
-
-			if (pAction->IsSPBelowSafeValue(TRUE, TRUE, 10))
-			{
-				DebugLog(_T("µÍSP°²È«Öµ"));
-				// ÓÒ¼ü;
-				pAction->MouseMove({ (GameAssist::g_rcRoleIdleSP.right + GameAssist::g_rcRoleIdleSP.left) / 2, (GameAssist::g_rcRoleIdleSP.bottom + GameAssist::g_rcRoleIdleSP.top) / 2 });
-				pAction->MouseRClick({ (GameAssist::g_rcRoleIdleSP.right + GameAssist::g_rcRoleIdleSP.left) / 2, (GameAssist::g_rcRoleIdleSP.bottom + GameAssist::g_rcRoleIdleSP.top) / 2 });
-			}
-
-			Sleep(800);
-		}
+		pAction->StartRepeat();
 	}
 }
 
-
 void CGameAssistDlg::OnBnClickedButton11() // Ë¢ÐÂ;
 {
 	std::vector<DWORD> vtPID;