Procházet zdrojové kódy

判断是否我方攻击时,不要每次都移动鼠标。

Wang Jeff před 4 roky
rodič
revize
4295709eae
2 změnil soubory, kde provedl 72 přidání a 162 odebrání
  1. 71 161
      GameAssist/GameAssist/GameAssistDlg.cpp
  2. 1 1
      GameAssist/img/jnmap.bin

+ 71 - 161
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -76,11 +76,11 @@ BOOL ClickDlgSetup(HWND hWnd, LPCSTR lpszTemplateImage)
 		// 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
 		GAssist::MouseMove(hWnd, CPoint(rc.right + RAND(5, 12), rc.bottom + RAND(5, 10)));
 		SRAND(200, 500);	// 进入孤独洞要时间切换地图;
-		DebugLog(_T("找到目标并单击成功:%s"), lpszTemplateImage);
+		DebugLog(_T("===> 找到目标并单击成功:%s"), lpszTemplateImage);
 		return TRUE;
 	}
 
-	DebugLog(_T("没有找到目标:%s"), lpszTemplateImage);
+	DebugLog(_T("<==== 没有找到目标:%s"), lpszTemplateImage);
 	return FALSE;
 }
 
@@ -132,67 +132,6 @@ BOOL IsBattle(HWND hWnd)
 // 
 BOOL IsWattingAttack(HWND hWnd, int nAttackNPCType)
 {
-#if 0
-	// 先截图
-	BOOL bIsAttack = FALSE;
-	GAssist::SaveHwndToBmpFile(hWnd, GAssist::g_strAppdir + _T("IsWattingAttack.bmp"));
-	cv::Mat srcImg, tempImg, matchImg;
-	if (!GAssist::OpenImage(GAssist::g_strAppdir + _T("IsWattingAttack.bmp"), srcImg)) {
-		if (srcImg.data) srcImg.release();
-		if (tempImg.data) tempImg.release();
-		return bIsAttack;
-	}
-
-	// 指定区域进行二值化;
-	cv::Mat imgThreshold;
-	cv::Mat imgROI = srcImg(cv::Rect(350, 55, 50, 60));
-	//cv::imwrite("IsWattingAttack-match.bmp", imgROI);
-	if (GAssist::SetImgThreshold(imgROI, imgThreshold, 150, 255))
-	{
-		if (imgThreshold.data) {
-			// 轮廓;
-			std::vector<std::vector<cv::Point>> contours;
-			// 轮廓关系;
-			std::vector<cv::Vec4i> hierarchy;
-			// 查找轮廓;
-			contours.clear();
-			hierarchy.clear();
-
-			// 所有轮廓,内外轮廓分等级;
-			//findContours(imgROI, m_contours, m_hierarchy, cv::RETR_CCOMP, cv::CHAIN_APPROX_SIMPLE);
-			// 所有轮廓,内外轮廓不分等级,独立;
-			//findContours(m_ImgThreshold, m_contours, m_hierarchy, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
-			// RETR_EXTERNAL=只检索最外面的轮廓;
-			findContours(imgThreshold, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
-
-#if 1
-			double length, area;
-			// 找出白色区域的面积或周长;
-			std::vector<std::vector<cv::Point>>::iterator it = contours.begin();
-			for (; it != contours.end(); it++)
-			{
-				length = arcLength(*it, true); area = contourArea(*it);
-				if (length > 130 && area > 550.0)
-				{
-					//DebugLog(_T("当前周长和面积:%lf, %lf"), length, area);
-					bIsAttack = TRUE;
-					break;
-				}
-			}
-#else
-			// 只要白色区域个数>=2
-			if (contours.size() >= 2)
-				bIsAttack = TRUE;
-#endif
-		}
-	}
-
-	if (imgROI.data) imgROI.release();
-	if (srcImg.data) srcImg.release();
-	if (tempImg.data) tempImg.release();
-
-	return bIsAttack;
-#else
 	CRect rc;
 	BOOL bIsAttack = FALSE;
 	switch (nAttackNPCType)
@@ -212,8 +151,8 @@ BOOL IsWattingAttack(HWND hWnd, int nAttackNPCType)
 		{
 			// 将鼠标移动到指定位置;
 			DebugLog(_T("IsWattingAttack:职业挑战中……"));// 要求角色:自定全黑头像;
-			POINT ptDest = { 625, 28 }; // 左上角;
-			GAssist::MouseMove(hWnd, ptDest);
+			//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;
@@ -225,7 +164,6 @@ BOOL IsWattingAttack(HWND hWnd, int nAttackNPCType)
 	}
 
 	return bIsAttack;
-#endif
 }
 
 void BattleOnece(HWND hWnd, BOOL bHasSummoner)
@@ -623,6 +561,34 @@ void AttachGDD(HWND hWnd)
 	// 人物技能:Alt+S,双击选中,单击敌人;
 }
 
