dongri_task.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. # -*- coding: utf-8 -*-
  2. import threading
  3. from scriptBase.imgFind import pcacc_img, savePic
  4. from scriptBase.mouseClick import pcacc_mouse
  5. from scriptBase.ocr import capture_and_ocr
  6. import scriptBase.base
  7. from scriptBase.comon import *
  8. from scriptBase.ocr import *
  9. from apscheduler.schedulers.blocking import BlockingScheduler
  10. import pyautogui
  11. import random
  12. import sys
  13. import math
  14. import os
  15. import time
  16. from dongri_define import *
  17. from dongri_pic import *
  18. import subprocess
  19. import socket
  20. from dongri_pic import _imported
  21. '''
  22. 基础配置说明:
  23. 600*800(DPI 300)
  24. 游戏画面:流畅
  25. 高帧率关闭
  26. 町中模式:旧版
  27. '''
  28. todo_msg = ''
  29. todo_list = []
  30. g_task_lineCheck = False
  31. def set_lineCheck(val):
  32. global g_task_lineCheck
  33. g_task_lineCheck = val
  34. def get_todo_msg():
  35. global todo_msg
  36. return todo_msg
  37. def get_todo_msgList():
  38. global todo_list
  39. todo_str = ''
  40. for item in todo_list:
  41. todo_str += f'{item["item"]}:{item["time"]}</br>'
  42. return todo_str
  43. def fing_todoList_time(taskStr):
  44. for item in todo_list:
  45. if item['task'] == taskStr:
  46. return item['time']
  47. def task_getComputerName():
  48. return socket.gethostname()
  49. def task_acceptTask():
  50. while True:
  51. myTimeSleep_big()
  52. def init():
  53. global _imported
  54. if not _imported:
  55. acceptTask = threading.Thread(target=task_acceptTask)
  56. acceptTask.daemon = True
  57. if acceptTask.is_alive() == False:
  58. acceptTask.start()
  59. _imported = True
  60. class basic_operate:
  61. @staticmethod
  62. def do_back():
  63. task_return_game()
  64. ret = False
  65. ret |= waitClickImg_noWait_withBool(place_img.back1, 0.6, 0)
  66. if ret:
  67. return
  68. ret |= waitClickImg_noWait_withBool(place_img.back2, 0.6, 0)
  69. if ret:
  70. return
  71. ret |= waitClickImg_noWait_withBool(place_img.back3, 0.6, 0)
  72. if ret:
  73. return
  74. ret, pos = waitFindImg(place_img.title, 1, 0)
  75. if ret:
  76. pcacc_mouse.click(pos[0] + 20, pos[1] + 80)
  77. @staticmethod
  78. def backToGame(preTime = 0):
  79. tryMaxTimes = 5
  80. while tryMaxTimes > 0:
  81. tryMaxTimes -= 1
  82. if waitFindImg_withBool((place_img.gameIn, place_img.gameIn2), 1, preTime) == False:
  83. basic_operate.do_back()
  84. else:
  85. return True
  86. return False
  87. @staticmethod
  88. def go_town(preTime = 0):
  89. if basic_operate.backToGame(preTime) == False:
  90. return False
  91. waitClickImg_noWait_withBool(place_img.outside, 0.6, 0.5)
  92. return True
  93. @staticmethod
  94. def go_outside(preTime = 0):
  95. if basic_operate.backToGame(preTime) == False:
  96. return False
  97. waitClickImg_noWait_withBool(place_img.town, 0.6, 0.5)
  98. return True
  99. @staticmethod
  100. def click_outside_search():
  101. taskListRet, taskListPos = waitFindImg(monster_img.tasklist, 2, 3)
  102. if taskListRet == False:
  103. return False
  104. else:
  105. pcacc_mouse.click(taskListPos[0], taskListPos[1] - 110)#click search
  106. myTimeSleep_big()
  107. return True
  108. @staticmethod
  109. def enter_auto_supply_resource(enter_pic):
  110. if waitClickImg_noWait_withBool(enter_pic, 2, 2) == False:
  111. return False
  112. if waitClickImg_noWait_withBool(train_img.getAll, 2, 1) == False:
  113. return True
  114. if waitClickImg_noWait_withBool(train_img.enter, 2, 1) == False:
  115. return False
  116. if waitClickImg_noWait_withBool(enter_pic, 2, 1) == False:
  117. return False
  118. return True
  119. @staticmethod
  120. def return_line():
  121. if waitClickImg_noWait_withBool(monster_img.returnLine, 2, 1) == False:
  122. return False
  123. if waitClickImg_noWait_withBool(monster_img.enter, 2, 1) == False:
  124. return False
  125. return True
  126. @staticmethod
  127. def add_strength():
  128. if waitClickImg_noWait_withBool(check_img.no_strength, 2, 1) == False:
  129. return False
  130. if waitClickImg_noWait_withBool(check_img.add_strength, 2, 1) == False:
  131. return False
  132. if waitClickImg_noWait_withBool(information_img.add_strength, 2, 1) == False:
  133. return False
  134. if waitClickImg_noWait_withBool(information_img.add_strength, 2, 1) == False:
  135. return False
  136. if waitClickImg_noWait_withBool(information_img.add_strength, 2, 1) == False:
  137. return False
  138. return True
  139. @staticmethod
  140. def get_line_num():
  141. lineStr = yys_ocrAuto(check_img.line_orc)
  142. if len(lineStr) == 0:
  143. return 0
  144. match = re.search(r'\d', lineStr[0]) # 查找第一个数字
  145. if match:
  146. first_digit = match.group()
  147. print("第一个数字:", first_digit)
  148. return int(first_digit)
  149. else:
  150. print("未找到数字")
  151. return 0
  152. def task_return_game():
  153. tryTimes = 3
  154. while tryTimes > 0:
  155. if False == waitFindImg_withBool([place_img.title], 1, 1):
  156. waitClickImg_noWait([place_img.ico, place_img.ico2], 1, 0)
  157. myTimeSleep_big()
  158. tryTimes -= 1
  159. if tryTimes == 0:
  160. return False
  161. else:
  162. break
  163. def task_save_compress_pic():
  164. # 截取屏幕截图
  165. screenshot = pyautogui.screenshot()
  166. compressed_data = compress_image(screenshot)
  167. # 保存压缩后的图像到文件
  168. with open('compressed_screenshot.jpg', 'wb') as f:
  169. f.write(compressed_data)
  170. def task_close_game():
  171. subprocess.call(f"taskkill /f /im MuMuPlayer.exe")
  172. subprocess.call(f"taskkill /f /im MuMuVMMHeadless.exe")
  173. subprocess.call(f"taskkill /f /im MuMuVMMSVC.exe")
  174. myTimeSleep_big()
  175. def task_start_game():
  176. isSuccess = True
  177. path1 = R'C:\\Program Files\\Netease\\MuMuPlayer-12.0\\shell\\MuMuPlayer.exe'
  178. path2 = R'C:\Program Files\Netease\MuMu Player 12\shell\MuMuPlayer.exe'
  179. if os.path.exists(path1):
  180. subprocess.Popen(path1)
  181. elif os.path.exists(path2):
  182. subprocess.Popen(path2)
  183. waitClickImg_withBool(gameStart_img.not_upgrade, 20, 10)
  184. if waitClickImg_withBool(gameStart_img.ico, 100, 0) == False:
  185. return False
  186. waitFindImg_withBool(place_img.gameIn, 10, 20)
  187. basic_operate.go_town()
  188. waitFindImg_withBool(place_img.gameIn, 10, 20)
  189. basic_operate.go_town()
  190. if waitFindImg_withBool(place_img.gameIn, 10, 20) == False:
  191. return False
  192. myTimeSleep_big()
  193. return isSuccess
  194. class dongri_task:
  195. def __init__(self, name):
  196. self.name = name
  197. def run(self):
  198. print(f"Running task: {self.name}")
  199. class task_fight_yongbing(dongri_task):
  200. def __init__(self, add_strengh):
  201. super().__init__("战斗佣兵")
  202. self.add_strengh = add_strengh
  203. def run(self):
  204. basic_operate.go_outside()
  205. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  206. if self.add_strengh:
  207. basic_operate.add_strength()
  208. basic_operate.go_outside()
  209. else:
  210. print("没有足够的体力了")
  211. return False
  212. if basic_operate.get_line_num() >= 6:
  213. return False
  214. if waitClickImg_noWait_withBool(check_img.yongbing, 2, 1) == False:
  215. return False
  216. waitClickImg_noWait_withBool(check_img.detect, 2, 1)
  217. if waitClickImg_noWait_withBool(check_img.yongbing_fight, 2, 1) == False:
  218. return False
  219. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  220. return False
  221. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  222. return False
  223. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  224. return False
  225. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  226. maxTryTimes = 3
  227. while maxTryTimes > 0:
  228. maxTryTimes -= 1
  229. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  230. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  231. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  232. break
  233. return True
  234. class task_fight_jina_only(dongri_task):
  235. def __init__(self):
  236. super().__init__("战斗召唤的吉娜")
  237. def run(self):
  238. basic_operate.go_outside()
  239. #必须加体力
  240. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  241. basic_operate.add_strength()
  242. basic_operate.go_outside()
  243. if waitClickImg_noWait_withBool((check_img.talk_in,check_img.talk_in2), 2, 1) == False:
  244. return False
  245. waitClickImg_noWait_withBool(check_img.talkin_person, 2, 1)
  246. if waitClickImg_noWait_withBool(check_img.talkin_jina, 2, 1) == False:
  247. return False
  248. myTimeSleep_big()
  249. yys_dragAuto(check_img.move_down)
  250. yys_dragAuto(check_img.move_down)
  251. myTimeSleep_big()
  252. if waitClickImg_noWait_withBool(check_img.xiaohao_jina, 2, 1) == False:
  253. return False
  254. if waitClickImg_noWait_withBool((check_img.jina_pic, check_img.jina_pic2), 2, 1) == False:
  255. return False
  256. if waitClickImg_noWait_withBool(monster_img.muti_team, 2, 1) == False:
  257. return False
  258. waitClickImg_noWait_withBool(monster_img.begin_multi, 2, 1)
  259. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  260. return False
  261. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  262. return False
  263. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  264. return False
  265. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  266. maxTryTimes = 3
  267. while maxTryTimes > 0:
  268. maxTryTimes -= 1
  269. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  270. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  271. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  272. break
  273. return True
  274. class task_call_jina(dongri_task):
  275. def __init__(self):
  276. super().__init__("召唤吉娜")
  277. def run(self):
  278. basic_operate.go_outside()
  279. if waitClickImg_noWait_withBool(check_img.pack, 2, 1) == False:
  280. return False
  281. if waitClickImg_noWait_withBool((check_img.other, check_img.other2), 2, 1) == False:
  282. return False
  283. if waitClickImg_noWait_withBool(check_img.jina_jiao, 2, 1) == False:
  284. return False
  285. if waitClickImg_noWait_withBool(check_img.use, 2, 1) == False:
  286. return False
  287. if waitClickImg_noWait_withBool(check_img.share, 2, 1) == False:
  288. return False
  289. if waitClickImg_noWait_withBool(check_img.to_pcacc, 2, 1) == False:
  290. return False
  291. if waitClickImg_noWait_withBool(check_img.share_btn, 2, 1) == False:
  292. return False
  293. return True
  294. class task_fight_jina(dongri_task):
  295. def __init__(self, add_strengh):
  296. super().__init__("战斗吉娜")
  297. self.add_strengh = add_strengh
  298. def run(self):
  299. basic_operate.go_outside()
  300. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  301. if self.add_strengh:
  302. basic_operate.add_strength()
  303. basic_operate.go_outside()
  304. else:
  305. print("没有足够的体力了")
  306. return False
  307. if waitClickImg_noWait_withBool(check_img.pack, 2, 1) == False:
  308. return False
  309. if waitClickImg_noWait_withBool((check_img.other, check_img.other2), 2, 1) == False:
  310. return False
  311. if waitClickImg_noWait_withBool(check_img.jina_jiao, 2, 1) == False:
  312. return False
  313. if waitClickImg_noWait_withBool(check_img.use, 2, 1) == False:
  314. return False
  315. if waitClickImg_noWait_withBool(monster_img.muti_team, 2, 1) == False:
  316. return False
  317. waitClickImg_noWait_withBool(monster_img.begin_multi, 2, 1)
  318. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  319. return False
  320. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  321. return False
  322. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  323. return False
  324. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  325. maxTryTimes = 3
  326. while maxTryTimes > 0:
  327. maxTryTimes -= 1
  328. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  329. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  330. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  331. break
  332. return True
  333. class task_fightMonster(dongri_task):
  334. def __init__(self, add_strengh, fight_bigMonster, isSimple):
  335. self.add_strengh = add_strengh
  336. self.isSimple = isSimple
  337. if fight_bigMonster == True:
  338. super().__init__(f"战斗大怪物")
  339. self.monster = monster_img.bigMonster
  340. self.attack = monster_img.muti_team
  341. else:
  342. super().__init__(f"战斗小怪物")
  343. self.monster = monster_img.wolf
  344. self.attack = monster_img.attack
  345. def run(self):
  346. global g_task_lineCheck
  347. basic_operate.go_outside()
  348. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  349. if self.add_strengh:
  350. basic_operate.add_strength()
  351. basic_operate.go_outside()
  352. else:
  353. print("没有足够的体力了")
  354. return False
  355. maxLineNum = 6
  356. if basic_operate.get_line_num() >= maxLineNum:
  357. return False
  358. if False == basic_operate.click_outside_search():
  359. return False
  360. if waitFindImg_withBool(monster_img.search, 2, 1):
  361. myTimeSleep_big()
  362. yys_dragAuto(monster_img.move_left)
  363. if waitClickImg_noWait_withBool(self.monster, 2, 1) == False:
  364. return False
  365. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  366. return False
  367. if waitClickImg_noWait_withBool(self.attack, 2, 1) == False:
  368. return False
  369. waitClickImg_noWait_withBool(monster_img.begin_multi, 2, 1)
  370. if not self.isSimple:
  371. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  372. return False
  373. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  374. return False
  375. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  376. return False
  377. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  378. maxTryTimes = 3
  379. while maxTryTimes > 0:
  380. maxTryTimes -= 1
  381. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  382. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  383. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  384. break
  385. return True
  386. class task_collect(dongri_task):
  387. def __init__(self, type = 0, isSimple = False, isAddStrenghth = False):
  388. self.isSimple = isSimple
  389. self.isAddStrenghth = isAddStrenghth
  390. if isinstance(type, (list, tuple)):
  391. typeArr = type
  392. type = typeArr[random.randint(0, len(typeArr) - 1)]
  393. elif type == 0:
  394. typeArr = [4,4,3,3,3,2,2,2,1,1]
  395. type = typeArr[random.randint(0, len(typeArr) - 1)]
  396. elif type == 5:
  397. typeArr = [2,1]
  398. type = typeArr[random.randint(0, len(typeArr) - 1)]
  399. if type == 1:
  400. self.type = monster_img.meat
  401. self.line = monster_img.line2
  402. super().__init__(f"采集肉")
  403. elif type == 2:
  404. self.type = monster_img.wood
  405. self.line = monster_img.line3
  406. super().__init__(f"采集木头")
  407. elif type == 3:
  408. self.type = monster_img.mine
  409. self.line = monster_img.line4
  410. super().__init__(f"采矿石")
  411. elif type == 4:
  412. self.type = monster_img.iron
  413. self.line = monster_img.line5
  414. super().__init__(f"采集铁矿石")
  415. else:
  416. self.type = None
  417. self.line = None
  418. super().__init__(f"采集None")
  419. if isSimple:
  420. self.line = None
  421. def run(self):
  422. global g_task_lineCheck
  423. if self.type == None:
  424. return True
  425. basic_operate.go_outside()
  426. maxLineNum = 6
  427. if self.isAddStrenghth or g_task_lineCheck:
  428. maxLineNum = 5
  429. else:
  430. maxLineNum = 6
  431. if basic_operate.get_line_num() >= maxLineNum:
  432. return False
  433. if False == basic_operate.click_outside_search():
  434. return False
  435. if waitFindImg_withBool(monster_img.search, 2, 1):
  436. myTimeSleep_big()
  437. yys_dragAuto(monster_img.move_right)
  438. if waitClickImg_noWait_withBool(self.type, 2, 1) == False:
  439. return False
  440. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  441. return False
  442. if waitClickImg_withBool(monster_img.collect, 2, 1) == False:
  443. return False
  444. if self.line != None:
  445. waitClickImg_noWait_withBool(self.line, 2, 1)
  446. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  447. return False
  448. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  449. maxTryTimes = 3
  450. while maxTryTimes > 0:
  451. maxTryTimes -= 1
  452. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  453. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  454. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  455. break
  456. return True
  457. class task_train(dongri_task):
  458. def __init__(self, train_type = None):
  459. super().__init__(f"检查训练{train_type}")
  460. self.train_type = train_type
  461. def run(self):
  462. basic_operate.go_town()
  463. if self.train_type == 'None':
  464. return True
  465. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  466. return False
  467. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  468. return False
  469. tryTimes = 3
  470. isSuccess = False
  471. while tryTimes > 0:
  472. tryTimes -= 1
  473. waitClickImg_noWait_withBool([train_img.dun, train_img.gong, train_img.mao], 2, 1)
  474. if waitClickImg_noWait_withBool(train_img.train, 2, 1):
  475. isSuccess = True
  476. break
  477. if isSuccess == False:
  478. pcacc_mouse.quickclick_current()
  479. myTimeSleep_big()
  480. pcacc_mouse.quickclick_current()
  481. if waitClickImg_noWait_withBool(train_img.train, 2, 1) == False:
  482. return False
  483. if self.train_type == 'lv1':
  484. myTimeSleep_big()
  485. yys_dragAuto(train_img.move_left)
  486. yys_dragAuto(train_img.move_left)
  487. waitClickImg_noWait_withBool(train_img.soilder_lv1, 2, 1)
  488. elif self.train_type == 'lv8':
  489. waitClickImg_noWait_withBool(train_img.soilder_lv8, 2, 1)
  490. elif self.train_type == 'lv9':
  491. waitClickImg_noWait_withBool(train_img.soilder_lv9, 2, 1)
  492. elif self.train_type == 'upgrade':
  493. waitClickImg_noWait_withBool(train_img.upgrade_small, 2, 1)
  494. waitClickImg_noWait_withBool(train_img.upgrade_big, 2, 1)
  495. return basic_operate.enter_auto_supply_resource([train_img.begin_train,train_img.begin_train2])
  496. class task_checkHelp(dongri_task):
  497. def __init__(self, isOutSide = False):
  498. super().__init__(f"检查帮助")
  499. self.isOutSide = isOutSide
  500. def run(self):
  501. if self.isOutSide:
  502. basic_operate.go_outside()
  503. else:
  504. basic_operate.go_town()
  505. waitClickImg_noWait_withBool(place_img.help, 2, 1)
  506. return True
  507. class task_gotoTree(dongri_task):
  508. def __init__(self):
  509. super().__init__(f"查看生命之树")
  510. def run(self):
  511. basic_operate.go_town()
  512. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  513. return False
  514. myTimeSleep_big()
  515. yys_dragAuto(check_img.move_down)
  516. yys_dragAuto(check_img.move_down)
  517. myTimeSleep_big()
  518. if waitClickImg_noWait_withBool(check_img.life_tree, 2, 1) == False:
  519. return False
  520. myTimeSleep_big()
  521. pcacc_mouse.quickclick_current()
  522. myTimeSleep_big()
  523. waitClickImg_noWait_withBool(check_img.life_jam, 2, 1)
  524. waitClickImg_noWait_withBool(check_img.life_jam, 2, 1)
  525. return True
  526. class task_checkStoreRoom(dongri_task):
  527. def __init__(self):
  528. super().__init__(f"检查仓库或招募")
  529. def run(self):
  530. basic_operate.go_town()
  531. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  532. return False
  533. myTimeSleep_big()
  534. yys_dragAuto(check_img.move_down)
  535. yys_dragAuto(check_img.move_down)
  536. myTimeSleep_big()
  537. if waitClickImg_noWait_withBool((train_img.train_success, check_img.needgo), 2, 1) == False:
  538. return False
  539. myTimeSleep_big()
  540. if waitFindImg_withBool(check_img.pet_findtreature, 2, 1) == False:
  541. waitClickImg_noWait_withBool(check_img.bigGet, 2, 1)
  542. pcacc_mouse.quickclick_current()
  543. myTimeSleep_big()
  544. if waitClickImg_noWait_withBool((check_img.detail,check_img.detail2), 2, 1):
  545. myTimeSleep_big()
  546. basic_operate.go_town()
  547. myTimeSleep_big()
  548. if waitClickImg_noWait_withBool((check_img.storeroom, check_img.storeroom2, check_img.invite_free), 2, 1) == False:
  549. return False
  550. myTimeSleep_big()
  551. pcacc_mouse.quickclick_current()
  552. myTimeSleep_big()
  553. waitClickImg_noWait_withBool(check_img.store_strength, 2, 1)
  554. waitClickImg_noWait_withBool((check_img.get,check_img.bigGet), 2, 1)
  555. else:
  556. if waitClickImg_noWait_withBool(check_img.pet_success, 2, 1):
  557. myTimeSleep_big()
  558. dstPos = get_yys_random_point(check_img.pet_getRegion)
  559. pcacc_mouse.click(dstPos[0], dstPos[1])
  560. myTimeSleep_big()
  561. elif waitClickImg_noWait_withBool((check_img.pet_advance, check_img.pet_senior, check_img.pet_junior), 2, 1):
  562. waitClickImg_noWait_withBool(check_img.pet_gotreature, 2, 1)
  563. waitClickImg_noWait_withBool(check_img.pet_begintreature, 2, 1)
  564. return True
  565. class task_checkConfilits(dongri_task):
  566. def __init__(self):
  567. super().__init__(f"检查集结")
  568. def run(self):
  569. basic_operate.go_outside()
  570. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  571. return False
  572. if waitClickImg_noWait_withBool(check_img.paticipate, 2, 1) == False:
  573. return False
  574. if waitClickImg_noWait_withBool(check_img.auto_confilit, 2, 1) == False:
  575. return False
  576. return True
  577. class task_checkDonata(dongri_task):
  578. def __init__(self):
  579. super().__init__(f"检查捐献")
  580. def run(self):
  581. basic_operate.go_town()
  582. if waitClickImg_noWait_withBool(check_img.union, 2, 1) == False:
  583. return False
  584. if waitClickImg_noWait_withBool(check_img.union_technology, 2, 1) == False:
  585. return False
  586. if waitClickImg_noWait_withBool(check_img.technology_better, 2, 1) == False:
  587. return False
  588. if waitClickImg_withBool([check_img.donate, check_img.donate2], 2, 1) == False:
  589. return False
  590. else:
  591. maxTryTimes = 3
  592. while waitClickImg_withBool([check_img.donate, check_img.donate2], 1, 0) and maxTryTimes > 0:
  593. maxTryTimes -= 1
  594. return True
  595. class task_checkAdventure(dongri_task):
  596. def __init__(self):
  597. super().__init__(f"检查冒险")
  598. def run(self):
  599. basic_operate.go_town()
  600. if waitClickImg_noWait_withBool(check_img.adventure, 2, 1) == False:
  601. return False
  602. if waitClickImg_noWait_withBool(check_img.get, 2, 1) == False:
  603. return False
  604. if waitClickImg_noWait_withBool(check_img.bigGet, 2, 1) == False:
  605. return False
  606. return True
  607. class task_waitTime(dongri_task):
  608. def __init__(self):
  609. super().__init__(f"等待时间")
  610. def run(self):
  611. myTimeSleep(300)
  612. class check_buildOrResearch(dongri_task):
  613. def __init__(self):
  614. super().__init__(f"检查建筑或研究")
  615. def run(self):
  616. basic_operate.go_town()
  617. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  618. return False
  619. if waitClickImg_noWait_withBool(check_img.needgo, 2, 1) == False:
  620. return False
  621. dstType = 'none'
  622. while True:
  623. 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):
  624. dstType = 'build'
  625. break
  626. handRet, handPos = waitFindImg(check_img.hand, 2, 1)
  627. if not handRet:
  628. return False
  629. detailRet, detailPos = waitFindImg((check_img.detail,check_img.detail2), 2, 1)
  630. dstPos = [0, 0]
  631. if not detailRet:
  632. # 如果找不到详细信息,兵营之类的,需点中间
  633. dstPos = [handPos[0] - 70, handPos[1] + 120]
  634. else:
  635. dstPos = [detailPos[0] + 70, detailPos[1] - 100]
  636. tryTimes = 5
  637. while tryTimes > 0:
  638. tryTimes -= 1
  639. myTimeSleep_big()
  640. pcacc_mouse.click(dst_x=dstPos[0], dst_y=dstPos[1])
  641. if waitClickImg_noWait_withBool(check_img.research, 2, 1):
  642. dstType = 'research'
  643. break
  644. elif waitClickImg_noWait_withBool(check_img.build_upgrade, 2, 1):
  645. dstType = 'build'
  646. break
  647. break
  648. if dstType == 'none':
  649. print('没有找到建筑或研究')
  650. return False
  651. elif dstType == 'build':
  652. buildtimes = 4
  653. 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]):
  654. buildtimes -= 1
  655. if buildtimes == 0:
  656. break
  657. continue
  658. elif dstType == 'research':
  659. if waitClickImg_withBool([check_img.research_type1, check_img.research_type2], 2, 1) == False:
  660. return False
  661. if basic_operate.enter_auto_supply_resource(check_img.research_done) == False:
  662. return False
  663. waitClickImg_withBool([check_img.help, check_img.help2, check_img.help3], 2, 2)
  664. return True
  665. class task_information(dongri_task):
  666. def __init__(self, isAddStrengh = False):
  667. super().__init__(f"检查情报")
  668. self.isAddStrengh = isAddStrengh
  669. def run(self):
  670. basic_operate.go_outside()
  671. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  672. if self.isAddStrengh:
  673. basic_operate.add_strength()
  674. basic_operate.go_outside()
  675. else:
  676. print("没有足够的体力了")
  677. return False
  678. if waitClickImg_noWait_withBool(information_img.information, 1, 1) == False:
  679. return False
  680. hero_arr = [information_img.hero0, information_img.hero1, information_img.hero2]
  681. camp_arr = [information_img.camp1, information_img.camp2]
  682. wolf_arr = [information_img.wolf0, information_img.wolf1, information_img.wolf2, information_img.wolf3, information_img.wolf4]
  683. total_arr = hero_arr + camp_arr + wolf_arr
  684. if waitFindImg_withBool(total_arr, 2, 1) == False:
  685. return False
  686. if waitClickImg_noWait_withBool(hero_arr, 0.5, 0.5):
  687. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  688. return False
  689. if waitClickImg_noWait_withBool(information_img.explore, 1, 1) == False:
  690. return False
  691. if waitClickImg_noWait_withBool(information_img.hero_fight, 1, 1) == False:
  692. return False
  693. myTimeSleep_big()
  694. return True
  695. elif waitClickImg_noWait_withBool(camp_arr, 0.5, 0.5):
  696. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  697. return False
  698. if waitClickImg_noWait_withBool(information_img.survive, 1, 1) == False:
  699. return False
  700. return True
  701. elif waitClickImg_noWait_withBool(wolf_arr, 0.5, 0.5):
  702. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  703. return False
  704. if waitClickImg_noWait_withBool(information_img.fight, 1, 1) == False:
  705. return False
  706. if waitClickImg_noWait_withBool(monster_img.line1, 1, 1) == False:
  707. return False
  708. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  709. return False
  710. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  711. maxTryTimes = 3
  712. while maxTryTimes > 0:
  713. maxTryTimes -= 1
  714. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  715. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  716. break
  717. return True
  718. else:
  719. return False
  720. class task_returnAllLine(dongri_task):
  721. def __init__(self):
  722. super().__init__(f"返回所有路线")
  723. def run(self):
  724. basic_operate.go_outside()
  725. basic_operate.return_line()
  726. basic_operate.return_line()
  727. basic_operate.return_line()
  728. basic_operate.return_line()
  729. basic_operate.return_line()
  730. basic_operate.return_line()
  731. return True
  732. class task_paticipateInTeam(dongri_task):
  733. def __init__(self):
  734. super().__init__(f"参与队伍")
  735. def run(self):
  736. basic_operate.go_outside()
  737. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  738. return False
  739. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1, True) == False:
  740. yys_dragAuto(check_img.move_down)
  741. myTimeSleep_big()
  742. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1, True) == False:
  743. return False
  744. while True:
  745. if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
  746. break
  747. if waitFindImg_withBool(monster_img.no_hero, 0.1, 0.5) == False:
  748. break
  749. if waitClickImg_noWait_withBool(monster_img.line4, 0.1, 0.5) == False:
  750. break
  751. break
  752. maxTryTimes = 3
  753. while maxTryTimes > 0:
  754. maxTryTimes -= 1
  755. waitClickImg_withBool([monster_img.fight, monster_img.fight2, monster_img.fight3], 1, 0.5)
  756. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 0.5):
  757. break
  758. return True
  759. class task_cure(dongri_task):
  760. def __init__(self, continueCure = False, cureNum = None):
  761. cureStr = ""
  762. if continueCure:
  763. cureStr = "50次连续"
  764. super().__init__(f"{cureStr}治疗{cureNum}")
  765. self.continueCure = continueCure
  766. self.cureNum = cureNum
  767. def run(self):
  768. basic_operate.go_town()
  769. basic_operate.go_outside()
  770. if waitClickImg_noWait_withBool(check_img.soilder_cure, 2, 1) == False:
  771. return False
  772. while waitFindImg_withBool(special_activity_img.done_immediately, 1, 0.5) == False:
  773. if waitClickImg_noWait_withBool(special_activity_img.quick_choose, 1, 0.5) == False:
  774. return False
  775. while waitFindImg_withBool(special_activity_img.done_immediately, 1, 0.5):
  776. if waitClickImg_noWait_withBool(special_activity_img.choose_zero, 1, 0.5) == False:
  777. return False
  778. else:
  779. myTimeSleep_big()
  780. pcacc_mouse.input_string(str(self.cureNum))
  781. if self.continueCure == False:
  782. if waitClickImg_noWait_withBool(check_img.cure, 2, 1) == False:
  783. return False
  784. if waitClickImg_noWait_withBool(check_img.help4, 2, 1) == False:
  785. return False
  786. else:
  787. maxTryTimes = 50 * 2
  788. while waitClickImg_noWait_withBool((check_img.cure, check_img.help4, check_img.help5), 30, 0.2) and maxTryTimes >= 0:
  789. maxTryTimes -= 1
  790. continue
  791. waitClickImg_noWait_withBool((check_img.help4, check_img.help5), 1, 1)
  792. return True
  793. class task_useAnnimalSkill(dongri_task):
  794. def __init__(self):
  795. super().__init__(f"使用动物技能")
  796. def run(self):
  797. basic_operate.go_outside()
  798. if waitClickImg_noWait_withBool(check_img.annimal_skill, 2, 1) == False:
  799. return False
  800. if waitClickImg_noWait_withBool((check_img.wolf_skill, check_img.elephant_skill, check_img.lu_skill), 2, 1) == False:
  801. return False
  802. if waitClickImg_noWait_withBool((check_img.use, check_img.use2), 2, 1) == False:
  803. return False
  804. class task_activity_lianmeng(dongri_task):
  805. def __init__(self):
  806. super().__init__(f"联盟总动员")
  807. def run(self):
  808. basic_operate.go_town()
  809. if waitClickImg_noWait_withBool(special_activity_img.normal, 2, 1) == False:
  810. return False
  811. if waitClickImg_noWait_withBool((special_activity_img.lianmeng,special_activity_img.lianmeng2), 2, 1) == False:
  812. yys_dragAuto(special_activity_img.move_left)
  813. myTimeSleep_big()
  814. yys_dragAuto(special_activity_img.move_left)
  815. myTimeSleep_big()
  816. if waitClickImg_noWait_withBool((special_activity_img.lianmeng,special_activity_img.lianmeng2), 2, 1) == False:
  817. return False
  818. waitClickImg_noWait_withBool(special_activity_img.task_done, 2, 1)
  819. if waitFindImg_withBool(special_activity_img.doing_task, 2, 1) == False:
  820. if waitClickImg_noWait_withBool((special_activity_img.shili_120, special_activity_img.shili_860_2, special_activity_img.bigMonster), 2, 1) == True:
  821. if waitClickImg_noWait_withBool(special_activity_img.accept_task, 2, 1) == False:
  822. return False
  823. if waitFindImg_withBool((special_activity_img.shili_120, special_activity_img.shili_860_2), 2, 1) == False:
  824. maxTryTimes = 2
  825. while waitClickImg_noWait_withBool((special_activity_img.owning), 2, 1) == True:
  826. waitClickImg_noWait_withBool(special_activity_img.refresh_task, 2, 1)
  827. waitClickImg_noWait_withBool(special_activity_img.refresh, 2, 1)
  828. maxTryTimes -= 1
  829. if maxTryTimes <= 0:
  830. break
  831. return True
  832. class task_checkMaster(dongri_task):
  833. def __init__(self):
  834. super().__init__(f"检查统帅")
  835. def run(self):
  836. basic_operate.go_town()
  837. if waitClickImg_noWait_withBool(check_img.master, 2, 1) == False:
  838. return False
  839. if waitClickImg_noWait_withBool(check_img.master_get, 2, 1) == False:
  840. return False
  841. myTimeSleep_big()
  842. pcacc_mouse.quickclick_current()
  843. if waitClickImg_noWait_withBool(check_img.little_treasure, 2, 1) == False:
  844. return False
  845. return True
  846. class task_checkActivities(dongri_task):
  847. def __init__(self):
  848. super().__init__(f"检查各种活动时间")
  849. def find_all_matching_events(self, parts, input_word):
  850. results = []
  851. # 查找所有包含输入关键词的项
  852. matches = [i for i, part in enumerate(parts) if input_word in part]
  853. for match_index in matches:
  854. # 从匹配项开始向后查找第一个时间或状态
  855. for i in range(match_index + 1, len(parts)):
  856. current_part = parts[i]
  857. # 检查是否是时间(如 19:30)或状态(如 已结束)
  858. if re.match(r'^\d{1,2}:\d{2}$', current_part) or current_part in ["已结束"]:
  859. dst = {"item":parts[match_index], "time":current_part}
  860. results.append(dst)
  861. break # 找到第一个匹配就停止
  862. return results
  863. def run(self):
  864. global todo_msg, todo_list
  865. basic_operate.go_outside()
  866. if waitClickImg_noWait_withBool(check_img.activity_open, 2, 1) == False:
  867. return False
  868. if waitFindImg_withBool(check_img.todoList, 2, 1) == False:
  869. return False
  870. activityStr = yys_ocrAuto(check_img.todo_region)
  871. if activityStr:
  872. todo_msg = activityStr
  873. print(todo_msg)
  874. result = []
  875. judianArr = self.find_all_matching_events(activityStr, "据点")
  876. result.extend(judianArr)
  877. baoleiArr = self.find_all_matching_events(activityStr, "堡垒")
  878. result.extend(baoleiArr)
  879. juxiongArr = self.find_all_matching_events(activityStr, "巨熊")
  880. result.extend(juxiongArr)
  881. yaosaiArr = self.find_all_matching_events(activityStr, "要塞")
  882. result.extend(yaosaiArr)
  883. todo_list = result
  884. print(todo_list)
  885. return activityStr
  886. class task_visit_island(dongri_task):
  887. def __init__(self):
  888. super().__init__(f"访问岛屿")
  889. def run(self):
  890. basic_operate.go_outside()
  891. if waitClickImg_noWait_withBool(check_img.visit_island_small, 2, 1) == False:
  892. return False
  893. if waitClickImg_noWait_withBool(check_img.visit_enter, 2, 1) == False:
  894. return False
  895. if waitClickImg_noWait_withBool(check_img.visit_island_big, 2, 1) == False:
  896. return False
  897. return True
  898. class task_fight_ranshuang(dongri_task):
  899. def __init__(self):
  900. super().__init__(f"打燃霜")
  901. def run(self):
  902. basic_operate.backToGame()
  903. while True:
  904. if waitClickImg_noWait_withBool(monster_img.ranshuang_search, 0.5, 0.5) == False:
  905. return False
  906. if waitClickImg_noWait_withBool(monster_img.ranshuang_attack, 0.5, 0.5) == False:
  907. firstPos = get_yys_random_point(special_activity_img.mid_enemy_region)
  908. pcacc_mouse.click(firstPos[0], firstPos[1])
  909. myTimeSleep_big()
  910. if waitClickImg_noWait_withBool(monster_img.ranshuang_attack, 1, 0.5) == False:
  911. break
  912. break
  913. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 1, 0.5) == False:
  914. return False
  915. return True
  916. class task_fight_enemy(dongri_task):
  917. def __init__(self):
  918. super().__init__(f"打敌人or王城")
  919. def run(self):
  920. basic_operate.go_town()
  921. basic_operate.go_outside()
  922. if waitClickImg_noWait_withBool(special_activity_img.collection, 2, 1) == False:
  923. return False
  924. if waitClickImg_noWait_withBool(special_activity_img.enemy, 2, 1) == False:
  925. return False
  926. attackArr = [monster_img.attack, monster_img.attack2, monster_img.ranshuang_attack]
  927. myTimeSleep_big()
  928. firstPos = get_yys_random_point(special_activity_img.first_enemy_region)
  929. pcacc_mouse.click(firstPos[0], firstPos[1])
  930. maxTryTimes = 5
  931. while waitFindImg_withBool(attackArr, 2, 1) == False and maxTryTimes > 0:
  932. maxTryTimes -= 1
  933. myTimeSleep_big()
  934. mid_enemy_pos = get_yys_random_point(special_activity_img.mid_enemy_region)
  935. pcacc_mouse.click(mid_enemy_pos[0], mid_enemy_pos[1])
  936. myTimeSleep_big()
  937. if waitClickImg_noWait_withBool(attackArr, 2, 1) == False:
  938. return False
  939. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  940. return False
  941. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  942. return False
  943. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 2, 1) == False:
  944. return False
  945. return True
  946. class task_get_redPackage(dongri_task):
  947. def __init__(self):
  948. super().__init__(f"领取红包")
  949. def run(self):
  950. basic_operate.go_outside()
  951. if waitClickImg_noWait_withBool((check_img.talk_in,check_img.talk_in2, check_img.talk_in3), 2, 1) == False:
  952. return False
  953. waitClickImg_noWait_withBool(check_img.talkin_person, 2, 1)
  954. oldTime = time.time()
  955. while True:
  956. if time.time() - oldTime > 150:
  957. break
  958. waitClickImg_noWait_withBool((special_activity_img.red_package, special_activity_img.red_package2, special_activity_img.msg_new, special_activity_img.red_package_open), 2, 0)
  959. return True
  960. class task_read_mails(dongri_task):
  961. def __init__(self):
  962. super().__init__(f"读邮件")
  963. def run(self):
  964. basic_operate.go_town()
  965. if waitClickImg_noWait_withBool(check_img.mail_btn, 2, 1) == False:
  966. return False
  967. waitClickImg_noWait_withBool(check_img.mail_collect, 2, 1)
  968. if waitClickImg_noWait_withBool(check_img.mail_union, 2, 1) == False:
  969. return False
  970. if waitClickImg_noWait_withBool(check_img.mail_read, 2, 1) == False:
  971. return False
  972. if waitClickImg_noWait_withBool(check_img.mail_system, 2, 1) == False:
  973. return False
  974. if waitClickImg_noWait_withBool(check_img.mail_read, 2, 1) == False:
  975. return False
  976. if waitClickImg_noWait_withBool(check_img.mail_reports, 2, 1) == False:
  977. return False
  978. if waitClickImg_noWait_withBool(check_img.mail_read, 2, 1) == False:
  979. return False
  980. return True
  981. if __name__ == '__main__':
  982. #task_cure(True, 85).run()
  983. #task_fight_enemy().run()
  984. #task_fight_ranshuang().run()
  985. #task_gotoTree().run()
  986. #task_fight_jina_only().run()
  987. #task_checkConfilits().run()
  988. #task_checkActivities().run()
  989. #task_checkMaster().run()
  990. #basic_operate.get_line_num()
  991. #yys_ocrAuto(check_img.line_orc)
  992. #basic_operate.go_town()
  993. #basic_operate.add_strength()
  994. #task_fightMonster(False, False,False).run()
  995. #task_checkHelp().run()
  996. #task_checkStoreRoom().run()
  997. #task_activity_lianmeng().run()
  998. #task_fight_yongbing(True).run()
  999. #task_collect([4,3,2,1]).run()
  1000. #task_train("upgrade").run()
  1001. #task_information().run()
  1002. #check_buildOrResearch().run()
  1003. #task_checkDonata().run()
  1004. #task_collect(1).run()
  1005. #task_collect(2).run()
  1006. #task_collect(3).run()
  1007. #task_collect(4).run()
  1008. #task_returnAllLine().run()
  1009. #task_paticipateInTeam().run()
  1010. #task_fight_jina(True).run()
  1011. #task_get_redPackage().run()
  1012. task_read_mails().run()