Browse Source

SP HP函数判断

Jeff 3 years ago
parent
commit
0e6206ef60

+ 14 - 1
GameAssist/GameAssist/Assist.cpp

@@ -943,12 +943,25 @@ namespace ImgAssist
 		return (lv_nMaxVal >= lowestMatchValue ? TRUE : FALSE);
 	}
 
-	int GetColorOccupiedLength(std::string strImg, COLORREF color)
+	int GetColorOccupiedLength(std::string strImg, int r, int g, int b)
 	{
 		cv::Mat src = cv::imread(strImg.c_str());
 		// 获取图片的矩形大小;
 		int width = src.cols;
 		int height = src.rows;
+
+		int i = 0;
+		for ( ; i < width; ++i )
+		{
+			cv::Vec3b pixel = src.at<cv::Vec3b>(height / 2, i);	// 读取第 height / 2行 第 i 列像素值;
+			if (abs(pixel[0] - b) <= 3 && abs(pixel[1] - g) <= 3 && abs(pixel[2] - r) <= 3)
+			{
+				continue;
+			}
+		}
+		src.release();
+
+		return i/width;
 	}
 
 };

+ 1 - 1
GameAssist/GameAssist/Assist.h

@@ -43,7 +43,7 @@ namespace ImgAssist {
 	BOOL CropPicture(HWND hWnd, CRect rc, const char* szSaveName); // 剪裁图片;
 	BOOL IsSimilarPicture(const char* szp1, const char* szp2, double lowestMatchValue = 0.99);
 	// 获取指定颜色占用矩形长度比例;
-	int GetColorOccupiedLength(std::string strImg, COLORREF color);
+	int GetColorOccupiedLength(std::string strImg, int r, int g, int b);
 };
 
 // 所有坐标,都是基于游戏窗口的相对坐标值;

+ 12 - 6
GameAssist/GameAssist/CAction.cpp

@@ -485,11 +485,11 @@ SRAND(80,120);
 		RECT rect = { 0,0,0,0 };
 		if (IsFighting())
 		{
-			rect = IsRole ? RECT{ 0, 0, 0, 0 } : RECT{ 0, 0, 0, 0 };
+			rect = IsRole ? RECT{ 656, 46, 717, 52 } : RECT{ 766, 46, 800, 52 };
 		}
 		else
 		{
-			rect = IsRole ? RECT{ 0, 0, 0, 0 } : RECT{ 0, 0, 0, 0 };
+			rect = IsRole ? RECT{ 58, 46, 119, 52 } : RECT{ 168, 46, 202, 52 };
 		}
 
 		// ½ØÍ¼;
@@ -497,21 +497,27 @@ SRAND(80,120);
 		_stprintf_s(szSPImg, _T("%s%p_SPValue.bmp"), GameGlobal::g_szTempDir, m_hGameWnd);
 		ImgAssist::CropPicture(m_hGameWnd, rect, szSPImg);
 
-		return false;
+		return ImgAssist::GetColorOccupiedLength(szSPImg, 8, 96, 248) < nSafeValue;
 	}
 
 	bool CAction::IsHPBelowSafeValue(BOOL IsRole, int nSafeValue /*= 30*/)
 	{
+		RECT rect = { 0,0,0,0 };
 		if (IsFighting())
 		{
-
+			rect = IsRole ? RECT{ 656, 34, 717, 40 } : RECT{ 766, 34, 800, 40 };
 		}
 		else
 		{
-
+			rect = IsRole ? RECT{ 58, 34, 119, 40 } : RECT{ 168, 34, 202, 40 };
 		}
 
-		return false;
+		// ½ØÍ¼;
+		TCHAR szSPImg[MAX_PATH] = { 0 };
+		_stprintf_s(szSPImg, _T("%s%p_HPValue.bmp"), GameGlobal::g_szTempDir, m_hGameWnd);
+		ImgAssist::CropPicture(m_hGameWnd, rect, szSPImg);
+
+		return ImgAssist::GetColorOccupiedLength(szSPImg, 248, 56, 64) < nSafeValue;
 	}
 
 	void CAction::FightingJY(BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill)

+ 2 - 0
GameAssist/GameAssist/GameAssist.cpp

@@ -322,6 +322,8 @@ BOOL CGameAssistApp::InitInstance()
 	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void**)&pCreateDevEnum);
 #endif
 
+	
+
 	// 标准初始化
 	// 如果未使用这些功能并希望减小
 	// 最终可执行文件的大小,则应移除下列

+ 3 - 1
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -377,7 +377,9 @@ void CGameAssistDlg::OnBnClickedButton2()  // 
 
 	if (bCropPicture)
 	{
-		ImgAssist::CropPicture(hWnd, { nX, nY, nX2, nY2 }, _T("²Ã¼ô½á¹û.bmp"));
+		std::string strImg = GameGlobal::g_szTempDir;
+		strImg.append(_T("²Ã¼ô½á¹û.bmp"));
+		ImgAssist::CropPicture(hWnd, { nX, nY, nX2, nY2 }, strImg.c_str());
 	}
 	else
 	{