Jeff há 4 anos atrás
pai
commit
03825e5c40

+ 14 - 10
GameAssist/GameAssist/Assist.cpp

@@ -1551,20 +1551,20 @@ namespace GameAssist
 		if (!hClipString)
 			goto end;
 
-		/*char* lpBuffer = (char*)GlobalLock(hClipString);
+		char* lpBuffer = (char*)GlobalLock(hClipString);
 		if (!lpBuffer)
-			goto end;*/
-
-			//bRet = TRUE;
-			//_tcscpy_s(lpBuffer, _tcslen(lpString) + 1, lpString);
+			goto end;
 
+		_tcscpy_s(lpBuffer, _tcslen(lpString) + 1, lpString);
+		GlobalUnlock(hClipString);
+		SetClipboardData(CF_TEXT, hClipString);
+		bRet = TRUE;
 	end:
 		if (hClipString)
-		{
-			GlobalUnlock(hClipString);
-			SetClipboardData(CF_TEXT, hClipString);
-			CloseClipboard();
-		}
+			GlobalFree(hClipString);
+		
+		CloseClipboard();
+
 		return bRet;
 	}
 
@@ -1798,7 +1798,11 @@ namespace GameGlobal
 	std::string BuildImgPath(HWND hWnd, LPCTSTR lpName)
 	{
 		TCHAR szName[MAX_PATH] = { 0 };
+		if ( lpName == NULL || lpName[0] == '\0')
+			_stprintf_s(szName, _T("%s%p.bmp"), GameGlobal::g_szCurModuleDir, hWnd);
+		else
 		_stprintf_s(szName, _T("%s%p-%s.bmp"), GameGlobal::g_szCurModuleDir, hWnd, lpName);
+
 		return std::string(szName);
 	}
 };

+ 1 - 1
GameAssist/GameAssist/Assist.h

@@ -147,7 +147,7 @@ namespace GameGlobal {
 	extern int nGameWndType;
 
 	void Init();
-	std::string BuildImgPath(HWND hWnd, LPCTSTR lpName);
+	std::string BuildImgPath(HWND hWnd, LPCTSTR lpName = NULL);
 };
 
 namespace ImgAssist {

+ 274 - 4
GameAssist/GameAssist/CAction.cpp

@@ -8,6 +8,37 @@ if (!::IsWindow(m_hGameWnd)) return;\
 ::ShowWindow(m_hGameWnd, SW_SHOWNORMAL);\
 ::SetForegroundWindow(m_hGameWnd);
 
+	std::map<std::string, POINT> g_mapZYNPC;
+	std::map<std::string, PNPC> g_mapZYNPC2;
+
+	// 使用快捷键来处理:读取配置文件
+	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;
+	};
+
+
 	ThreadSection CAction::m_ts;
 	VOID DebugLog(CHAR* pszStr, ...)
 	{
@@ -22,8 +53,9 @@ if (!::IsWindow(m_hGameWnd)) return;\
 		OutputDebugStringA(szData);
 	}
 
-	CAction::CAction(HWND hWnd) :m_hGameWnd(hWnd)
+	CAction::CAction(HWND hWnd) :m_hGameWnd(hWnd), m_ptCur({0,0})
 	{
+		InitNPCInfo();
 	}
 
 	CAction::~CAction()
