dongri_task.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. # -*- coding: utf-8 -*-
  2. from scriptBase.imgFind import pcacc_img, savePic
  3. from scriptBase.mouseClick import pcacc_mouse
  4. from scriptBase.ocr import capture_and_ocr
  5. import scriptBase.base
  6. from scriptBase.comon import *
  7. from scriptBase.ocr import *
  8. from apscheduler.schedulers.blocking import BlockingScheduler
  9. import pyautogui
  10. import random
  11. import sys
  12. import math
  13. import os
  14. import time
  15. from dongri_define import *
  16. from dongri_pic import *
  17. import subprocess
  18. import socket
  19. from dongri_pic import _imported
  20. '''
  21. 基础配置说明:
  22. 600*800(DPI 300)
  23. 游戏画面:流畅
  24. 高帧率关闭
  25. 町中模式:旧版
  26. '''
  27. def task_getComputerName():
  28. return socket.gethostname()
  29. def task_acceptTask():
  30. while True:
  31. myTimeSleep_big()
  32. def init():
  33. global _imported
  34. if not _imported:
  35. acceptTask = threading.Thread(target=task_acceptTask)
  36. acceptTask.daemon = True
  37. if acceptTask.is_alive() == False:
  38. acceptTask.start()
  39. _imported = True
  40. class basic_operate:
  41. @staticmethod
  42. def do_back():
  43. task_return_game()
  44. ret = False
  45. ret |= waitClickImg_noWait_withBool(place_img.back1, 0.6, 0)
  46. if ret:
  47. return
  48. ret |= waitClickImg_noWait_withBool(place_img.back2, 0.6, 0)
  49. if ret:
  50. return
  51. ret |= waitClickImg_noWait_withBool(place_img.back3, 0.6, 0)
  52. if ret:
  53. return
  54. ret, pos = waitFindImg(place_img.title, 1, 0)
  55. if ret:
  56. pcacc_mouse.click(pos[0], pos[1] + 40)
  57. def backToGame(preTime = 0):
  58. tryMaxTimes = 5
  59. while tryMaxTimes > 0:
  60. tryMaxTimes -= 1
  61. if waitFindImg_withBool(place_img.gameIn, 1, preTime) == False:
  62. basic_operate.do_back()
  63. else:
  64. return True
  65. return False
  66. @staticmethod
  67. def go_town(preTime = 0):
  68. if basic_operate.backToGame(preTime) == False:
  69. return False
  70. waitClickImg_noWait_withBool(place_img.outside, 0.6, 0)
  71. return True
  72. @staticmethod
  73. def go_outside(preTime = 0):
  74. if basic_operate.backToGame(preTime) == False:
  75. return False
  76. waitClickImg_noWait_withBool(place_img.town, 0.6, 0)
  77. return True
  78. @staticmethod
  79. def click_outside_search():
  80. taskListRet, taskListPos = waitFindImg(monster_img.tasklist, 2, 3)
  81. if taskListRet == False:
  82. return False
  83. else:
  84. pcacc_mouse.click(taskListPos[0], taskListPos[1] - 110)#click search
  85. myTimeSleep_big()
  86. return True
  87. @staticmethod
  88. def enter_auto_supply_resource(enter_pic):
  89. if waitClickImg_noWait_withBool(enter_pic, 2, 2) == False:
  90. return False
  91. if waitClickImg_noWait_withBool(train_img.getAll, 2, 1) == False:
  92. return True
  93. if waitClickImg_noWait_withBool(train_img.enter, 2, 1) == False:
  94. return False
  95. if waitClickImg_noWait_withBool(enter_pic, 2, 1) == False:
  96. return False
  97. return True
  98. @staticmethod
  99. def return_line():
  100. if waitClickImg_noWait_withBool(monster_img.returnLine, 2, 1) == False:
  101. return False
  102. if waitClickImg_noWait_withBool(monster_img.enter, 2, 1) == False:
  103. return False
  104. return True
  105. def task_return_game():
  106. tryTimes = 3
  107. while tryTimes > 0:
  108. if False == waitFindImg_withBool([place_img.title], 1, 1):
  109. waitClickImg_noWait([place_img.ico, place_img.ico2], 1, 0)
  110. myTimeSleep_big()
  111. tryTimes -= 1
  112. if tryTimes == 0:
  113. return False
  114. else:
  115. break
  116. def task_save_compress_pic():
  117. # 截取屏幕截图
  118. screenshot = pyautogui.screenshot()
  119. compressed_data = compress_image(screenshot)
  120. # 保存压缩后的图像到文件
  121. with open('compressed_screenshot.jpg', 'wb') as f:
  122. f.write(compressed_data)
  123. def task_close_game():
  124. subprocess.call(f"taskkill /f /im MuMuPlayer.exe")
  125. subprocess.call(f"taskkill /f /im MuMuVMMHeadless.exe")
  126. subprocess.call(f"taskkill /f /im MuMuVMMSVC.exe")
  127. myTimeSleep_big()
  128. def task_start_game():
  129. isSuccess = True
  130. path1 = R'C:\\Program Files\\Netease\\MuMuPlayer-12.0\\shell\\MuMuPlayer.exe'
  131. path2 = R'C:\Program Files\Netease\MuMu Player 12\shell\MuMuPlayer.exe'
  132. if os.path.exists(path1):
  133. subprocess.Popen(path1)
  134. elif os.path.exists(path2):
  135. subprocess.Popen(path2)
  136. if waitClickImg_withBool(gameStart_img.ico, 100, 20) == False:
  137. return False
  138. waitFindImg_withBool(place_img.gameIn, 10, 20)
  139. basic_operate.go_town()
  140. waitFindImg_withBool(place_img.gameIn, 10, 20)
  141. basic_operate.go_town()
  142. if waitFindImg_withBool(place_img.gameIn, 10, 20) == False:
  143. return False
  144. myTimeSleep_big()
  145. return isSuccess
  146. class dongri_task:
  147. def __init__(self, name):
  148. self.name = name
  149. def run(self):
  150. print(f"Running task: {self.name}")
  151. class task_fightMonster(dongri_task):
  152. def __init__(self, add_strengh, fight_bigMonster):
  153. super().__init__(f"战斗怪物")
  154. self.add_strengh = add_strengh
  155. if fight_bigMonster == True:
  156. self.monster = monster_img.bigMonster
  157. self.attack = monster_img.muti_team
  158. else:
  159. self.monster = monster_img.wolf
  160. self.attack = monster_img.attack
  161. def run(self):
  162. basic_operate.go_outside()
  163. if False == basic_operate.click_outside_search():
  164. return False
  165. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  166. print("没有足够的体力了")
  167. return False
  168. if waitFindImg_withBool(monster_img.search, 2, 1):
  169. myTimeSleep_big()
  170. yys_dragAuto(monster_img.move_left)
  171. if waitClickImg_noWait_withBool(self.monster, 2, 1) == False:
  172. return False
  173. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  174. return False
  175. if waitClickImg_noWait_withBool(self.attack, 2, 1) == False:
  176. return False
  177. waitClickImg_noWait_withBool(monster_img.begin_multi, 2, 1)
  178. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  179. return False
  180. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  181. return False
  182. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  183. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  184. maxTryTimes = 3
  185. while maxTryTimes > 0:
  186. maxTryTimes -= 1
  187. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 2, 1)
  188. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  189. return True
  190. class task_collect(dongri_task):
  191. def __init__(self, type = 0):
  192. if type == 0:
  193. typeArr = [4,3,2,1]
  194. type = typeArr[random.randint(0, len(typeArr) - 1)]
  195. elif type == 5:
  196. typeArr = [2,1]
  197. type = typeArr[random.randint(0, len(typeArr) - 1)]
  198. if type == 1:
  199. self.type = monster_img.meat
  200. self.line = monster_img.line2
  201. super().__init__(f"采集肉")
  202. elif type == 2:
  203. self.type = monster_img.wood
  204. self.line = monster_img.line3
  205. super().__init__(f"采集木头")
  206. elif type == 3:
  207. self.type = monster_img.mine
  208. self.line = None
  209. super().__init__(f"采矿石")
  210. elif type == 4:
  211. self.type = monster_img.iron
  212. self.line = None
  213. super().__init__(f"采集铁矿石")
  214. def run(self):
  215. basic_operate.go_outside()
  216. if False == basic_operate.click_outside_search():
  217. return False
  218. if waitFindImg_withBool(monster_img.search, 2, 1):
  219. myTimeSleep_big()
  220. yys_dragAuto(monster_img.move_right)
  221. if waitClickImg_noWait_withBool(self.type, 2, 1) == False:
  222. return False
  223. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  224. return False
  225. if waitClickImg_withBool(monster_img.collect, 2, 1) == False:
  226. return False
  227. if self.line != None:
  228. waitClickImg_noWait_withBool(self.line, 2, 1)
  229. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  230. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  231. maxTryTimes = 3
  232. while maxTryTimes > 0:
  233. maxTryTimes -= 1
  234. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 2, 1)
  235. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  236. return True
  237. class task_train(dongri_task):
  238. def __init__(self):
  239. super().__init__(f"检查训练")
  240. def run(self):
  241. basic_operate.go_town()
  242. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  243. return False
  244. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  245. return False
  246. tryTimes = 3
  247. while tryTimes > 0:
  248. tryTimes -= 1
  249. waitClickImg_noWait_withBool([train_img.dun, train_img.gong, train_img.mao], 2, 1)
  250. if waitClickImg_noWait_withBool(train_img.train, 2, 1):
  251. break
  252. return basic_operate.enter_auto_supply_resource(train_img.begin_train)
  253. class task_checkHelp(dongri_task):
  254. def __init__(self, isOutSide = False):
  255. super().__init__(f"检查帮助")
  256. self.isOutSide = isOutSide
  257. def run(self):
  258. if self.isOutSide:
  259. basic_operate.go_outside()
  260. else:
  261. basic_operate.go_town()
  262. waitClickImg_noWait_withBool(place_img.help, 2, 1)
  263. return True
  264. class task_checkStoreRoom(dongri_task):
  265. def __init__(self):
  266. super().__init__(f"检查仓库")
  267. def run(self):
  268. basic_operate.go_town()
  269. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  270. return False
  271. myTimeSleep_big()
  272. yys_dragAuto(check_img.move_down)
  273. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  274. return False
  275. myTimeSleep_big()
  276. pcacc_mouse.quickclick_current()
  277. if waitClickImg_noWait_withBool(check_img.storeroom, 2, 1) == False:
  278. return False
  279. return True
  280. class task_checkConfilits(dongri_task):
  281. def __init__(self):
  282. super().__init__(f"检查集结")
  283. def run(self):
  284. basic_operate.go_outside()
  285. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  286. return False
  287. if waitClickImg_noWait_withBool(check_img.paticipate, 2, 1) == False:
  288. return False
  289. if waitClickImg_noWait_withBool(check_img.auto_confilit, 2, 1) == False:
  290. return False
  291. return True
  292. class task_checkDonata(dongri_task):
  293. def __init__(self):
  294. super().__init__(f"检查捐献")
  295. def run(self):
  296. basic_operate.go_town()
  297. if waitClickImg_noWait_withBool(check_img.union, 2, 1) == False:
  298. return False
  299. if waitClickImg_noWait_withBool(check_img.union_technology, 2, 1) == False:
  300. return False
  301. if waitClickImg_noWait_withBool(check_img.technology_better, 2, 1) == False:
  302. return False
  303. if waitClickImg_withBool([check_img.donate, check_img.donate2], 2, 1) == False:
  304. return False
  305. else:
  306. maxTryTimes = 3
  307. while waitClickImg_withBool([check_img.donate, check_img.donate2], 1, 0) and maxTryTimes > 0:
  308. maxTryTimes -= 1
  309. return True
  310. class task_checkAdventure(dongri_task):
  311. def __init__(self):
  312. super().__init__(f"检查冒险")
  313. def run(self):
  314. basic_operate.go_town()
  315. if waitClickImg_noWait_withBool(check_img.adventure, 2, 1) == False:
  316. return False
  317. if waitClickImg_noWait_withBool(check_img.get, 2, 1) == False:
  318. return False
  319. if waitClickImg_noWait_withBool(check_img.bigGet, 2, 1) == False:
  320. return False
  321. return True
  322. class task_waitTime(dongri_task):
  323. def __init__(self):
  324. super().__init__(f"等待时间")
  325. def run(self):
  326. myTimeSleep(300)
  327. class check_buildOrResearch(dongri_task):
  328. def __init__(self):
  329. super().__init__(f"检查建筑或研究")
  330. def run(self):
  331. basic_operate.go_town()
  332. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  333. return False
  334. if waitClickImg_noWait_withBool(check_img.needgo, 2, 1) == False:
  335. return False
  336. dstType = 'none'
  337. while True:
  338. if waitFindImg_withBool([check_img.upgrade_done, check_img.upgrade_done2, check_img.upgrade_done3, check_img.upgrade_next], 2, 1):
  339. dstType = 'build'
  340. break
  341. handRet, handPos = waitFindImg(check_img.hand, 2, 1)
  342. if not handRet:
  343. return False
  344. detailRet, detailPos = waitFindImg(check_img.detail, 2, 1)
  345. dstPos = [0, 0]
  346. if not detailRet:
  347. # 如果找不到详细信息,兵营之类的,需点中间
  348. dstPos = [handPos[0] - 70, handPos[1] + 120]
  349. else:
  350. dstPos = [detailPos[0] + 70, detailPos[1] - 100]
  351. tryTimes = 5
  352. while tryTimes > 0:
  353. tryTimes -= 1
  354. myTimeSleep_big()
  355. pcacc_mouse.click(dst_x=dstPos[0], dst_y=dstPos[1])
  356. if waitClickImg_noWait_withBool(check_img.research, 2, 1):
  357. dstType = 'research'
  358. break
  359. elif waitClickImg_noWait_withBool(check_img.build_upgrade, 2, 1):
  360. dstType = 'build'
  361. break
  362. break
  363. if dstType == 'none':
  364. print('没有找到建筑或研究')
  365. return False
  366. elif dstType == 'build':
  367. while basic_operate.enter_auto_supply_resource([check_img.upgrade_done, check_img.upgrade_done2, check_img.upgrade_done3, check_img.upgrade_next]):
  368. continue
  369. elif dstType == 'research':
  370. if waitClickImg_withBool([check_img.research_type1, check_img.research_type2], 2, 1) == False:
  371. return False
  372. if basic_operate.enter_auto_supply_resource(check_img.research_done) == False:
  373. return False
  374. waitClickImg_withBool([check_img.help, check_img.help2, check_img.help3], 2, 2)
  375. return True
  376. class task_information(dongri_task):
  377. def __init__(self):
  378. super().__init__(f"检查情报")
  379. def run(self):
  380. basic_operate.go_outside()
  381. if waitClickImg_noWait_withBool(information_img.information, 2, 1) == False:
  382. return False
  383. if waitClickImg_noWait_withBool([information_img.hero0, information_img.hero1, information_img.hero2], 2, 1):
  384. if waitClickImg_noWait_withBool(information_img.gotosee, 2, 1) == False:
  385. return False
  386. if waitClickImg_noWait_withBool(information_img.explore, 2, 1) == False:
  387. return False
  388. if waitClickImg_noWait_withBool(information_img.hero_fight, 2, 1) == False:
  389. waitClickImg_noWait(information_img.add_strength, 1, 1)
  390. waitClickImg_noWait(information_img.add_strength, 1, 1)
  391. waitClickImg_noWait(information_img.add_strength, 1, 1)
  392. return False
  393. myTimeSleep_big()
  394. return True
  395. elif waitClickImg_noWait_withBool([information_img.camp1, information_img.camp2], 2, 1):
  396. if waitClickImg_noWait_withBool(information_img.gotosee, 2, 1) == False:
  397. return False
  398. if waitClickImg_noWait_withBool(information_img.survive, 2, 1) == False:
  399. return False
  400. waitClickImg_noWait(information_img.add_strength, 1, 1)
  401. waitClickImg_noWait(information_img.add_strength, 1, 1)
  402. waitClickImg_noWait(information_img.add_strength, 1, 1)
  403. return True
  404. elif waitClickImg_noWait_withBool([information_img.wolf0, information_img.wolf1, information_img.wolf2], 2, 1):
  405. if waitClickImg_noWait_withBool(information_img.gotosee, 2, 1) == False:
  406. return False
  407. if waitClickImg_noWait_withBool(information_img.fight, 2, 1) == False:
  408. return False
  409. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  410. return False
  411. if waitClickImg_withBool([monster_img.fight, monster_img.fight2], 2, 1) == False:
  412. return False
  413. waitClickImg_noWait(information_img.add_strength, 1, 1)
  414. waitClickImg_noWait(information_img.add_strength, 1, 1)
  415. waitClickImg_noWait(information_img.add_strength, 1, 1)
  416. return True
  417. else:
  418. return False
  419. class task_returnAllLine(dongri_task):
  420. def __init__(self):
  421. super().__init__(f"返回所有路线")
  422. def run(self):
  423. basic_operate.go_outside()
  424. basic_operate.return_line()
  425. basic_operate.return_line()
  426. basic_operate.return_line()
  427. basic_operate.return_line()
  428. basic_operate.return_line()
  429. basic_operate.return_line()
  430. return True
  431. class task_paticipateInTeam(dongri_task):
  432. def __init__(self):
  433. super().__init__(f"参与队伍")
  434. def run(self):
  435. basic_operate.go_outside()
  436. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  437. return False
  438. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1) == False:
  439. return False
  440. while True:
  441. if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
  442. break
  443. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  444. break
  445. if waitClickImg_noWait_withBool(monster_img.line4, 0.1, 1) == False:
  446. break
  447. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  448. break
  449. break
  450. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  451. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  452. maxTryTimes = 3
  453. while maxTryTimes > 0:
  454. maxTryTimes -= 1
  455. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  456. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  457. break
  458. return True
  459. if __name__ == '__main__':
  460. #basic_operate.go_town()
  461. #task_fightMonster(False, True).run()
  462. #task_checkHelp().run()
  463. #task_checkStoreRoom().run()
  464. #task_collect().run()
  465. #task_train().run()
  466. #task_information().run()
  467. #check_buildOrResearch().run()
  468. task_checkDonata().run()
  469. #task_collect(1).run()
  470. #task_collect(2).run()
  471. #task_collect(3).run()
  472. #task_collect(4).run()
  473. #task_returnAllLine().run()
  474. #task_paticipateInTeam().run()