dongri_task.py 20 KB

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