@@ -34,7 +66,34 @@ if (!::IsWindow(m_hGameWnd)) return;\
 	{
 		SETGAMEFOREGROUND;
 		GameAssist::GamePos2Screen(m_hGameWnd, pt);
-		GameAssist::MouseMove(pt);
+		GameAssist::MouseMove(pt, bSetCurPos);
+	}
+
+	void CAction::MouseMove(POINT ptStart, POINT ptEnd, bool bSetCurPos)
+	{
+		SETGAMEFOREGROUND;
+		GameAssist::GamePos2Screen(m_hGameWnd, ptStart);
+		GameAssist::MouseMove(ptStart, bSetCurPos);
+
+		GameAssist::GamePos2Screen(m_hGameWnd, ptEnd);
+		GameAssist::MouseMove(ptEnd, bSetCurPos);
+	}
+
+	void CAction::MouseMoveEx(POINT pt, bool bSetCurPos)
+	{
+		SETGAMEFOREGROUND;
+		GameAssist::GamePos2Screen(m_hGameWnd, pt);
+		GameAssist::MouseClick(pt);
+	}
+
+	void CAction::MouseMoveEx(POINT ptStart, POINT ptEnd, bool bSetCurPos)
+	{
+		SETGAMEFOREGROUND;
+		GameAssist::GamePos2Screen(m_hGameWnd, ptStart);
+		GameAssist::MouseMove(ptStart, bSetCurPos);
+
+		GameAssist::GamePos2Screen(m_hGameWnd, ptEnd);
+		GameAssist::MouseClick(ptEnd);
 	}
 
 	void CAction::MouseClick()
@@ -89,6 +148,41 @@ if (!::IsWindow(m_hGameWnd)) return;\
 		GameAssist::SendKey(key, bCtrl, bAtl, bShift);
 	}
 
