浏览代码

完善FindNPC函数

Jeff 4 年之前
父节点
当前提交
dcd226f94e
共有 1 个文件被更改,包括 69 次插入59 次删除
  1. 69 59
      GameAssist/GameAssist/GameAssistDlg.cpp

+ 69 - 59
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -16,7 +16,7 @@
 #define SRAND(a,b) (Sleep(rand()%(b-a)+a))
 
 BOOL IsWalkStop(HWND hWnd);
-
+CRect FindMatchIcon(HWND hWnd, LPCSTR lpszTemplateImage);
 
 VOID DebugLog(CHAR* pszStr, ...)
 {
@@ -32,13 +32,13 @@ VOID DebugLog(CHAR* pszStr, ...)
 }
 
 
-CRect FindNPC(HWND hWnd, LPCSTR lpszNPC)
+BOOL FindNPC(HWND hWnd, LPCSTR lpszNPC)
 {
 	CRect rc;
 	//// 打开世界地图;
 	GAssist::SendKey(hWnd, VK_TAB); SRAND(500, 600);
 	if (!GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\寻路窗口.bmp"), rc))
-		return rc;
+		return FALSE;
 
 	//// 单击寻路窗口;
 	GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 2, (rc.top + rc.bottom) / 2 + rand() % 2)); SRAND(500, 800);
@@ -53,10 +53,23 @@ CRect FindNPC(HWND hWnd, LPCSTR lpszNPC)
 	//// 退出世界地址;
 	GAssist::SendKey(hWnd, VK_TAB); SRAND(200, 300);
 
-	// 问题:返回TRUE并不表示到寻路到NPC;
-	// 是否成功寻路到NPC要对NPC人物进向模板匹配或与NPC对话框模板匹配
+	// 直到停止走动为止;
+	IsWalkStop(hWnd);
 
-	return rc;
+	// 遍历3次;
+	BOOL bFind = FALSE;
+	for (int i = 0; i < 3; i++)
+	{
+		Sleep(600);
+		rc = FindMatchIcon(hWnd, "img\\对话框关闭按钮.bmp");
+		if (!rc.IsRectEmpty() && !rc.IsRectNull())
+		{
+			bFind = TRUE;
+			break;
+		}
+	}
+
+	return bFind;
 }
 
 // 单击对话框里的步骤;