+
+// 使用快捷键来处理:读取配置文件
+auto FindJNShortCut = [](LPCTSTR lpSkillName, int& nKeyValue, int& nSkilltime)->BOOL {
+	// 读取文件:jnmap.bin
+	// 格式:技能=快捷键的键值;
+	std::string line;
+	std::ifstream ifJN("img\\jnmap.bin");
+	if (ifJN)
+	{
+		TCHAR szKeyValue[MAX_PATH] = { 0 };
+		TCHAR szSkillName[MAX_PATH] = { 0 };
+		TCHAR szSkillTime[MAX_PATH] = { 0 };
+		while (std::getline(ifJN, line))
+		{
+			int nRet = _stscanf_s(line.c_str(), _T("%[^;];%[^;];%s"), szSkillName, MAX_PATH, szKeyValue, MAX_PATH, szSkillTime, MAX_PATH);
+			if (nRet == 3 && _tcsicmp(lpSkillName, szSkillName) == 0) {
+				// 将快捷键值
+				nKeyValue = atol(szKeyValue);
+				nSkilltime = atol(szSkillTime);
+				return TRUE;
+			}
+		}
+	}
+
+	// 没有找到jnmap.bin文件;
+	return FALSE;
+};
+
 // 挑战医师;
 void BattleYS(HWND hWnd, const char* lpszJN)
 {
@@ -653,7 +619,9 @@ void BattleYS(HWND hWnd, const char* lpszJN)
 		rc = FindMatchIcon(hWnd, _T("img\\gdd\\离开这里.bmp"));
 		if (!rc.IsRectEmpty() && !rc.IsRectNull())
 		{
+			SRAND(150,250);
 			// 只有离开这里:已经打过,右键并退出 ;
+			DebugLog("只有离开这里:已经打过,右键并退出");
 			GAssist::MouseRClick(hWnd);
 		}
 		else
@@ -690,6 +658,8 @@ void BattleYS(HWND hWnd, const char* lpszJN)
 						// 找到目标,单击;
 						GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2), TRUE);
 						SRAND(300, 500);
+						// 移动下,防止高亮识别失败;
+						GAssist::MouseMoveEx(hWnd, { rc.left, rc.top }, { rc.right + rand() % 10, rc.bottom + rand() % 10 });
 					}
 
 					ClickDlgSetup(hWnd, _T("img\\确定.bmp"));
@@ -739,63 +709,44 @@ void BattleYS(HWND hWnd, const char* lpszJN)
 		}
 	}
 