+	void CAction::InitNPCInfo()
+	{
+		static bool bInit = false;
+		if (!bInit) {
+			// "医师独侠","术士独侠","道士独侠","武师独侠","浪子独侠","剑客独侠", "弓手独侠", "禁卫独侠", "墨者独侠", "巫煞独侠", "魂武独侠"
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("医师独侠"), { 305, 325 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("术士独侠"), { 305, 325 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("道士独侠"), { 305, 325 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("武师独侠"), { 305, 325 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("浪子独侠"), { 160, 435 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("剑客独侠"), { 420, 215 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("弓手独侠"), { 265, 230 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("禁卫独侠"), { 155, 205 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("墨者独侠"), { 155, 205 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("巫煞独侠"), { 155, 205 }));
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("魂武独侠"), { 165, 335 }));
+			// 应天府NPC
+			g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("职业训导大师"), { 315, 415 }));
+
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("医师独侠"), { { 305, 325 }, { 590, 380 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("术士独侠"), { { 305, 325 }, { 610, 160 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("道士独侠"), { { 305, 325 }, { 140, 160 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("武师独侠"), { { 305, 325 }, { 140, 380 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("浪子独侠"), { { 160, 435 }, { 190, 370 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("剑客独侠"), { { 420, 215 }, { 540, 170 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("弓手独侠"), { { 265, 230 }, { 460, 150 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("禁卫独侠"), { { 155, 205 }, { 605, 235 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("墨者独侠"), { { 155, 205 }, { 315, 380 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("巫煞独侠"), { { 155, 205 }, { 270, 175 } }));
+			g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("魂武独侠"), { { 165, 335 }, { 270, 305 } }));
+
+			bInit = true;
+		}
+	}
+
 	void CAction::SetGameForeground()
 	{
 		AutoThreadSection ats(&m_ts);
@@ -149,7 +243,7 @@ if (!::IsWindow(m_hGameWnd)) return;\
 		DebugLog(_T("FindMatchIcon=%s"), lpszTemplateImage);
 		ImgAssist::CaptureGameWnd(m_hGameWnd); SRAND(200, 500);
 		_stprintf_s(szTemplateImage, _T("%s%s"), GameGlobal::g_strAppdir.c_str(), lpszTemplateImage);
-		if (ImgAssist::GetImgMatchtemplate(GameGlobal::BuildImgPath(m_hGameWnd, _T("Game")), szTemplateImage, rc)) {
+		if (ImgAssist::GetImgMatchtemplate(GameGlobal::BuildImgPath(m_hGameWnd), szTemplateImage, rc)) {
 			// 找到匹配的模块;
 			DebugLog(_T("====> 找到匹配目标:%s"), lpszTemplateImage);
 			return rc;
@@ -267,7 +361,7 @@ if (!::IsWindow(m_hGameWnd)) return;\
 		bool bFind = false;
 		for (int i = 0; i < 3; i++)
 		{
-			Sleep(600 - i * 150);
+			Sleep(800 - i * 150);
 			rc = FindMatchIcon(_T("img\\对话框关闭按钮.bmp"));
 			if (!rc.IsRectEmpty() && !rc.IsRectNull())
 			{
@@ -358,6 +452,20 @@ if (!::IsWindow(m_hGameWnd)) return;\
 		return bFind;
 	}
 
+	bool CAction::FindNPCByMap(LPCTSTR lpszNPCName)
+	{
+		auto it = g_mapZYNPC2.find(lpszNPCName);
+		if (it != g_mapZYNPC2.end())
+		{
+			if (FindNPCByIconAndPos(it->first.c_str(), it->second.ptMap, it->second.ptNpc))
+			{
+				return true;
+			}
+		}
+
+		return false;
+	}
+
 	void CAction::BattleJY(BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill)
 	{
 		BOOL bFirstAttack = TRUE;
@@ -504,4 +612,166 @@ if (!::IsWindow(m_hGameWnd)) return;\
 			}
 		}
 	}
+
+	void CAction::BattleYS(LPCTSTR lpszSkillName)
+	{
+		CRect rc;
+		BOOL bBattle = FALSE;
+		if (!FindNPCByMap("医师独侠"))
+			return;
+
+		// 废话少说:表示这个没打过;
+		rc = FindMatchIcon(_T("img\\gdd\\废话少说.bmp"));
+		if (!rc.IsRectEmpty() && !rc.IsRectNull())
+		{
+			// 确定
+			bBattle = TRUE;
+			MouseMove({ rc.left - RAND(30, 50), rc.top - RAND(30, 50) });
+			SRAND(20, 50);
+			MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+			SRAND(500, 800); // 切图时间长;
+			MouseMoveEx({ rc.left, rc.top }, { rc.right + rand() % 10, rc.bottom + rand() % 10 });
+			SRAND(20, 60);
+			ClickDlgSetup(_T("img\\确定.bmp"));
+		}
+		else
+		{
+			rc = FindMatchIcon(_T("img\\gdd\\离开这里.bmp"));
+			if (!rc.IsRectEmpty() && !rc.IsRectNull())
+			{
+				SRAND(150, 250);
+				// 只有离开这里:已经打过,右键并退出 ;
+				DebugLog("只有离开这里:已经打过,右键并退出");
+				MouseRClick();
+				SRAND(200, 500);
+			}
+			else
+			{
+				// 找下一页的技能:没有下一页返回-1,找到返回0,没找到返回1;
+				auto FindNextPageJZ = [&](TCHAR* pJN)->int {
+					// 没有在当前页找到目标,看看是否在下一页;
+					rc = FindMatchIcon(_T("img\\jn-jk\\gdd\\xyy.bmp"));
+					if (rc.IsRectEmpty() || rc.IsRectNull())
+					{
+						// 没有下一页,右键退出;
+						MouseRClick();
+						SRAND(200, 300);
+						return -1;
+					}
+
+					MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+					SRAND(500, 750);
+					// 下一页中查看;
+					rc = FindMatchIcon(pJN);
+					if (!rc.IsRectEmpty() && !rc.IsRectNull())
+					{
+						// 找到目标,单击;
+						MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+						SRAND(500, 800);
+						// 移动下,防止高亮识别失败;
+						MouseMoveEx({ rc.left, rc.top }, { rc.right - rand() % 10, rc.bottom - rand() % 10 });
+						SRAND(250, 300);
+						ClickDlgSetup(_T("img\\确定.bmp"));
+						SRAND(350, 500);
+
+						rc = FindMatchIcon(_T("img\\gdd\\接受挑战.bmp"));
+						if (!rc.IsRectEmpty() && !rc.IsRectNull())
+						{// 第二次开始都会多这个;
+							// 找到目标,单击;
+							MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+							SRAND(500, 800);
+							// 移动下,防止高亮识别失败;
+							MouseMoveEx({ rc.left, rc.top }, { rc.left - rand() % 20, rc.top - rand() % 20 });
+							SRAND(250, 350);
+						}
+
+						ClickDlgSetup(_T("img\\确定.bmp"));
+						SRAND(250, 300);
+
+						// 战斗;
+						return 0;
+					}
+
+					return 1;
+				};
+
+				TCHAR szJN[MAX_PATH] = { 0 };
+				_stprintf_s(szJN, _T("img\\jn-jk\\gdd\\%s.bmp"), lpszSkillName);
+				rc = FindMatchIcon(szJN);
+				if (rc.IsRectEmpty() || rc.IsRectNull())
+				{
+					// 最多只有三页;
+					for (int i = 0; i < 3; i++)
+					{
+						// 没有在当前页找到目标,看看是否在下一页;
+						int nRet = FindNextPageJZ(szJN);
+						if (nRet == 1)
+						{
+							// 没有找到技能;
+							SRAND(500, 800);
+							continue;
+						}
+
+						if (nRet == 0)
+						{
+							// 找到了;
+							bBattle = TRUE;
+						}
+
+						break; // 没有下一页也直接break;
+					}
+				}
+				else
+				{
+					bBattle = TRUE;
+					// 找到目标,单击;
+					MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+					// 切图时间比较长;
+					SRAND(500, 800);
+					// 战斗;
+					ClickDlgSetup(_T("img\\确定.bmp"));
+					SRAND(200, 300);
+				}
+			}
+		}
+
+		int KeyValue, SkillTime;
+		// 进入战斗;
+		if (bBattle)
+		{
+			// 人物:Alt+S显示技能,双击选择技能,单击怪物发动技能;
+			// 注:有的人物技能太多,导致会有滚动条:这是有难点;
+			BOOL bRet = FindJNShortCut(lpszSkillName, KeyValue, SkillTime);
+			DebugLog("快捷键值=%ld", KeyValue);
+
+			// 快捷键;
+			SendKey(KeyValue);
+			SRAND(350, 650);
+			// 单击指定位置;
+			MouseClick({ 230, 170 });
+			SRAND(260, 380);
+			// 将鼠标移动到指定位置;
+			POINT ptDest = { 625, 28 }; // 左上角;
+			MouseMove(ptDest);
+			while (IsBattle())
+			{
+				// 判断是否我方攻击;
+				if (IsWattingAttack(1))
+				{
+					SendKey(VK_A, FALSE, TRUE);
+				}
+				SRAND(500, 900);
+			}
+		}
+
+		// 右键退出;
+		SRAND(300, 500); //必要的等待时间;
+		do
+		{
+			rc = FindMatchIcon("img\\对话框关闭按钮.bmp");
+			Sleep(900);
+		} while (rc.IsRectEmpty() || rc.IsRectNull());
+
+		MouseRClick();
+	}
 };

+ 10 - 4
GameAssist/GameAssist/CAction.h

@@ -16,9 +16,6 @@ namespace GameAssist {
 		POINT ptNpc;	// npc具体坐标;
 	}PNPC, * pPNPC;
 
-	std::map<std::string, POINT> g_mapZYNPC;
-	std::map<std::string, PNPC> g_mapZYNPC2;
-
 	// 单击:POINT
 	// 右击:POINT
 	// 双击:POINT
@@ -40,10 +37,13 @@ namespace GameAssist {
 	{
 		HWND m_hGameWnd;
 		static ThreadSection m_ts;
-
+		POINT m_ptCur;
 	private:
 		// 鼠标移动;
 		void MouseMove(POINT pt, bool bSetCurPos = true);
+		void MouseMove(POINT ptStart, POINT ptEnd, bool bSetCurPos = true);
+		void MouseMoveEx(POINT pt, bool bSetCurPos = true);
+		void MouseMoveEx(POINT ptStart, POINT ptEnd, bool bSetCurPos = true);
 		// 鼠标单击;
 		void MouseClick();
 		void MouseClick(POINT pt);
@@ -63,6 +63,8 @@ namespace GameAssist {
 		CAction(HWND hWnd);
 		~CAction();
 
+		// 初始NPC坐标;
+		void InitNPCInfo();
 		// 窗口前置;
 		void SetGameForeground();
 		// 是否停止走路;
@@ -86,6 +88,8 @@ namespace GameAssist {
 		bool FindNPCByIcon(POINT ptMap, LPCTSTR lpszNPCName);
 		// 查找NPC:定位指定位置后,再相对这个坐标后的位置单击NPC坐标;
 		bool FindNPCByIconAndPos(LPCTSTR lpszNPCName, POINT ptMap, POINT ptNpc);
+		// 查找NPC:查找map中的NPC;
+		bool FindNPCByMap(LPCTSTR lpszNPCName);
 
 	public:
 		// 与镜妖战斗;
@@ -93,6 +97,8 @@ namespace GameAssist {
 		// nZJType:重击类型;
 		// bAggressiveSkill:人物攻击技能还是辅助技能;
 		void BattleJY(BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill);
+		// 与职业医师战斗;
+		void BattleYS(LPCTSTR lpszSkillName);
 	};
 
 };

+ 35 - 0
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -7,6 +7,7 @@
 #include "GameAssistDlg.h"
 //#include "VideoDXGICaptor.h"
 #include "MouseAssist.h"
+#include "CAction.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -1796,6 +1797,38 @@ void CGameAssistDlg::OnBnClickedButton6() // 职业
 	HWND hWnd = GetCurGameWnd();// GAssist::GetProcessMainWnd();
 	if (hWnd == NULL)
 		return;
+#if 1
+	GameAssist::CAction ct(hWnd);
+	if (!ct.FindNPCByWorldMap("职业训导大师"))
+		return;
+	// 选择进入;
+	BOOL bMatch = FALSE;
+	int trySize = 20;
+
+
+	// 我要挑战他们;
+	while (!(bMatch = ct.ClickDlgSetup(_T("img\\zyxdds-wytztm.bmp")))) {
+		SRAND(1200, 2200);
+		if (!trySize--) break;
+	}
+
+	// 准备好了
+	if (ct.ClickDlgSetup(_T("img\\zyxdds-zbhl.bmp")))
+	{
+		// 地图切换,等出图;
+		SRAND(2000, 2500);
+		if (ct.IsOnMap(_T("img\\gdd\\name.bmp")))
+		{
+			DebugLog(_T("进入孤独洞"));
+			char szName[10][32] = { "术士独侠","道士独侠","武师独侠","浪子独侠","剑客独侠","弓手独侠","禁卫独侠","墨者独侠","巫煞独侠","魂武独侠" };
+			ct.BattleYS("缚神诀");
+			for (int i = 0; i < 10; i++)
+			{
+				//BattleOthers(hWnd, szName[i], "缚神诀");
+			}
+		}
+	}
+#else	
 	if (!FindNPC(hWnd, "职业训导大师"))
 		return;
 
@@ -1803,6 +1836,7 @@ void CGameAssistDlg::OnBnClickedButton6() // 职业
 	BOOL bMatch = FALSE;
 	int trySize = 20;
 
+
 	// 我要挑战他们;
 	while (!(bMatch = ClickDlgSetup(hWnd, _T("img\\zyxdds-wytztm.bmp")))) {
 		SRAND(1200, 2200);
@@ -1825,6 +1859,7 @@ void CGameAssistDlg::OnBnClickedButton6() // 职业
 			}
 		}
 	}
+#endif
 }