CAction.cpp 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. #include "stdafx.h"
  2. #include "CAction.h"
  3. namespace GameAssist
  4. {
  5. #define SETGAMEFOREGROUND AutoThreadSection ats(&m_ts);\
  6. if (!::IsWindow(m_hGameWnd)) return;\
  7. ::ShowWindow(m_hGameWnd, SW_SHOWNORMAL);\
  8. ::SetForegroundWindow(m_hGameWnd);\
  9. SRAND(80,120);
  10. std::map<std::string, POINT> g_mapZYNPC;
  11. std::map<std::string, PNPC> g_mapZYNPC2;
  12. // 使用快捷键来处理:读取配置文件
  13. auto FindJNShortCut = [](LPCTSTR lpSkillName, int& nKeyValue, int& nSkilltime)->BOOL {
  14. // 读取文件:jnmap.bin
  15. // 格式:技能=快捷键的键值;
  16. std::string line;
  17. std::ifstream ifJN("img\\jnmap.bin");
  18. if (ifJN)
  19. {
  20. TCHAR szKeyValue[MAX_PATH] = { 0 };
  21. TCHAR szSkillName[MAX_PATH] = { 0 };
  22. TCHAR szSkillTime[MAX_PATH] = { 0 };
  23. while (std::getline(ifJN, line))
  24. {
  25. int nRet = _stscanf_s(line.c_str(), _T("%[^;];%[^;];%s"), szSkillName, MAX_PATH, szKeyValue, MAX_PATH, szSkillTime, MAX_PATH);
  26. if (nRet == 3 && _tcsicmp(lpSkillName, szSkillName) == 0) {
  27. // 将快捷键值
  28. nKeyValue = atol(szKeyValue);
  29. nSkilltime = atol(szSkillTime);
  30. return TRUE;
  31. }
  32. }
  33. }
  34. // 没有找到jnmap.bin文件;
  35. return FALSE;
  36. };
  37. ThreadSection CAction::m_ts;
  38. VOID DebugLog(CHAR* pszStr, ...)
  39. {
  40. char szData[MAX_PATH] = { 0 };
  41. _stprintf_s(szData, _T("%s %s "), _T("[GameAssist] "), CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")).GetString());
  42. int len = strlen(szData);
  43. va_list args;
  44. va_start(args, pszStr);
  45. _vsnprintf_s(szData + len, MAX_PATH - len, MAX_PATH - len, pszStr, args);
  46. va_end(args);
  47. strcat_s(szData, "\n");
  48. OutputDebugStringA(szData);
  49. }
  50. CAction::CAction(HWND hWnd) :m_hGameWnd(hWnd), m_ptCur({ 0,0 })
  51. {
  52. m_hBattleJY = NULL;
  53. m_hBattleJYEvent = NULL;
  54. m_hBattleZYTZ = NULL;
  55. InitNPCInfo();
  56. }
  57. CAction::~CAction()
  58. {
  59. }
  60. void CAction::MouseMove(POINT pt, bool bSetCurPos)
  61. {
  62. SETGAMEFOREGROUND;
  63. GameAssist::GamePos2Screen(m_hGameWnd, pt);
  64. GameAssist::MouseMove(pt, bSetCurPos);
  65. SRAND(80, 150);
  66. }
  67. void CAction::MouseMove(POINT ptStart, POINT ptEnd, bool bSetCurPos)
  68. {
  69. SETGAMEFOREGROUND;
  70. GameAssist::GamePos2Screen(m_hGameWnd, ptStart);
  71. GameAssist::MouseMove(ptStart, bSetCurPos);
  72. Sleep(50);
  73. GameAssist::GamePos2Screen(m_hGameWnd, ptEnd);
  74. GameAssist::MouseMove(ptEnd, bSetCurPos);
  75. SRAND(80, 150);
  76. }
  77. void CAction::MouseMoveEx(POINT pt, bool bSetCurPos)
  78. {
  79. SETGAMEFOREGROUND;
  80. GameAssist::GamePos2Screen(m_hGameWnd, pt);
  81. GameAssist::MouseClick(pt);
  82. SRAND(80, 150);
  83. }
  84. void CAction::MouseMoveEx(POINT ptStart, POINT ptEnd, bool bSetCurPos)
  85. {
  86. SETGAMEFOREGROUND;
  87. GameAssist::GamePos2Screen(m_hGameWnd, ptStart);
  88. GameAssist::MouseMove(ptStart, bSetCurPos);
  89. GameAssist::GamePos2Screen(m_hGameWnd, ptEnd);
  90. GameAssist::MouseClick(ptEnd);
  91. SRAND(80, 150);
  92. }
  93. void CAction::MouseClick()
  94. {
  95. SETGAMEFOREGROUND;
  96. GameAssist::MouseClick();
  97. SRAND(80, 150);
  98. }
  99. void CAction::MouseClick(POINT pt)
  100. {
  101. SETGAMEFOREGROUND;
  102. GameAssist::GamePos2Screen(m_hGameWnd, pt);
  103. GameAssist::MouseClick(pt);
  104. SRAND(80, 150);
  105. }
  106. void CAction::MouseDbClick()
  107. {
  108. SETGAMEFOREGROUND;
  109. GameAssist::MouseDbClick();
  110. SRAND(80, 150);
  111. }
  112. void CAction::MouseDbClick(POINT pt)
  113. {
  114. SETGAMEFOREGROUND;
  115. GameAssist::GamePos2Screen(m_hGameWnd, pt);
  116. GameAssist::MouseDbClick(pt);
  117. SRAND(80, 150);
  118. }
  119. void CAction::MouseRClick()
  120. {
  121. SETGAMEFOREGROUND;
  122. GameAssist::MouseRClick();
  123. SRAND(80, 150);
  124. }
  125. void CAction::MouseRClick(POINT pt)
  126. {
  127. SETGAMEFOREGROUND;
  128. GameAssist::GamePos2Screen(m_hGameWnd, pt);
  129. GameAssist::MouseRClick(pt);
  130. SRAND(80, 150);
  131. }
  132. void CAction::MouseDrag(POINT pt)
  133. {
  134. SETGAMEFOREGROUND;
  135. GameAssist::GamePos2Screen(m_hGameWnd, pt);
  136. GameAssist::MouseDrag(pt);
  137. SRAND(80, 150);
  138. }
  139. void CAction::SendKey(DWORD key, BOOL bCtrl, BOOL bAtl, BOOL bShift)
  140. {
  141. SETGAMEFOREGROUND;
  142. GameAssist::SendKey(key, bCtrl, bAtl, bShift);
  143. SRAND(80, 150);
  144. }
  145. void CAction::InitNPCInfo()
  146. {
  147. static bool bInit = false;
  148. if (!bInit) {
  149. // "医师独侠","术士独侠","道士独侠","武师独侠","浪子独侠","剑客独侠", "弓手独侠", "禁卫独侠", "墨者独侠", "巫煞独侠", "魂武独侠"
  150. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("医师独侠"), { 305, 325 }));
  151. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("术士独侠"), { 305, 325 }));
  152. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("道士独侠"), { 305, 325 }));
  153. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("武师独侠"), { 305, 325 }));
  154. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("浪子独侠"), { 160, 435 }));
  155. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("剑客独侠"), { 420, 215 }));
  156. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("弓手独侠"), { 265, 230 }));
  157. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("禁卫独侠"), { 155, 205 }));
  158. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("墨者独侠"), { 155, 205 }));
  159. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("巫煞独侠"), { 155, 205 }));
  160. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("魂武独侠"), { 165, 335 }));
  161. // 应天府NPC
  162. g_mapZYNPC.insert(std::pair<std::string, POINT>(_T("职业训导大师"), { 315, 415 }));
  163. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("医师独侠"), { { 305, 325 }, { 590, 380 } }));
  164. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("术士独侠"), { { 305, 325 }, { 610, 160 } }));
  165. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("道士独侠"), { { 305, 325 }, { 140, 160 } }));
  166. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("武师独侠"), { { 305, 325 }, { 140, 380 } }));
  167. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("浪子独侠"), { { 160, 435 }, { 190, 370 } }));
  168. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("剑客独侠"), { { 420, 215 }, { 540, 170 } }));
  169. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("弓手独侠"), { { 265, 230 }, { 460, 150 } }));
  170. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("禁卫独侠"), { { 155, 205 }, { 605, 235 } }));
  171. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("墨者独侠"), { { 155, 205 }, { 315, 380 } }));
  172. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("巫煞独侠"), { { 155, 205 }, { 270, 175 } }));
  173. g_mapZYNPC2.insert(std::pair<std::string, PNPC>(_T("魂武独侠"), { { 165, 335 }, { 270, 305 } }));
  174. bInit = true;
  175. }
  176. }
  177. void CAction::SetGameForeground()
  178. {
  179. AutoThreadSection ats(&m_ts);
  180. if (!::IsWindow(m_hGameWnd)) return;
  181. ::ShowWindow(m_hGameWnd, SW_SHOWNORMAL);
  182. ::SetForegroundWindow(m_hGameWnd); // 窗口前置才能单击成功;
  183. }
  184. bool CAction::IsWalkStop()
  185. {
  186. if (!::IsWindow(m_hGameWnd))
  187. return false;
  188. // 将鼠标移走,不要在抠图区域;
  189. // 截图,抠指定区域;
  190. // 再截图,抠指定区域与上次抠图结果比较;
  191. // 比较结果相同,表示停止走路;
  192. //POINT pt1 = { 635, 20 };
  193. //POINT pt2 = { 780, 38 };
  194. CRect rc = { 630, 40, 800, 65 };
  195. CRect rc2 = { 640, 45, 770, 63 };
  196. for (int i = 0; i < 100; i++)
  197. {
  198. std::string strImg = GameGlobal::BuildImgPath(m_hGameWnd, "walk1");
  199. std::string strImg2 = GameGlobal::BuildImgPath(m_hGameWnd, "walk2");
  200. ImgAssist::CropPicture(m_hGameWnd, rc, strImg.c_str());
  201. Sleep(600);
  202. ImgAssist::CropPicture(m_hGameWnd, rc2, strImg2.c_str());
  203. // 判断2张图片是否一样;
  204. if (ImgAssist::IsSimilarPicture(strImg.c_str(), strImg2.c_str()))
  205. {
  206. DebugLog(_T("停止走路"));
  207. return true;
  208. }
  209. }
  210. return false;
  211. }
  212. bool CAction::IsBattle()
  213. {
  214. CRect rc;
  215. SRAND(100, 200);
  216. if (ImgAssist::IsMatchIcon(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\非战斗中.bmp"), { 630, 25, 805, 45 }, rc)) {
  217. DebugLog(_T("Battle:非战斗中"));
  218. return false;
  219. }
  220. DebugLog(_T("Battle:战斗中"));
  221. return true;
  222. }
  223. CRect CAction::FindMatchIcon(LPCTSTR lpszTemplateImage)
  224. {
  225. CRect rc;
  226. TCHAR szTemplateImage[MAX_PATH] = { 0 };
  227. // 先截图;
  228. DebugLog(_T("FindMatchIcon=%s"), lpszTemplateImage);
  229. ImgAssist::CaptureGameWnd(m_hGameWnd); SRAND(200, 500);
  230. _stprintf_s(szTemplateImage, _T("%s%s"), GameGlobal::g_strAppdir.c_str(), lpszTemplateImage);
  231. if (ImgAssist::GetImgMatchtemplate(GameGlobal::BuildImgPath(m_hGameWnd), szTemplateImage, rc)) {
  232. // 找到匹配的模块;
  233. DebugLog(_T("====> 找到匹配目标:%s"), lpszTemplateImage);
  234. return rc;
  235. }
  236. rc.SetRectEmpty();
  237. DebugLog(_T("<==== 没找到匹配目标:%s"), lpszTemplateImage);
  238. return rc;
  239. }
  240. bool CAction::IsOnMap(LPCTSTR lpszTemplateImage)
  241. {
  242. CRect rc = FindMatchIcon(lpszTemplateImage);
  243. if (rc.IsRectEmpty() || rc.IsRectNull())
  244. return false;
  245. return true;
  246. }
  247. void CAction::WorldMapPositioning(POINT ptMap)
  248. {
  249. CRect rc;
  250. //// 打开世界地图;
  251. SendKey(VK_TAB); SRAND(550, 800);
  252. // 判断是否打开了地图;
  253. if (!ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\世界地图.bmp"), rc))
  254. return;
  255. //// 单击寻路窗口;
  256. MouseClick(ptMap); SRAND(300, 600);
  257. while (ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\世界地图.bmp"), rc)) {
  258. // 退出世界地址;
  259. SendKey(VK_TAB); SRAND(200, 300);
  260. }
  261. IsWalkStop();
  262. }
  263. bool CAction::IsWattingAttack(int nAttackNPCType)
  264. {
  265. CRect rc;
  266. BOOL bIsAttack = FALSE;
  267. if (ImgAssist::IsMatchIcon(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\我方攻击2.bmp"), { 720, 85, 806, 120 }, rc)) {
  268. DebugLog(_T("IsWattingAttack:我方攻击中……"));
  269. bIsAttack = TRUE;
  270. }
  271. return bIsAttack;
  272. }
  273. bool CAction::ClickDlgSetup(LPCSTR lpszTemplateImage)
  274. {
  275. CRect rc = FindMatchIcon(_T("img\\对话框关闭按钮.bmp"));
  276. if (rc.IsRectEmpty() || rc.IsRectNull())
  277. return false;
  278. // 移动到关闭按钮;
  279. MouseMove({rc.left -30 , rc.top + 10});
  280. SRAND(50, 80);
  281. // 再找目标;
  282. rc = FindMatchIcon(lpszTemplateImage);
  283. SRAND(50, 80);
  284. // 单击目标;
  285. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2 + rand() % 3));
  286. // 单击后,系统切图可能要的时间会比较长;
  287. SRAND(100, 200);
  288. // 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
  289. MouseMove(CPoint(rc.top - RAND(5, 12), rc.left - RAND(5, 10))); // 移动到左上角;
  290. SRAND(100, 200);
  291. return true;
  292. }
  293. bool CAction::ClickDlgSetup(std::vector<std::string> vtOptions)
  294. {
  295. std::vector<std::string>::iterator it = vtOptions.begin();
  296. for(;it != vtOptions.end(); it++)
  297. {
  298. }
  299. return false;
  300. }
  301. bool CAction::FindNPCByWorldMap(LPCTSTR lpszNPCName)
  302. {
  303. CRect rc;
  304. //// 打开世界地图;
  305. SendKey(VK_TAB); SRAND(500, 600);
  306. if (!ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\寻路窗口.bmp"), rc))
  307. return false;
  308. //// 单击寻路窗口;
  309. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 2, (rc.top + rc.bottom) / 2 + rand() % 2)); SRAND(500, 800);
  310. //// 设置剪切板:职业大挑战;
  311. SetClipboardString(lpszNPCName); SRAND(200, 500);
  312. //// Ctrl+V
  313. SendKey(0x56, TRUE); SRAND(300, 500);
  314. // 先移动到目标后,才能实现单击;
  315. MouseMove(CPoint((rc.right + rc.left) / 2 + 5 + rand() % 2, (rc.top + rc.bottom) / 2 + 60 + rand() % 2)); SRAND(200, 300);
  316. //// 寻路窗口往下50就是目标;
  317. MouseDbClick(CPoint((rc.right + rc.left) / 2 + 5 + rand() % 2, (rc.top + rc.bottom) / 2 + 60 + rand() % 2)); SRAND(200, 300);
  318. while (ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\世界地图.bmp"), rc)) {
  319. // 退出世界地址;
  320. SendKey(VK_TAB); SRAND(200, 300);
  321. }
  322. // 直到停止走动为止;
  323. IsWalkStop();
  324. // 遍历3次;
  325. bool bFind = false;
  326. for (int i = 0; i < 3; i++)
  327. {
  328. Sleep(800 - i * 150);
  329. rc = FindMatchIcon(_T("img\\对话框关闭按钮.bmp"));
  330. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  331. {
  332. bFind = true;
  333. break;
  334. }
  335. }
  336. return bFind;
  337. }
  338. bool CAction::FindNPCByIcon(POINT ptMap, LPCTSTR lpszNPCName)
  339. {
  340. TCHAR szNPC[MAX_PATH] = { 0 };
  341. _stprintf_s(szNPC, _T("img\\npc\\%s.bmp"), lpszNPCName);
  342. CRect rc = FindMatchIcon(szNPC);
  343. if (rc.IsRectEmpty() || rc.IsRectNull())
  344. {
  345. WorldMapPositioning(ptMap);
  346. Sleep(600); // 有时走到目标点,NPC还未刷新出来;
  347. rc = FindMatchIcon(szNPC);
  348. if (rc.IsRectEmpty() || rc.IsRectNull())
  349. {
  350. // 可能还是未刷新出来,再次等待;
  351. Sleep(300);
  352. rc = FindMatchIcon(szNPC);
  353. if (rc.IsRectEmpty() || rc.IsRectNull())
  354. {
  355. return false;
  356. }
  357. }
  358. }
  359. // 找到目标,单击;
  360. MouseMove(CPoint(rc.left, rc.top));
  361. // 单击:我要挑战他们;
  362. MouseClick({ (rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2 });
  363. SRAND(500, 1300);// 等对话框出现;
  364. // 移动鼠标:不要停留在人物身上;
  365. MouseMove({ rc.left - rand() % 10, rc.top - rand() % 10 });
  366. return true;
  367. }
  368. bool CAction::FindNPCByIconAndPos(LPCTSTR lpszNPCName, POINT ptMap, POINT ptNpc)
  369. {
  370. TCHAR szNPC[MAX_PATH] = { 0 };
  371. _stprintf_s(szNPC, _T("img\\npc\\%s.bmp"), lpszNPCName);
  372. CRect rc = FindMatchIcon(szNPC);
  373. if (rc.IsRectEmpty() || rc.IsRectNull())
  374. {
  375. WorldMapPositioning(ptMap);
  376. Sleep(600); // 有时走到目标点,NPC还未刷新出来;
  377. rc = FindMatchIcon(szNPC);
  378. if (rc.IsRectEmpty() || rc.IsRectNull())
  379. {
  380. // 可能还是未刷新出来,再次等待;
  381. Sleep(600);
  382. rc = FindMatchIcon(szNPC);
  383. if (rc.IsRectEmpty() || rc.IsRectNull())
  384. {
  385. return false;
  386. }
  387. }
  388. }
  389. // 找到目标,单击;
  390. MouseMove(CPoint(rc.left - rand() % 30, rc.top + rand() % 50));
  391. // 单击:我要挑战他们;
  392. MouseClick(ptNpc);
  393. // 遍历3次;
  394. bool bFind = false;
  395. for (int i = 0; i < 3; i++)
  396. {
  397. Sleep(800 - i * 150);
  398. CRect rc = FindMatchIcon("img\\对话框关闭按钮.bmp");
  399. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  400. {
  401. bFind = true;
  402. break;
  403. }
  404. }
  405. // 移动鼠标:不要停留在人物身上;
  406. MouseMove({ ptNpc.x - rand() % 30, ptNpc.y - rand() % 30 });
  407. return bFind;
  408. }
  409. bool CAction::FindNPCByMap(LPCTSTR lpszNPCName)
  410. {
  411. auto it = g_mapZYNPC2.find(lpszNPCName);
  412. if (it != g_mapZYNPC2.end())
  413. {
  414. if (FindNPCByIconAndPos(it->first.c_str(), it->second.ptMap, it->second.ptNpc))
  415. {
  416. return true;
  417. }
  418. }
  419. return false;
  420. }
  421. void CAction::BattleJY(BOOL bHasSummoner, int nZJType, BOOL bAggressiveSkill)
  422. {
  423. BOOL bFirstAttack = TRUE;
  424. // 1.是否在战斗中;
  425. while (IsBattle()) {
  426. // 2.是否我方攻击;
  427. while (IsWattingAttack(0)) { // Bug:如果被镜妖打死了,无法中断;
  428. DebugLog(_T("BattleJY:我方攻击……"));
  429. if (bFirstAttack)
  430. {
  431. SRAND(350, 500); // 有时切换需要时间,如果不延时会失败;
  432. DebugLog(_T("BattleJY:第一次攻击……"));
  433. // 根据角色选择技能;
  434. SendKey(VK_F1);
  435. SRAND(300, 350);
  436. if (bAggressiveSkill) // 打镜妖喽罗;
  437. {
  438. MouseClick(CPoint(290 - 3, 140 - 20));
  439. //MouseMove(hWnd, CPoint(220 - 5, 180 - 10));// 打主镜妖;
  440. SRAND(350, 500);
  441. }
  442. if (bHasSummoner) {
  443. CRect rc;
  444. // 召唤兽技能;
  445. DebugLog(_T("BattleJY:召唤兽技能选择"));
  446. // 选择重击;
  447. if (nZJType) {
  448. SRAND(150, 350);
  449. SendKey(VK_S, FALSE, TRUE);
  450. DebugLog(_T("BattleJY:召唤兽技能选择:%d"), nZJType);
  451. if (ImgAssist::GetImgMatchtemplate(m_hGameWnd, nZJType == 1 ? GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\重击.bmp") : GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\重击2.bmp"), rc))
  452. {
  453. SRAND(150, 300);
  454. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3));
  455. }
  456. }
  457. SRAND(300, 500);
  458. MouseMove(CPoint(290 - 3, 140 - 15));
  459. MouseClick(CPoint(290 - 3, 140 - 20));
  460. }
  461. bFirstAttack = FALSE;
  462. }
  463. else
  464. {
  465. DebugLog(_T("BattleJY:不是第一次攻击……"));
  466. SendKey(VK_A, FALSE, TRUE);
  467. SRAND(80, 100);
  468. if (bFirstAttack) {
  469. SendKey(VK_A, FALSE, TRUE);
  470. SRAND(80, 120);
  471. }
  472. }
  473. }
  474. SRAND(500, 850);
  475. }
  476. // 非战斗中,是否在贫民房中;
  477. if (!IsOnMap(_T("img\\地图\\贫民房.bmp"))) {
  478. // 找小米;
  479. CRect rc;
  480. if (!FindNPCByWorldMap("臭美的小米"))
  481. return;
  482. // 选择进入;
  483. BOOL bMatch = FALSE;
  484. int trySize = 15;
  485. // 我要挑战他们;
  486. while (!(bMatch = ClickDlgSetup(_T("img\\活动\\镜妖\\1-我帮您抓.bmp")))) {
  487. SRAND(800, 1200);
  488. if (!trySize--) break;
  489. }
  490. if (bMatch) {
  491. MouseMove(CPoint(rc.left, rc.top));
  492. // 单击:我要挑战他们;
  493. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  494. SRAND(1000, 1500);// 等出图;
  495. // 移动一下;
  496. MouseMove(CPoint(rc.left, rc.top));
  497. ::SetCursorPos(rc.left + rand() % 6, rc.top + rand() % 8);
  498. // 是否第一次进入地图;
  499. if (ClickDlgSetup(_T("img\\活动\\镜妖\\2-我这就去.bmp")))
  500. {
  501. SRAND(600, 1200);
  502. if (ClickDlgSetup(_T("img\\活动\\镜妖\\3-战意镜妖.bmp")))
  503. {
  504. SRAND(600, 1800);
  505. if ((bMatch = ClickDlgSetup(_T("img\\活动\\镜妖\\4-我就选择它.bmp"))))
  506. {
  507. SRAND(800, 1800);
  508. }
  509. }
  510. }
  511. }
  512. }
  513. else
  514. {
  515. // 找到镜妖;
  516. CRect rc;
  517. POINT spt[4] = { { 250, 335 }, { 310,360}, { 385, 315}, { 280,295 } };
  518. for (int i = 0; !ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\镜妖1.bmp"), rc); i++)
  519. {
  520. // 打开世界地图;
  521. SendKey(VK_TAB); SRAND(200, 300);
  522. // 选择坐标点;
  523. MouseClick(spt[i % 4]);
  524. while (ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\世界地图.bmp"), rc)) {
  525. // 退出世界地址;
  526. SendKey(VK_TAB); SRAND(500, 900);
  527. }
  528. // 等待跑完成;
  529. IsWalkStop();
  530. // 移动下鼠标;
  531. MouseMove(spt[(i+1)%4]);
  532. if (i > 10) {
  533. DebugLog(_T("未找到镜妖+10"));
  534. break;
  535. }
  536. }
  537. // 找到镜妖;
  538. MouseMove(CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
  539. DebugLog(_T("移动鼠标"));
  540. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3));
  541. SRAND(390, 600);
  542. // 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
  543. MouseMove(CPoint(rc.right + RAND(10, 20), rc.bottom + RAND(10, 20)));
  544. SRAND(300, 500);
  545. DebugLog(_T("找到目标并单击成功:%s"));
  546. // 我来抓你;
  547. if (ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
  548. // 找到匹配的模块;
  549. SRAND(200, 300);
  550. //MouseMove(hWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
  551. DebugLog(_T("我来抓你:移动鼠标"));
  552. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3));
  553. SRAND(1000, 1500);
  554. DebugLog(_T("我来抓你:找到目标并单击成功:%s"));
  555. }
  556. }
  557. }
  558. void CAction::BattleYS(LPCTSTR lpszSkillName)
  559. {
  560. CRect rc;
  561. BOOL bBattle = FALSE;
  562. if (!FindNPCByMap("医师独侠"))
  563. return;
  564. // 废话少说:表示这个没打过;
  565. rc = FindMatchIcon(_T("img\\gdd\\废话少说.bmp"));
  566. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  567. {
  568. // 确定
  569. bBattle = TRUE;
  570. MouseMove({ rc.left - RAND(30, 50), rc.top - RAND(30, 50) });
  571. SRAND(20, 50);
  572. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  573. SRAND(500, 800); // 切图时间长;
  574. ClickDlgSetup(_T("img\\确定.bmp"));
  575. }
  576. else
  577. {
  578. rc = FindMatchIcon(_T("img\\gdd\\离开这里.bmp"));
  579. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  580. {
  581. // 只有离开这里:已经打过,右键并退出 ;
  582. DebugLog("只有离开这里:已经打过,右键并退出");
  583. MouseRClick({rc.left, rc.top});
  584. SRAND(200, 500);
  585. return;
  586. }
  587. else
  588. {
  589. // 找下一页的技能:没有下一页返回-1,找到返回0,没找到返回1;
  590. auto FindNextPageJZ = [&](TCHAR* pJN)->int {
  591. // 没有在当前页找到目标,看看是否在下一页;
  592. rc = FindMatchIcon(_T("img\\jn-jk\\gdd\\xyy.bmp"));
  593. if (rc.IsRectEmpty() || rc.IsRectNull())
  594. {
  595. // 没有下一页,右键退出;
  596. MouseRClick();
  597. SRAND(200, 300);
  598. return -1;
  599. }
  600. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  601. SRAND(500, 750);
  602. // 下一页中查看;
  603. rc = FindMatchIcon(pJN);
  604. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  605. {
  606. // 找到目标,单击;
  607. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  608. SRAND(500, 800);
  609. ClickDlgSetup(_T("img\\确定.bmp"));
  610. SRAND(350, 500);
  611. rc = FindMatchIcon(_T("img\\gdd\\接受挑战.bmp"));
  612. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  613. {// 第二次开始都会多这个;
  614. // 找到目标,单击;
  615. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  616. SRAND(500, 800);
  617. // 移动下,防止高亮识别失败;
  618. MouseMove({ rc.left, rc.top }, { rc.left - rand() % 20, rc.top - rand() % 20 });
  619. SRAND(150, 250);
  620. }
  621. ClickDlgSetup(_T("img\\确定.bmp"));
  622. SRAND(250, 300);
  623. // 战斗;
  624. return 0;
  625. }
  626. return 1;
  627. };
  628. TCHAR szJN[MAX_PATH] = { 0 };
  629. _stprintf_s(szJN, _T("img\\jn-jk\\gdd\\%s.bmp"), lpszSkillName);
  630. rc = FindMatchIcon(szJN);
  631. if (rc.IsRectEmpty() || rc.IsRectNull())
  632. {
  633. // 最多只有三页;
  634. for (int i = 0; i < 3; i++)
  635. {
  636. // 没有在当前页找到目标,看看是否在下一页;
  637. int nRet = FindNextPageJZ(szJN);
  638. if (nRet == 1)
  639. {
  640. // 没有找到技能;
  641. SRAND(500, 800);
  642. continue;
  643. }
  644. if (nRet == 0)
  645. {
  646. // 找到了;
  647. bBattle = TRUE;
  648. }
  649. break; // 没有下一页也直接break;
  650. }
  651. }
  652. else
  653. {
  654. bBattle = TRUE;
  655. // 找到目标,单击;
  656. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  657. // 切图时间比较长;
  658. SRAND(500, 800);
  659. // 战斗;
  660. ClickDlgSetup(_T("img\\确定.bmp"));
  661. SRAND(200, 300);
  662. }
  663. }
  664. }
  665. int KeyValue, SkillTime;
  666. // 进入战斗;
  667. if (bBattle)
  668. {
  669. // 人物:Alt+S显示技能,双击选择技能,单击怪物发动技能;
  670. // 注:有的人物技能太多,导致会有滚动条:这是有难点;
  671. BOOL bRet = FindJNShortCut(lpszSkillName, KeyValue, SkillTime);
  672. DebugLog("快捷键值=%ld", KeyValue);
  673. // 快捷键;
  674. SendKey(KeyValue);
  675. SRAND(350, 650);
  676. // 单击指定位置;
  677. MouseClick({ 230, 170 });
  678. SRAND(260, 380);
  679. // 将鼠标移动到指定位置;
  680. POINT ptDest = { 625, 28 }; // 左上角;
  681. MouseMove(ptDest);
  682. while (IsBattle())
  683. {
  684. // 判断是否我方攻击;
  685. if (IsWattingAttack(1))
  686. {
  687. SendKey(VK_A, FALSE, TRUE);
  688. }
  689. SRAND(500, 900);
  690. }
  691. }
  692. // 右键退出;
  693. SRAND(300, 500); //必要的等待时间;
  694. do
  695. {
  696. rc = FindMatchIcon("img\\对话框关闭按钮.bmp");
  697. Sleep(900);
  698. } while (rc.IsRectEmpty() || rc.IsRectNull());
  699. MouseRClick();
  700. }
  701. void CAction::BattleOthers(LPCTSTR lpszName, LPCTSTR lpszSkillName)
  702. {
  703. CRect rc;
  704. BOOL bBattle = FALSE;
  705. if (!FindNPCByMap(lpszName))
  706. return;
  707. // 废话少说:表示这个没打过;
  708. rc = FindMatchIcon(_T("img\\gdd\\废话少说.bmp"));
  709. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  710. {
  711. MouseMove({ rc.left - RAND(30, 50), rc.top - RAND(30, 50) });
  712. SRAND(120, 150);
  713. MouseClick(CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
  714. SRAND(330, 550);
  715. // 确定
  716. bBattle = TRUE;
  717. ClickDlgSetup(_T("img\\确定.bmp"));
  718. SRAND(250, 350);
  719. }
  720. else
  721. {
  722. rc = FindMatchIcon(_T("img\\gdd\\离开这里.bmp"));
  723. }
  724. int KeyValue, SkillTime;
  725. if (bBattle) {
  726. BOOL bRet = FindJNShortCut(lpszSkillName, KeyValue, SkillTime);
  727. // 将鼠标移动到指定位置;
  728. POINT ptDest = { 625, 28 }; // 左上角;
  729. MouseMove(ptDest);
  730. while (IsBattle())
  731. {
  732. // 判断是否我方攻击;
  733. if (IsWattingAttack(1))
  734. {
  735. SendKey(VK_A, FALSE, TRUE);
  736. }
  737. SRAND(500, 750);
  738. }
  739. }
  740. // 右键退出;
  741. if (_tcsicmp(lpszName, _T("魂武独侠")))
  742. {
  743. SRAND(300, 500);
  744. do
  745. {
  746. rc = FindMatchIcon("img\\对话框关闭按钮.bmp");
  747. Sleep(900);
  748. } while (rc.IsRectEmpty() || rc.IsRectNull());
  749. MouseRClick();
  750. }
  751. else
  752. {
  753. // 回到应天府;
  754. MouseMoveEx({ rc.left, rc.top }, { rc.right + rand() % 10, rc.bottom + rand() % 10 });
  755. ClickDlgSetup(_T("\\img\\gdd\\送我回应天府.bmp"));
  756. }
  757. }
  758. void CAction::OpenChest(int nTimes)
  759. {
  760. CRect rc;
  761. for (int i = 0; i < nTimes; i++)
  762. {
  763. if (!ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\开宝箱\\应天府铁匠.bmp"), rc))
  764. {
  765. // 没找到,要将鼠标从目标中移走;并且要右击一次将目标的高亮状态取消;
  766. MouseMove({ rc.top - rand() % 5, rc.left - rand() % 5 });
  767. MouseRClick();
  768. }
  769. else
  770. {
  771. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 5));
  772. Sleep(600 + rand() % 30);
  773. // 再移动下,会更高精度;
  774. MouseMove({ rc.top - rand() % 15, rc.left - rand() % 15 });
  775. // 判断是否还有对话,如果没有的话表明不是第一次进入;
  776. if (ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\开宝箱\\开宝箱.bmp"), rc)) {
  777. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 2, (rc.top + rc.bottom) / 2 + rand() % 2));
  778. Sleep(rand() % 200 + 190);
  779. // 然后移动出去;
  780. //GameGlobal::MouseMove(hProcessMainWnd, CPoint(rc.top - 50 - rand()%20, rc.left - 50 - rand() % 20));
  781. MouseMoveEx({ rc.top + RAND(0, rc.Height()), rc.left + RAND(0, rc.Width()) });
  782. }
  783. }
  784. Sleep(600 + rand() % 300);
  785. }
  786. }
  787. void CAction::GetSaturdayPresents()
  788. {
  789. FindNPCByWorldMap(_T("送礼协会会长丙"));
  790. IsWalkStop();
  791. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\我来领取礼物.bmp")))
  792. {
  793. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\好的.bmp")))
  794. {
  795. FindNPCByWorldMap(_T("【星】铜钱怪"));
  796. IsWalkStop();
  797. CRect rc;
  798. //铜钱怪:好的,要问些什么问题呢?
  799. struct MyStruct
  800. {
  801. BOOL bDone = FALSE;
  802. TCHAR szQuestion[MAX_PATH] = { 0 };
  803. };
  804. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\铜钱怪:好的,要问些什么问题呢?.bmp")))
  805. {
  806. // 第一次回答;
  807. std::vector<MyStruct> vtMyst1 = { {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:帮派就象个大家庭.bmp")},
  808. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:交流的场所.bmp")},
  809. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:能够认识很多.bmp")},
  810. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:我希望能够.bmp")},
  811. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:由系统定时发布.bmp")},
  812. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:好的,快点问吧.bmp")}
  813. };
  814. for (; vtMyst1.size();)
  815. {
  816. for (std::vector<MyStruct>::iterator it = vtMyst1.begin(); it != vtMyst1.end(); it++)
  817. {
  818. rc = FindMatchIcon(it->szQuestion);
  819. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  820. {
  821. // 单击目标回答;
  822. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 5));
  823. // 再移动下鼠标,防止高亮影响下次的判断;
  824. MouseMove(CPoint(rc.right + RAND(6, 20), rc.bottom + RAND(6, 20)));
  825. // 等待下一个问题出现;
  826. SRAND(200, 300);
  827. it = vtMyst1.erase(it);
  828. break;
  829. }
  830. }
  831. }
  832. // 第二次回答;
  833. std::vector<MyStruct> vtMyst2 = { {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:帮派就象个大家庭.bmp")},
  834. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:交流的场所.bmp")},
  835. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:能够认识很多.bmp")},
  836. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:我希望能够.bmp")},
  837. {FALSE, _T("img\\活动\\周六礼物\\铜钱怪:由系统定时发布.bmp")}
  838. };
  839. for (; vtMyst2.size();)
  840. {
  841. for (std::vector<MyStruct>::iterator it = vtMyst2.begin(); it != vtMyst2.end(); it++)
  842. {
  843. rc = FindMatchIcon(it->szQuestion);
  844. if (!rc.IsRectEmpty() && !rc.IsRectNull())
  845. {
  846. // 单击目标回答;
  847. MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 5));
  848. // 再移动下鼠标,防止高亮影响下次的判断;
  849. MouseMove(CPoint(rc.right + RAND(6, 20), rc.bottom + RAND(6, 20)));
  850. // 等待下一个问题出现;
  851. SRAND(200, 300);
  852. it = vtMyst2.erase(it);
  853. break;
  854. }
  855. }
  856. }
  857. // 回答完所有问题,右键退出;
  858. SRAND(200, 300);
  859. MouseRClick();
  860. }
  861. // 再次回到送礼协会会长;
  862. FindNPCByWorldMap(_T("送礼协会会长丙"));
  863. IsWalkStop();
  864. // 再右键一次;
  865. SRAND(200, 300);
  866. MouseRClick();
  867. FindNPCByWorldMap(_T("送礼协会会长丙"));
  868. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\好,现在就去.bmp")))
  869. {
  870. // 等待切换地图;
  871. SRAND(800, 900);
  872. }
  873. }
  874. }
  875. if (IsOnMap(_T("img\\地图\\汴京城.bmp")))
  876. {
  877. // 找送礼协会会长丁
  878. FindNPCByWorldMap(_T("送礼协会会长丁"));
  879. IsWalkStop();
  880. SRAND(300, 500); // 等对话框出现;
  881. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\我来领取礼物.bmp")))
  882. {
  883. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\好的.bmp")))
  884. {
  885. // 找铜钱怪;
  886. FindNPCByWorldMap(_T("【汴】铜钱怪"));
  887. IsWalkStop();
  888. SRAND(300, 500);
  889. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\铜钱怪:进入战斗.bmp")))
  890. {
  891. // 将鼠标移动到指定位置;
  892. POINT ptDest = { 625, 28 }; // 左上角;
  893. MouseMove(ptDest);
  894. while (IsBattle())
  895. {
  896. // 判断是否我方攻击;
  897. if (IsWattingAttack(1))
  898. {
  899. SendKey(VK_A, FALSE, TRUE);
  900. }
  901. SRAND(500, 750);
  902. }
  903. // 送礼协会会长乙;
  904. FindNPCByWorldMap(_T("送礼协会会长乙"));
  905. IsWalkStop();
  906. // 再右键一次;
  907. SRAND(200, 300);
  908. MouseRClick();
  909. FindNPCByWorldMap(_T("送礼协会会长丙")); SRAND(200, 300);
  910. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\好,现在就去.bmp")))
  911. {
  912. // 等待切换地图;
  913. SRAND(800, 900);
  914. }
  915. }
  916. }
  917. }
  918. }
  919. if (IsOnMap(_T("img\\地图\\应天府.bmp")))
  920. {
  921. // 找送礼协会会长丁
  922. FindNPCByWorldMap(_T("送礼协会会长甲"));
  923. IsWalkStop();
  924. SRAND(300, 500); // 等对话框出现;
  925. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\我来领取礼物.bmp")))
  926. {
  927. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\好的.bmp")))
  928. {
  929. // 找铜钱怪;
  930. FindNPCByWorldMap(_T("【应】铜钱怪"));
  931. IsWalkStop();
  932. SRAND(300, 500);
  933. if (ClickDlgSetup(_T("img\\活动\\周六礼物\\铜钱怪:进入战斗.bmp")))
  934. {
  935. // 将鼠标移动到指定位置;
  936. POINT ptDest = { 625, 28 }; // 左上角;
  937. MouseMove(ptDest);
  938. while (IsBattle())
  939. {
  940. // 判断是否我方攻击;
  941. if (IsWattingAttack(1))
  942. {
  943. SendKey(VK_A, FALSE, TRUE);
  944. }
  945. SRAND(500, 750);
  946. }
  947. // 送礼协会会长乙;
  948. FindNPCByWorldMap(_T("送礼协会会长甲"));
  949. IsWalkStop();
  950. SRAND(1000, 2000);
  951. MouseRClick();
  952. }
  953. }
  954. }
  955. }
  956. }
  957. void CAction::StartBattleJY()
  958. {
  959. m_hBattleJYEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  960. if (m_hBattleJYEvent == NULL) {
  961. _tprintf_s(_T("创建事件失败\n"));
  962. return;
  963. }
  964. m_hBattleJY = CreateThread(NULL, 0, BattleJYThread, this, 0, NULL);
  965. if (m_hBattleJY == NULL) {
  966. _tprintf_s(_T("创建线程失败\n"));
  967. if (m_hBattleJYEvent) {
  968. SetEvent(m_hBattleJYEvent);
  969. CloseHandle(m_hBattleJYEvent);
  970. m_hBattleJYEvent = NULL;
  971. }
  972. }
  973. }
  974. void CAction::StopBattleJY()
  975. {
  976. // 设置事件有信号;
  977. if (m_hBattleJYEvent)
  978. SetEvent(m_hBattleJYEvent);
  979. // 等待线程结束;
  980. if (m_hBattleJY) {
  981. WaitForSingleObject(m_hBattleJY, INFINITE);
  982. CloseHandle(m_hBattleJY);
  983. m_hBattleJY = NULL;
  984. }
  985. // 关闭事件句柄;
  986. if (m_hBattleJYEvent) {
  987. CloseHandle(m_hBattleJYEvent);
  988. m_hBattleJYEvent = NULL;
  989. }
  990. }
  991. DWORD __stdcall CAction::BattleJYThread(LPVOID lpParam)
  992. {
  993. int i = 0;
  994. CAction* pThis = (CAction*)lpParam;
  995. do
  996. {
  997. DebugLog(_T("start.打镜妖 %d----------------------------"), i);
  998. pThis->BattleJY(pThis->m_bHasSummoner, pThis->m_nSummonerSkillType, pThis->m_bTargetOfRoleSkill);
  999. DebugLog(_T("end.打镜妖 %d----------------------------\n"), i++);
  1000. } while (WaitForSingleObject(pThis->m_hBattleJYEvent, 200) == WAIT_TIMEOUT);
  1001. return 0;
  1002. }
  1003. };