+	int KeyValue, SkillTime;
 	// 进入战斗;
 	if (bBattle)
 	{
 		// 人物:Alt+S显示技能,双击选择技能,单击怪物发动技能;
 		// 注:有的人物技能太多,导致会有滚动条:这是有难点;
-		// 使用快捷键来处理:读取配置文件
-		auto FindJNShortCut = [](LPCTSTR lpSkillName)->int {
-			// 读取文件:jnmap.bin
-			// 格式:技能=快捷键的键值;
-			std::string line;
-			std::ifstream ifJN("img\\jnmap.bin");
-			if (ifJN)
-			{
-				TCHAR szKeyValue[MAX_PATH] = { 0 };
-				TCHAR szSkillName[MAX_PATH] = { 0 };
-				while (std::getline(ifJN, line))
-				{
-					int nRet = _stscanf_s(line.c_str(), _T("%[^=]%s"), szSkillName, MAX_PATH, szKeyValue, MAX_PATH);
-					if (nRet == 2 && _tcsicmp(lpSkillName, szSkillName) == 0) {
-						// 将快捷键值
-						return atol(szKeyValue);
-					}
-				}
-			}
-
-			// 没有找到jnmap.bin文件;
-			return -1;
-		};
-
-		int KeyValue = FindJNShortCut(lpszJN);
+		BOOL bRet = FindJNShortCut(lpszJN, KeyValue, SkillTime);
 		DebugLog("快捷键值=%ld", KeyValue);
 		if (KeyValue != -1)
 		{
 			// 快捷键;
 			GAssist::SendKey(hWnd, KeyValue);
-			SRAND(200, 300);
+			SRAND(260, 380);
 			// 单击指定位置;
-			GAssist::MouseClick(hWnd, 300, 160);
+			GAssist::MouseClick(hWnd, 280, 150);
+			// 将鼠标移动到指定位置;
+			POINT ptDest = { 625, 28 }; // 左上角;
+			GAssist::MouseMove(hWnd, ptDest);
+
 			for (int i = 0; i < 5; i++)
 			{
 				// 判断是否我方攻击;
 				while (!IsWattingAttack(hWnd, 1))
 				{
-					Sleep(RAND(9600, 1500));
+					Sleep(RAND(900, 1200));
 				}
-
-				GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
-				Sleep(RAND(600, 1200));
+				SRAND(SkillTime, SkillTime + 200);
+				//GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
 			}
 		}
 	}
 
+	if (bBattle) SRAND(SkillTime + 1500, SkillTime + 1600); // 等待切回非战斗;
 	// 右键退出;
 	GAssist::MouseRClick(hWnd);
 }
 
-void BattleOthers(HWND hWnd, const char* lpszName)
+void BattleOthers(HWND hWnd, const char* lpszName, const char * lpszSkillName)
 {
 	CRect rc;
 	BOOL bBattle = FALSE;
@@ -823,22 +774,34 @@ void BattleOthers(HWND hWnd, const char* lpszName)
 		rc = FindMatchIcon(hWnd, _T("img\\gdd\\离开这里.bmp"));
 	}
 
+	int KeyValue, SkillTime;
 	if (bBattle) {
+		BOOL bRet = FindJNShortCut(lpszSkillName, KeyValue, SkillTime);
+		// 将鼠标移动到指定位置;
+		POINT ptDest = { 625, 28 }; // 左上角;
+		GAssist::MouseMove(hWnd, ptDest);
 		for (int i = 0; i < 6; i++)
 		{
 			// 判断是否我方攻击;
 			while (!IsWattingAttack(hWnd, 1))
 			{
-				Sleep(RAND(9600, 1500));
+				Sleep(RAND(1000, 1500));
 			}
 
 			GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
-			Sleep(RAND(600, 1200));
+			//SRAND(SkillTime, SkillTime + 150);
 		}
 	}
 
+	if (bBattle) SRAND(SkillTime + 1500, SkillTime + 1600); // 等待切回非战斗;
 	// 右键退出;
-	GAssist::MouseRClick(hWnd);
+	if ( _tcsicmp(lpszName, _T("魂武独侠")) )
+		GAssist::MouseRClick(hWnd);
+	else
+	{
+		// 回到应天府;
+		//ClickDlgSetup(hWnd, _T(""));
+	}
 }
 
 // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
@@ -1212,7 +1175,10 @@ void CGameAssistDlg::OnBnClickedButton2()  // 
 	HWND hProWnd = GAssist::GetProcessMainWnd();
 	//IsWattingAttack(hProWnd, 1);
 	//BattleYS(hProWnd, "缚神诀");
