Explorar o código

新增FindNPC函数。

Jeff %!s(int64=4) %!d(string=hai) anos
pai
achega
554817d2a6
Modificáronse 1 ficheiros con 20 adicións e 28 borrados
  1. 20 28
      GameAssist/GameAssist/GameAssistDlg.cpp

+ 20 - 28
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -17,6 +17,7 @@
 
 BOOL IsWalkStop(HWND hWnd);
 CRect FindMatchIcon(HWND hWnd, LPCSTR lpszTemplateImage);
+void WorldMapPositioning(HWND hWnd, POINT ptMap);
 
 VOID DebugLog(CHAR* pszStr, ...)
 {
@@ -72,34 +73,25 @@ BOOL FindNPC(HWND hWnd, LPCSTR lpszNPC)
 	return bFind;
 }
 
+BOOL FindNPC(HWND hWnd, POINT ptMap, LPCTSTR lpszTemplate)
+{
+	WorldMapPositioning(hWnd, ptMap);
+	CRect rc = FindMatchIcon(hWnd, lpszTemplate);
+	if (rc.IsRectEmpty() || rc.IsRectNull())
+		return FALSE;
+
+	// 找到目标,单击;
+	GAssist::MouseMove(hWnd, CPoint(rc.left, rc.top));
+	// 单击:我要挑战他们;
+	GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2), TRUE);
+	SRAND(900, 1500);// 等对话框出现;
+
+	return TRUE;
+}
+
 // 单击对话框里的步骤;
 BOOL ClickDlgSetup(HWND hWnd, LPCSTR lpszTemplateImage)
 {
-#if 0
-	CRect rc;
-	TCHAR szTemplateImage[MAX_PATH] = { 0 };
-	// 先截图;
-	::ShowWindow(hWnd, SW_SHOWNORMAL);
-	::SetForegroundWindow(hWnd);
-	DebugLog(_T("ClickDlgSetup=%s"), lpszTemplateImage);
-	GAssist::SaveHwndToBmpFile(hWnd, GAssist::g_strAppdir + _T("Game.bmp")); SRAND(200, 500);
-	_stprintf_s(szTemplateImage, _T("%s%s"), GAssist::g_strAppdir.c_str(), lpszTemplateImage);
-	if (GAssist::GetImgMatchtemplate(GAssist::g_strAppdir + _T("Game.bmp"), szTemplateImage, rc)) {
-		// 找到匹配的模块;
-		GAssist::MouseMove(hWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
-		DebugLog(_T("移动鼠标"));
-		GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
-		SRAND(300, 600);	// 进入孤独洞要时间切换地图;
-		// 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
-		GAssist::MouseMove(hWnd, CPoint(rc.right + RAND(5, 12), rc.bottom + RAND(5, 10)));
-		SRAND(200, 500);	// 进入孤独洞要时间切换地图;
-		DebugLog(_T("===> 找到目标并单击成功:%s"), lpszTemplateImage);
-		return TRUE;
-	}
-
-	DebugLog(_T("<==== 没有找到目标:%s"), lpszTemplateImage);
-	return FALSE;
-#else
 	CRect rc = FindMatchIcon(hWnd, lpszTemplateImage);
 	if (rc.IsRectEmpty() || rc.IsRectNull())
 		return FALSE;
@@ -108,10 +100,10 @@ BOOL ClickDlgSetup(HWND hWnd, LPCSTR lpszTemplateImage)
 	GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
 	SRAND(200, 300);
 	// 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
-	GAssist::MouseMove(hWnd, CPoint(rc.right + RAND(5, 12), rc.bottom + RAND(5, 10)));
+	GAssist::MouseMove(hWnd, CPoint(rc.top - RAND(5, 12), rc.left - RAND(5, 10))); // 移动到左上角;
 	SRAND(300, 500);
+
 	return TRUE;
-#endif
 }
 
 CRect FindMatchIcon(HWND hWnd, LPCSTR lpszTemplateImage)
@@ -628,7 +620,7 @@ void WorldMapPositioning(HWND hWnd, POINT ptMap)
 {
 	CRect rc;
 	//// 打开世界地图;
-	GAssist::SendKey(hWnd, VK_TAB); SRAND(500, 600);
+	GAssist::SendKey(hWnd, VK_TAB); SRAND(300, 500);
 	// 判断是否打开了地图;
 	if (!GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\世界地图.bmp"), rc))
 		return;