dongri_task.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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, force_lv1 = False):
  239. super().__init__(f"检查训练")
  240. self.force_lv1 = force_lv1
  241. def run(self):
  242. basic_operate.go_town()
  243. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  244. return False
  245. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  246. return False
  247. tryTimes = 3
  248. while tryTimes > 0:
  249. tryTimes -= 1
  250. waitClickImg_noWait_withBool([train_img.dun, train_img.gong, train_img.mao], 2, 1)
  251. if waitClickImg_noWait_withBool(train_img.train, 2, 1):
  252. break
  253. if self.force_lv1:
  254. myTimeSleep_big()
  255. yys_dragAuto(train_img.move_left)
  256. yys_dragAuto(train_img.move_left)
  257. waitClickImg_noWait_withBool(train_img.soilder_lv1, 2, 1)
  258. return basic_operate.enter_auto_supply_resource(train_img.begin_train)
  259. class task_checkHelp(dongri_task):
  260. def __init__(self, isOutSide = False):
  261. super().__init__(f"检查帮助")
  262. self.isOutSide = isOutSide
  263. def run(self):
  264. if self.isOutSide:
  265. basic_operate.go_outside()
  266. else:
  267. basic_operate.go_town()
  268. waitClickImg_noWait_withBool(place_img.help, 2, 1)
  269. return True
  270. class task_checkStoreRoom(dongri_task):
  271. def __init__(self):
  272. super().__init__(f"检查仓库")
  273. def run(self):
  274. basic_operate.go_town()
  275. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  276. return False
  277. myTimeSleep_big()
  278. yys_dragAuto(check_img.move_down)
  279. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  280. return False
  281. myTimeSleep_big()
  282. pcacc_mouse.quickclick_current()
  283. if waitClickImg_noWait_withBool(check_img.storeroom, 2, 1) == False:
  284. return False
  285. return True
  286. class task_checkConfilits(dongri_task):
  287. def __init__(self):
  288. super().__init__(f"检查集结")
  289. def run(self):
  290. basic_operate.go_outside()
  291. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  292. return False
  293. if waitClickImg_noWait_withBool(check_img.paticipate, 2, 1) == False:
  294. return False
  295. if waitClickImg_noWait_withBool(check_img.auto_confilit, 2, 1) == False:
  296. return False
  297. return True
  298. class task_checkDonata(dongri_task):
  299. def __init__(self):
  300. super().__init__(f"检查捐献")
  301. def run(self):
  302. basic_operate.go_town()
  303. if waitClickImg_noWait_withBool(check_img.union, 2, 1) == False:
  304. return False
  305. if waitClickImg_noWait_withBool(check_img.union_technology, 2, 1) == False:
  306. return False
  307. if waitClickImg_noWait_withBool(check_img.technology_better, 2, 1) == False:
  308. return False
  309. if waitClickImg_withBool([check_img.donate, check_img.donate2], 2, 1) == False:
  310. return False
  311. else:
  312. maxTryTimes = 3
  313. while waitClickImg_withBool([check_img.donate, check_img.donate2], 1, 0) and maxTryTimes > 0:
  314. maxTryTimes -= 1
  315. return True
  316. class task_checkAdventure(dongri_task):
  317. def __init__(self):
  318. super().__init__(f"检查冒险")
  319. def run(self):
  320. basic_operate.go_town()
  321. if waitClickImg_noWait_withBool(check_img.adventure, 2, 1) == False:
  322. return False
  323. if waitClickImg_noWait_withBool(check_img.get, 2, 1) == False:
  324. return False
  325. if waitClickImg_noWait_withBool(check_img.bigGet, 2, 1) == False:
  326. return False
  327. return True
  328. class task_waitTime(dongri_task):
  329. def __init__(self):
  330. super().__init__(f"等待时间")
  331. def run(self):
  332. myTimeSleep(300)
  333. class check_buildOrResearch(dongri_task):
  334. def __init__(self):
  335. super().__init__(f"检查建筑或研究")
  336. def run(self):
  337. basic_operate.go_town()
  338. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  339. return False
  340. if waitClickImg_noWait_withBool(check_img.needgo, 2, 1) == False:
  341. return False
  342. dstType = 'none'
  343. while True:
  344. if waitFindImg_withBool([check_img.upgrade_done, check_img.upgrade_done2, check_img.upgrade_done3, check_img.upgrade_next], 2, 1):
  345. dstType = 'build'
  346. break
  347. handRet, handPos = waitFindImg(check_img.hand, 2, 1)
  348. if not handRet:
  349. return False
  350. detailRet, detailPos = waitFindImg(check_img.detail, 2, 1)
  351. dstPos = [0, 0]
  352. if not detailRet:
  353. # 如果找不到详细信息,兵营之类的,需点中间
  354. dstPos = [handPos[0] - 70, handPos[1] + 120]
  355. else:
  356. dstPos = [detailPos[0] + 70, detailPos[1] - 100]
  357. tryTimes = 5
  358. while tryTimes > 0:
  359. tryTimes -= 1
  360. myTimeSleep_big()
  361. pcacc_mouse.click(dst_x=dstPos[0], dst_y=dstPos[1])
  362. if waitClickImg_noWait_withBool(check_img.research, 2, 1):
  363. dstType = 'research'
  364. break
  365. elif waitClickImg_noWait_withBool(check_img.build_upgrade, 2, 1):
  366. dstType = 'build'
  367. break
  368. break
  369. if dstType == 'none':
  370. print('没有找到建筑或研究')
  371. return False
  372. elif dstType == 'build':
  373. buildtimes = 4
  374. while basic_operate.enter_auto_supply_resource([check_img.upgrade_done, check_img.upgrade_done2, check_img.upgrade_done3, check_img.upgrade_next]):
  375. buildtimes -= 1
  376. if buildtimes == 0:
  377. break
  378. continue
  379. elif dstType == 'research':
  380. if waitClickImg_withBool([check_img.research_type1, check_img.research_type2], 2, 1) == False:
  381. return False
  382. if basic_operate.enter_auto_supply_resource(check_img.research_done) == False:
  383. return False
  384. waitClickImg_withBool([check_img.help, check_img.help2, check_img.help3], 2, 2)
  385. return True
  386. class task_information(dongri_task):
  387. def __init__(self):
  388. super().__init__(f"检查情报")
  389. def run(self):
  390. basic_operate.go_outside()
  391. if waitClickImg_noWait_withBool(information_img.information, 1, 1) == False:
  392. return False
  393. if waitClickImg_noWait_withBool([information_img.hero0, information_img.hero1, information_img.hero2], 0.5, 0.5):
  394. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  395. return False
  396. if waitClickImg_noWait_withBool(information_img.explore, 1, 1) == False:
  397. return False
  398. if waitClickImg_noWait_withBool(information_img.hero_fight, 1, 1) == False:
  399. waitClickImg_noWait(information_img.add_strength, 1, 1)
  400. waitClickImg_noWait(information_img.add_strength, 1, 1)
  401. waitClickImg_noWait(information_img.add_strength, 1, 1)
  402. return False
  403. myTimeSleep_big()
  404. return True
  405. elif waitClickImg_noWait_withBool([information_img.camp1, information_img.camp2], 0.5, 0.5):
  406. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  407. return False
  408. if waitClickImg_noWait_withBool(information_img.survive, 1, 1) == False:
  409. return False
  410. waitClickImg_noWait(information_img.add_strength, 1, 1)
  411. waitClickImg_noWait(information_img.add_strength, 1, 1)
  412. waitClickImg_noWait(information_img.add_strength, 1, 1)
  413. return True
  414. elif waitClickImg_noWait_withBool([information_img.wolf0, information_img.wolf1, information_img.wolf2], 0.5, 0.5):
  415. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  416. return False
  417. if waitClickImg_noWait_withBool(information_img.fight, 1, 1) == False:
  418. return False
  419. if waitClickImg_noWait_withBool(monster_img.line1, 1, 1) == False:
  420. return False
  421. if waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1) == False:
  422. return False
  423. waitClickImg_noWait(information_img.add_strength, 1, 1)
  424. waitClickImg_noWait(information_img.add_strength, 1, 1)
  425. waitClickImg_noWait(information_img.add_strength, 1, 1)
  426. return True
  427. else:
  428. return False
  429. class task_returnAllLine(dongri_task):
  430. def __init__(self):
  431. super().__init__(f"返回所有路线")
  432. def run(self):
  433. basic_operate.go_outside()
  434. basic_operate.return_line()
  435. basic_operate.return_line()
  436. basic_operate.return_line()
  437. basic_operate.return_line()
  438. basic_operate.return_line()
  439. basic_operate.return_line()
  440. return True
  441. class task_paticipateInTeam(dongri_task):
  442. def __init__(self):
  443. super().__init__(f"参与队伍")
  444. def run(self):
  445. basic_operate.go_outside()
  446. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  447. return False
  448. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1) == False:
  449. return False
  450. while True:
  451. if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
  452. break
  453. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  454. break
  455. if waitClickImg_noWait_withBool(monster_img.line4, 0.1, 1) == False:
  456. break
  457. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  458. break
  459. break
  460. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  461. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  462. maxTryTimes = 3
  463. while maxTryTimes > 0:
  464. maxTryTimes -= 1
  465. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  466. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  467. break
  468. return True
  469. if __name__ == '__main__':
  470. #basic_operate.go_town()
  471. #task_fightMonster(False, True).run()
  472. #task_checkHelp().run()
  473. #task_checkStoreRoom().run()
  474. #task_collect().run()
  475. #task_train().run()
  476. #task_information().run()
  477. #check_buildOrResearch().run()
  478. #task_checkDonata().run()
  479. #task_collect(1).run()
  480. #task_collect(2).run()
  481. #task_collect(3).run()
  482. #task_collect(4).run()
  483. #task_returnAllLine().run()
  484. #task_paticipateInTeam().run()
  485. task_train(True).run()