-	BattleOthers(hProWnd, "术士独侠");
+	char szName[10][32] = { "术士独侠","道士独侠","武师独侠","浪子独侠",
+		"剑客独侠","弓手独侠","禁卫独侠","墨者独侠","巫煞独侠","魂武独侠" };
+
+	BattleOthers(hProWnd, szName[9], _T("缚神诀"));
 //	auto FindJNShortCut = [](LPCTSTR lpSkillName)->int {
 //		// 读取文件:jnmap.bin
 //		// 格式:技能=快捷键的键值;
@@ -1236,7 +1202,8 @@ void CGameAssistDlg::OnBnClickedButton2()  // 
 //		return -1;
 //		};
 //
-//	int KeyValue = FindJNShortCut("缚神诀");
+	//int KeyValue, SkillTime;
+	//FindJNShortCut("缚神诀", KeyValue, SkillTime);
 #endif
 
 #if 0
@@ -1312,63 +1279,6 @@ void CGameAssistDlg::OnBnClickedButton3() // 
 		BattleJY(hProWnd, m_cbSummoner.GetCheck(), m_cbZJ.GetCheck());
 		DebugLog(_T("end.打镜妖 %d----------------------------\n"), i);
 	}
-
-#if 0
-	if (IsOnMap(hProWnd, _T("img\\地图\\贫民房.bmp")))
-		goto battle;
-
-	rc = FindNPC(hProWnd, "臭美的小米");
-
-	// 选择进入;
-	BOOL bMatch = FALSE;
-	int trySize = 20;
-	// 我要挑战他们;
-	while ( !(bMatch = ClickDlgSetup(hProWnd, _T("img\\活动\\镜妖\\1-我帮您抓.bmp"))) ) {
-		SRAND(800, 1200);
-		if (!trySize--) break;
-	}
-
-	if (bMatch) {
-		GAssist::MouseMove(hProWnd, CPoint(rc.left, rc.top));
-		// 单击:我要挑战他们;
-		GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2), TRUE);
-		SRAND(1000, 1500);// 等出图;
-
-		// 移动一下;
-		GAssist::MouseMove(hProWnd, CPoint(rc.left, rc.top));
-		::SetCursorPos(rc.left + rand() % 6, rc.top + rand() % 8);
-
-		// 是否第一次进入地图;
-		if ( ClickDlgSetup(hProWnd, _T("img\\活动\\镜妖\\2-我这就去.bmp")))
-		{
-			SRAND(600,1200);
-			if ( ClickDlgSetup(hProWnd, _T("img\\活动\\镜妖\\3-战意镜妖.bmp")))
-			{
-				SRAND(600, 1800);
-				if ((bMatch = ClickDlgSetup(hProWnd, _T("img\\活动\\镜妖\\4-我就选择它.bmp"))))
-				{
-					SRAND(800, 1800);
-				}
-			}
-		}
-	}
-
-battle:
-	if (IsOnMap(hProWnd, _T("img\\地图\\贫民房.bmp"))) {
-		GAssist::MouseMove(hProWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
-		GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
-		SRAND(1500, 2000);// 进入孤独洞要时间切换地图;
-		DebugLog(_T("进入贫民房"));
-
-		// 找镜妖;
-		for (int i = 0; i < 100; i++)
-		{
-			DebugLog(_T("start.打镜妖 %d----------------------------"), i);
-			BattleJY(hProWnd, m_cbSummoner.GetCheck());
-			DebugLog(_T("end.打镜妖 %d----------------------------\n"), i);
-		}
-	}
-#endif
 }
 
 
@@ -1448,7 +1358,7 @@ void CGameAssistDlg::OnBnClickedButton6() // 职业
 			BattleYS(hProWnd, "缚神诀");
 			for (int i = 0; i < 10; i++)
 			{
-				BattleOthers(hProWnd, szName[i]);
+				BattleOthers(hProWnd, szName[i], "缚神诀");
 			}
 		}
 	}

+ 1 - 1
GameAssist/img/jnmap.bin

@@ -1 +1 @@
-╦©иЯ╬В=118
+╦©иЯ╬В;118;3000