dongri_task.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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] + 80)
  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. @staticmethod
  106. def add_strength():
  107. basic_operate.do_back()
  108. if waitClickImg_noWait_withBool(check_img.no_strength, 2, 1) == False:
  109. return False
  110. if waitClickImg_noWait_withBool(check_img.add_strength, 2, 1) == False:
  111. return False
  112. if waitClickImg_noWait_withBool(information_img.add_strength, 2, 1) == False:
  113. return False
  114. if waitClickImg_noWait_withBool(information_img.add_strength, 2, 1) == False:
  115. return False
  116. if waitClickImg_noWait_withBool(information_img.add_strength, 2, 1) == False:
  117. return False
  118. return True
  119. def task_return_game():
  120. tryTimes = 3
  121. while tryTimes > 0:
  122. if False == waitFindImg_withBool([place_img.title], 1, 1):
  123. waitClickImg_noWait([place_img.ico, place_img.ico2], 1, 0)
  124. myTimeSleep_big()
  125. tryTimes -= 1
  126. if tryTimes == 0:
  127. return False
  128. else:
  129. break
  130. def task_save_compress_pic():
  131. # 截取屏幕截图
  132. screenshot = pyautogui.screenshot()
  133. compressed_data = compress_image(screenshot)
  134. # 保存压缩后的图像到文件
  135. with open('compressed_screenshot.jpg', 'wb') as f:
  136. f.write(compressed_data)
  137. def task_close_game():
  138. subprocess.call(f"taskkill /f /im MuMuPlayer.exe")
  139. subprocess.call(f"taskkill /f /im MuMuVMMHeadless.exe")
  140. subprocess.call(f"taskkill /f /im MuMuVMMSVC.exe")
  141. myTimeSleep_big()
  142. def task_start_game():
  143. isSuccess = True
  144. path1 = R'C:\\Program Files\\Netease\\MuMuPlayer-12.0\\shell\\MuMuPlayer.exe'
  145. path2 = R'C:\Program Files\Netease\MuMu Player 12\shell\MuMuPlayer.exe'
  146. if os.path.exists(path1):
  147. subprocess.Popen(path1)
  148. elif os.path.exists(path2):
  149. subprocess.Popen(path2)
  150. if waitClickImg_withBool(gameStart_img.ico, 100, 20) == False:
  151. return False
  152. waitFindImg_withBool(place_img.gameIn, 10, 20)
  153. basic_operate.go_town()
  154. waitFindImg_withBool(place_img.gameIn, 10, 20)
  155. basic_operate.go_town()
  156. if waitFindImg_withBool(place_img.gameIn, 10, 20) == False:
  157. return False
  158. myTimeSleep_big()
  159. return isSuccess
  160. class dongri_task:
  161. def __init__(self, name):
  162. self.name = name
  163. def run(self):
  164. print(f"Running task: {self.name}")
  165. class task_fightMonster(dongri_task):
  166. def __init__(self, add_strengh, fight_bigMonster, isSimple):
  167. super().__init__(f"战斗怪物")
  168. self.add_strengh = add_strengh
  169. self.isSimple = isSimple
  170. if fight_bigMonster == True:
  171. self.monster = monster_img.bigMonster
  172. self.attack = monster_img.muti_team
  173. else:
  174. self.monster = monster_img.wolf
  175. self.attack = monster_img.attack
  176. def run(self):
  177. basic_operate.go_outside()
  178. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  179. if self.add_strengh:
  180. basic_operate.add_strength()
  181. basic_operate.go_outside()
  182. else:
  183. print("没有足够的体力了")
  184. return False
  185. if False == basic_operate.click_outside_search():
  186. return False
  187. if waitFindImg_withBool(monster_img.search, 2, 1):
  188. myTimeSleep_big()
  189. yys_dragAuto(monster_img.move_left)
  190. if waitClickImg_noWait_withBool(self.monster, 2, 1) == False:
  191. return False
  192. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  193. return False
  194. if waitClickImg_noWait_withBool(self.attack, 2, 1) == False:
  195. return False
  196. waitClickImg_noWait_withBool(monster_img.begin_multi, 2, 1)
  197. if not self.isSimple:
  198. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  199. return False
  200. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  201. return False
  202. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  203. return False
  204. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  205. maxTryTimes = 3
  206. while maxTryTimes > 0:
  207. maxTryTimes -= 1
  208. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 2, 1)
  209. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  210. return True
  211. class task_collect(dongri_task):
  212. def __init__(self, type = 0, isSimple = False):
  213. self.isSimple = isSimple
  214. if type == 0:
  215. typeArr = [4,3,2,1]
  216. type = typeArr[random.randint(0, len(typeArr) - 1)]
  217. elif type == 5:
  218. typeArr = [2,1]
  219. type = typeArr[random.randint(0, len(typeArr) - 1)]
  220. if type == 1:
  221. self.type = monster_img.meat
  222. self.line = monster_img.line2
  223. super().__init__(f"采集肉")
  224. elif type == 2:
  225. self.type = monster_img.wood
  226. self.line = monster_img.line3
  227. super().__init__(f"采集木头")
  228. elif type == 3:
  229. self.type = monster_img.mine
  230. self.line = monster_img.line4
  231. super().__init__(f"采矿石")
  232. elif type == 4:
  233. self.type = monster_img.iron
  234. self.line = monster_img.line5
  235. super().__init__(f"采集铁矿石")
  236. if isSimple:
  237. self.line = None
  238. def run(self):
  239. basic_operate.go_outside()
  240. if False == basic_operate.click_outside_search():
  241. return False
  242. if waitFindImg_withBool(monster_img.search, 2, 1):
  243. myTimeSleep_big()
  244. yys_dragAuto(monster_img.move_right)
  245. if waitClickImg_noWait_withBool(self.type, 2, 1) == False:
  246. return False
  247. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  248. return False
  249. if waitClickImg_withBool(monster_img.collect, 2, 1) == False:
  250. return False
  251. if self.line != None:
  252. waitClickImg_noWait_withBool(self.line, 2, 1)
  253. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  254. return False
  255. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  256. maxTryTimes = 3
  257. while maxTryTimes > 0:
  258. maxTryTimes -= 1
  259. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 2, 1)
  260. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  261. return True
  262. class task_train(dongri_task):
  263. def __init__(self, force_lv1 = False):
  264. super().__init__(f"检查训练")
  265. self.force_lv1 = force_lv1
  266. def run(self):
  267. basic_operate.go_town()
  268. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  269. return False
  270. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  271. return False
  272. tryTimes = 3
  273. while tryTimes > 0:
  274. tryTimes -= 1
  275. waitClickImg_noWait_withBool([train_img.dun, train_img.gong, train_img.mao], 2, 1)
  276. if waitClickImg_noWait_withBool(train_img.train, 2, 1):
  277. break
  278. if self.force_lv1:
  279. myTimeSleep_big()
  280. yys_dragAuto(train_img.move_left)
  281. yys_dragAuto(train_img.move_left)
  282. waitClickImg_noWait_withBool(train_img.soilder_lv1, 2, 1)
  283. return basic_operate.enter_auto_supply_resource(train_img.begin_train)
  284. class task_checkHelp(dongri_task):
  285. def __init__(self, isOutSide = False):
  286. super().__init__(f"检查帮助")
  287. self.isOutSide = isOutSide
  288. def run(self):
  289. if self.isOutSide:
  290. basic_operate.go_outside()
  291. else:
  292. basic_operate.go_town()
  293. waitClickImg_noWait_withBool(place_img.help, 2, 1)
  294. return True
  295. class task_checkStoreRoom(dongri_task):
  296. def __init__(self):
  297. super().__init__(f"检查仓库或招募")
  298. def run(self):
  299. basic_operate.go_town()
  300. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  301. return False
  302. myTimeSleep_big()
  303. yys_dragAuto(check_img.move_down)
  304. if waitClickImg_noWait_withBool((train_img.train_success, check_img.needgo), 2, 1) == False:
  305. return False
  306. myTimeSleep_big()
  307. pcacc_mouse.quickclick_current()
  308. if waitClickImg_noWait_withBool((check_img.storeroom, check_img.invite_free), 2, 1) == False:
  309. return False
  310. return True
  311. class task_checkConfilits(dongri_task):
  312. def __init__(self):
  313. super().__init__(f"检查集结")
  314. def run(self):
  315. basic_operate.go_outside()
  316. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  317. return False
  318. if waitClickImg_noWait_withBool(check_img.paticipate, 2, 1) == False:
  319. return False
  320. if waitClickImg_noWait_withBool(check_img.auto_confilit, 2, 1) == False:
  321. return False
  322. return True
  323. class task_checkDonata(dongri_task):
  324. def __init__(self):
  325. super().__init__(f"检查捐献")
  326. def run(self):
  327. basic_operate.go_town()
  328. if waitClickImg_noWait_withBool(check_img.union, 2, 1) == False:
  329. return False
  330. if waitClickImg_noWait_withBool(check_img.union_technology, 2, 1) == False:
  331. return False
  332. if waitClickImg_noWait_withBool(check_img.technology_better, 2, 1) == False:
  333. return False
  334. if waitClickImg_withBool([check_img.donate, check_img.donate2], 2, 1) == False:
  335. return False
  336. else:
  337. maxTryTimes = 3
  338. while waitClickImg_withBool([check_img.donate, check_img.donate2], 1, 0) and maxTryTimes > 0:
  339. maxTryTimes -= 1
  340. return True
  341. class task_checkAdventure(dongri_task):
  342. def __init__(self):
  343. super().__init__(f"检查冒险")
  344. def run(self):
  345. basic_operate.go_town()
  346. if waitClickImg_noWait_withBool(check_img.adventure, 2, 1) == False:
  347. return False
  348. if waitClickImg_noWait_withBool(check_img.get, 2, 1) == False:
  349. return False
  350. if waitClickImg_noWait_withBool(check_img.bigGet, 2, 1) == False:
  351. return False
  352. return True
  353. class task_waitTime(dongri_task):
  354. def __init__(self):
  355. super().__init__(f"等待时间")
  356. def run(self):
  357. myTimeSleep(300)
  358. class check_buildOrResearch(dongri_task):
  359. def __init__(self):
  360. super().__init__(f"检查建筑或研究")
  361. def run(self):
  362. basic_operate.go_town()
  363. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  364. return False
  365. if waitClickImg_noWait_withBool(check_img.needgo, 2, 1) == False:
  366. return False
  367. dstType = 'none'
  368. while True:
  369. if waitFindImg_withBool([check_img.upgrade_done, check_img.upgrade_done2, check_img.upgrade_done3, check_img.upgrade_next, check_img.upgrade_done4], 2, 1):
  370. dstType = 'build'
  371. break
  372. handRet, handPos = waitFindImg(check_img.hand, 2, 1)
  373. if not handRet:
  374. return False
  375. detailRet, detailPos = waitFindImg((check_img.detail,check_img.detail2), 2, 1)
  376. dstPos = [0, 0]
  377. if not detailRet:
  378. # 如果找不到详细信息,兵营之类的,需点中间
  379. dstPos = [handPos[0] - 70, handPos[1] + 120]
  380. else:
  381. dstPos = [detailPos[0] + 70, detailPos[1] - 100]
  382. tryTimes = 5
  383. while tryTimes > 0:
  384. tryTimes -= 1
  385. myTimeSleep_big()
  386. pcacc_mouse.click(dst_x=dstPos[0], dst_y=dstPos[1])
  387. if waitClickImg_noWait_withBool(check_img.build_upgrade, 2, 1):
  388. dstType = 'build'
  389. break
  390. elif waitClickImg_noWait_withBool(check_img.research, 2, 1):
  391. dstType = 'research'
  392. break
  393. break
  394. if dstType == 'none':
  395. print('没有找到建筑或研究')
  396. return False
  397. elif dstType == 'build':
  398. buildtimes = 4
  399. while basic_operate.enter_auto_supply_resource([check_img.upgrade_done, check_img.upgrade_done2, check_img.upgrade_done3, check_img.upgrade_next, check_img.upgrade_done4]):
  400. buildtimes -= 1
  401. if buildtimes == 0:
  402. break
  403. continue
  404. elif dstType == 'research':
  405. if waitClickImg_withBool([check_img.research_type1, check_img.research_type2], 2, 1) == False:
  406. return False
  407. if basic_operate.enter_auto_supply_resource(check_img.research_done) == False:
  408. return False
  409. waitClickImg_withBool([check_img.help, check_img.help2, check_img.help3], 2, 2)
  410. return True
  411. class task_information(dongri_task):
  412. def __init__(self):
  413. super().__init__(f"检查情报")
  414. def run(self):
  415. basic_operate.go_outside()
  416. if waitClickImg_noWait_withBool(information_img.information, 1, 1) == False:
  417. return False
  418. if waitClickImg_noWait_withBool([information_img.hero0, information_img.hero1, information_img.hero2], 0.5, 0.5):
  419. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  420. return False
  421. if waitClickImg_noWait_withBool(information_img.explore, 1, 1) == False:
  422. return False
  423. if waitClickImg_noWait_withBool(information_img.hero_fight, 1, 1) == False:
  424. waitClickImg_noWait(information_img.add_strength, 1, 1)
  425. waitClickImg_noWait(information_img.add_strength, 1, 1)
  426. waitClickImg_noWait(information_img.add_strength, 1, 1)
  427. return False
  428. myTimeSleep_big()
  429. return True
  430. elif waitClickImg_noWait_withBool([information_img.camp1, information_img.camp2], 0.5, 0.5):
  431. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  432. return False
  433. if waitClickImg_noWait_withBool(information_img.survive, 1, 1) == False:
  434. return False
  435. waitClickImg_noWait(information_img.add_strength, 1, 1)
  436. waitClickImg_noWait(information_img.add_strength, 1, 1)
  437. waitClickImg_noWait(information_img.add_strength, 1, 1)
  438. return True
  439. elif waitClickImg_noWait_withBool([information_img.wolf0, information_img.wolf1, information_img.wolf2], 0.5, 0.5):
  440. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  441. return False
  442. if waitClickImg_noWait_withBool(information_img.fight, 1, 1) == False:
  443. return False
  444. if waitClickImg_noWait_withBool(monster_img.line1, 1, 1) == False:
  445. return False
  446. if waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1) == False:
  447. return False
  448. waitClickImg_noWait(information_img.add_strength, 1, 1)
  449. waitClickImg_noWait(information_img.add_strength, 1, 1)
  450. waitClickImg_noWait(information_img.add_strength, 1, 1)
  451. return True
  452. else:
  453. return False
  454. class task_returnAllLine(dongri_task):
  455. def __init__(self):
  456. super().__init__(f"返回所有路线")
  457. def run(self):
  458. basic_operate.go_outside()
  459. basic_operate.return_line()
  460. basic_operate.return_line()
  461. basic_operate.return_line()
  462. basic_operate.return_line()
  463. basic_operate.return_line()
  464. basic_operate.return_line()
  465. return True
  466. class task_paticipateInTeam(dongri_task):
  467. def __init__(self):
  468. super().__init__(f"参与队伍")
  469. def run(self):
  470. basic_operate.go_outside()
  471. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  472. return False
  473. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1) == False:
  474. return False
  475. while True:
  476. if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
  477. break
  478. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  479. break
  480. if waitClickImg_noWait_withBool(monster_img.line4, 0.1, 1) == False:
  481. break
  482. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  483. break
  484. break
  485. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  486. return False
  487. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  488. maxTryTimes = 3
  489. while maxTryTimes > 0:
  490. maxTryTimes -= 1
  491. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  492. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  493. break
  494. return True
  495. class task_cure(dongri_task):
  496. def __init__(self):
  497. super().__init__(f"治疗")
  498. def run(self):
  499. basic_operate.go_outside()
  500. if waitClickImg_noWait_withBool(check_img.soilder_cure, 2, 1) == False:
  501. return False
  502. if waitClickImg_noWait_withBool(check_img.cure, 2, 1) == False:
  503. return False
  504. if waitClickImg_noWait_withBool(check_img.help4, 2, 1) == False:
  505. return False
  506. return True
  507. if __name__ == '__main__':
  508. #basic_operate.go_town()
  509. #basic_operate.add_strength()
  510. #task_fightMonster(False, True).run()
  511. #task_checkHelp().run()
  512. #task_checkStoreRoom().run()
  513. #task_collect().run()
  514. #task_train().run()
  515. #task_information().run()
  516. #check_buildOrResearch().run()
  517. #task_checkDonata().run()
  518. #task_collect(1).run()
  519. #task_collect(2).run()
  520. #task_collect(3).run()
  521. #task_collect(4).run()
  522. #task_returnAllLine().run()
  523. #task_paticipateInTeam().run()
  524. #task_train(True).run()