@@ -139,31 +152,31 @@ BOOL IsWattingAttack(HWND hWnd, int nAttackNPCType)
 	BOOL bIsAttack = FALSE;
 	switch (nAttackNPCType)
 	{
-	case 0:
-	{	// 将鼠标移动到指定位置;
-		DebugLog(_T("IsWattingAttack:镜妖中……"));
-		POINT ptDest = { 20, 50 }; // 左上角;
-		GAssist::MouseMove(hWnd, ptDest);
-		if (GAssist::IsMatchIcon(hWnd, GAssist::g_strAppdir + _T("img\\我方攻击.bmp"), { 0, 50, 60, 115 }, rc)) {
-			DebugLog(_T("IsWattingAttack:我方攻击"));
-			bIsAttack = TRUE;
+		case 0:
+		{	// 将鼠标移动到指定位置;
+			DebugLog(_T("IsWattingAttack:镜妖中……"));
+			POINT ptDest = { 20, 50 }; // 左上角;
+			GAssist::MouseMove(hWnd, ptDest);
+			if (GAssist::IsMatchIcon(hWnd, GAssist::g_strAppdir + _T("img\\我方攻击.bmp"), { 0, 50, 60, 115 }, rc)) {
+				DebugLog(_T("IsWattingAttack:我方攻击"));
+				bIsAttack = TRUE;
+			}
+			break;
 		}
-		break;
-	}
-	case 1:
-	{
-		// 将鼠标移动到指定位置;
-		DebugLog(_T("IsWattingAttack:职业挑战中……"));// 要求角色:自定全黑头像;
-		//POINT ptDest = { 625, 28 }; // 左上角;
-		//GAssist::MouseMove(hWnd, ptDest);
-		if (!GAssist::IsMatchIcon(hWnd, GAssist::g_strAppdir + _T("img\\战斗中.bmp"), { 600, 25, 655, 80 }, rc)) {
-			DebugLog(_T("IsWattingAttack:我方攻击"));
-			bIsAttack = TRUE;
+		case 1:
+		{
+			// 将鼠标移动到指定位置;
+			DebugLog(_T("IsWattingAttack:职业挑战中……"));// 要求角色:自定全黑头像;
+			//POINT ptDest = { 625, 28 }; // 左上角;
+			//GAssist::MouseMove(hWnd, ptDest);
+			if (!GAssist::IsMatchIcon(hWnd, GAssist::g_strAppdir + _T("img\\战斗中.bmp"), { 600, 25, 655, 80 }, rc)) {
+				DebugLog(_T("IsWattingAttack:我方攻击"));
+				bIsAttack = TRUE;
+			}
+			break;
 		}
-		break;
-	}
-	default:
-		break;
+		default:
+			break;
 	}
 
 	return bIsAttack;
@@ -195,7 +208,9 @@ void BattleOnece(HWND hWnd, BOOL bHasSummoner)
 		if (!IsOnMap(hWnd, _T("img\\地图\\贫民房.bmp")))
 		{
 			// 找小米;
-			CRect rc = FindNPC(hWnd, "臭美的小米");
+			CRect rc;
+			if (!FindNPC(hWnd, "臭美的小米"))
+				return;
 
 			// 选择进入;
 			BOOL bMatch = FALSE;
@@ -302,7 +317,7 @@ void BattleJY(HWND hWnd, BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill)
 					DebugLog(_T("BattleJY:召唤兽技能选择"));
 
 					// 选择重击;
-					if ( nZJType ) {
+					if (nZJType) {
 						SRAND(150, 350);
 						GAssist::SendKey(hWnd, VK_S, FALSE, TRUE);
 						DebugLog(_T("BattleJY:召唤兽技能选择:%d"), nZJType);
@@ -338,7 +353,9 @@ void BattleJY(HWND hWnd, BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill)
 	// 非战斗中,是否在贫民房中;
 	if (!IsOnMap(hWnd, _T("img\\地图\\贫民房.bmp"))) {
 		// 找小米;
-		CRect rc = FindNPC(hWnd, "臭美的小米");
+		CRect rc;
+		if (!FindNPC(hWnd, "臭美的小米"))
+			return;
 
 		// 选择进入;
 		BOOL bMatch = FALSE;
@@ -410,7 +427,7 @@ void BattleJY(HWND hWnd, BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill)
 		// 我来抓你;
 		if (GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
 			// 找到匹配的模块;
-			SRAND(200,300);
+			SRAND(200, 300);
 			//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);
@@ -424,7 +441,9 @@ void BattleJY2(HWND hWnd, BOOL bSummoner)
 {
 	if (!IsOnMap(hWnd, _T("img\\地图\\贫民房.bmp"))) {
 		// 找小米;
-		CRect rc = FindNPC(hWnd, "臭美的小米");
+		CRect rc;
+		if (!FindNPC(hWnd, "臭美的小米"))
+			return;
 
 		// 选择进入;
 		BOOL bMatch = FALSE;
@@ -640,13 +659,8 @@ void BattleYS(HWND hWnd, const char* lpszJN)
 {
 	CRect rc;
 	BOOL bBattle = FALSE;
-	FindNPC(hWnd, "医师独侠");
-
-	do
-	{
-		rc = FindMatchIcon(hWnd, "img\\对话框关闭按钮.bmp");
-		Sleep(900);
-	} while (rc.IsRectEmpty() || rc.IsRectNull());
+	if (!FindNPC(hWnd, "医师独侠"))
+		return;
 
 	// 废话少说:表示这个没打过;
 	rc = FindMatchIcon(hWnd, _T("img\\gdd\\废话少说.bmp"));
@@ -709,7 +723,7 @@ void BattleYS(HWND hWnd, const char* lpszJN)
 					}
 
 					ClickDlgSetup(hWnd, _T("img\\确定.bmp"));
-					SRAND(150, 200);
+					SRAND(250, 300);
 
 					// 战斗;
 					return 0;
@@ -810,12 +824,6 @@ void BattleOthers(HWND hWnd, const char* lpszName, const char* lpszSkillName)
 	}
 	FindNPC(hWnd, lpszName);
 
-	do
-	{
-		rc = FindMatchIcon(hWnd, "img\\对话框关闭按钮.bmp");
-		Sleep(900);
-	} while (rc.IsRectEmpty() || rc.IsRectNull());
-
 	// 废话少说:表示这个没打过;
 	rc = FindMatchIcon(hWnd, _T("img\\gdd\\废话少说.bmp"));
 	if (!rc.IsRectEmpty() && !rc.IsRectNull())
@@ -826,6 +834,7 @@ void BattleOthers(HWND hWnd, const char* lpszName, const char* lpszSkillName)
 		// 确定
 		bBattle = TRUE;
 		ClickDlgSetup(hWnd, _T("img\\确定.bmp"));
+		SRAND(250, 350);
 	}
 	else
 	{
@@ -1336,7 +1345,7 @@ void CGameAssistDlg::OnBnClickedButton2()  // 
 	else
 	{
 		i = 0;
-	}
+}
 #endif
 	// 	GAssist::MouseMove(hProWnd, CPoint(290 - 5, 140 - 20));
 	// 
@@ -1407,7 +1416,7 @@ void CGameAssistDlg::OnBnClickedButton4() // 
 			struct MyStruct
 			{
 				BOOL bDone = FALSE;
-				TCHAR szQuestion[MAX_PATH] = {0};
+				TCHAR szQuestion[MAX_PATH] = { 0 };
 			};
 
 			if (ClickDlgSetup(hWnd, _T("img\\活动\\周六礼物\\铜钱怪:好的,要问些什么问题呢?.bmp")))
@@ -1423,7 +1432,7 @@ void CGameAssistDlg::OnBnClickedButton4() // 
 
 				for (; vtMyst1.size();)
 				{
-					for (std::vector<MyStruct>::iterator it = vtMyst1.begin(); it != vtMyst1.end(); it++ )
+					for (std::vector<MyStruct>::iterator it = vtMyst1.begin(); it != vtMyst1.end(); it++)
 					{
 						rc = FindMatchIcon(hWnd, it->szQuestion);
 						if (!rc.IsRectEmpty() && !rc.IsRectNull())
@@ -1475,7 +1484,7 @@ void CGameAssistDlg::OnBnClickedButton4() // 
 			FindNPC(hWnd, _T("送礼协会会长丙"));
 			IsWalkStop(hWnd);
 			// 再右键一次;
-			SRAND(200,300);
+			SRAND(200, 300);
 			GAssist::MouseRClick(hWnd);
 			FindNPC(hWnd, _T("送礼协会会长丙"));
 			if (ClickDlgSetup(hWnd, _T("img\\活动\\周六礼物\\好,现在就去.bmp")))
@@ -1486,7 +1495,7 @@ void CGameAssistDlg::OnBnClickedButton4() // 
 		}
 	}
 
-	if (IsOnMap(hWnd, _T("img\\地图\\汴京城.bmp")) )
+	if (IsOnMap(hWnd, _T("img\\地图\\汴京城.bmp")))
 	{
 		// 找送礼协会会长丁
 		FindNPC(hWnd, _T("送礼协会会长丁"));
@@ -1621,7 +1630,8 @@ void CGameAssistDlg::OnBnClickedButton6() // 职业
 	CRect rc;
 	DebugLog(_T("进入孤独洞========="));
 	HWND hProWnd = GAssist::GetProcessMainWnd();
-	rc = FindNPC(hProWnd, "职业训导大师");
+	if (!FindNPC(hProWnd, "职业训导大师"))
+		return;
 
 	// 选择进入;
 	BOOL bMatch = FALSE;
@@ -1684,7 +1694,7 @@ void CGameAssistDlg::OnBnClickedButton9() // 
 	BOOL bOpenMap = ((CButton*)GetDlgItem(IDC_CHECK4))->GetCheck();
 
 	if (bOpenMap)
-		WorldMapPositioning(hWnd, {nX, nY});
+		WorldMapPositioning(hWnd, { nX, nY });
 	else
 		GAssist::MouseMove(hWnd, { nX, nY });
 }
@@ -1706,10 +1716,10 @@ void CGameAssistDlg::OnBnClickedButton10()
 
 
 
-		UpdateData(FALSE);
-		DebugLog(_T("start.打镜妖 %d----------------------------"));
-		BattleJY(hProWnd, m_cbSummoner.GetCheck(), nZJType, m_cbAggressiveSkill.GetCheck());
-		DebugLog(_T("end.打镜妖 %d----------------------------\n"));
+	UpdateData(FALSE);
+	DebugLog(_T("start.打镜妖 %d----------------------------"));
+	BattleJY(hProWnd, m_cbSummoner.GetCheck(), nZJType, m_cbAggressiveSkill.GetCheck());
+	DebugLog(_T("end.打镜妖 %d----------------------------\n"));
 
 }