dongri_task.py 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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 self.isSimple:
  357. maxLineNum = 4
  358. else:
  359. maxLineNum = 6
  360. if basic_operate.get_line_num() >= maxLineNum:
  361. return False
  362. if False == basic_operate.click_outside_search():
  363. return False
  364. if waitFindImg_withBool(monster_img.search, 2, 1):
  365. myTimeSleep_big()
  366. yys_dragAuto(monster_img.move_left)
  367. if waitClickImg_noWait_withBool(self.monster, 2, 1) == False:
  368. return False
  369. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  370. return False
  371. if waitClickImg_noWait_withBool(self.attack, 2, 1) == False:
  372. return False
  373. waitClickImg_noWait_withBool(monster_img.begin_multi, 2, 1)
  374. if not self.isSimple:
  375. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  376. return False
  377. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  378. return False
  379. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  380. return False
  381. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  382. maxTryTimes = 3
  383. while maxTryTimes > 0:
  384. maxTryTimes -= 1
  385. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  386. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  387. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  388. break
  389. return True
  390. class task_collect(dongri_task):
  391. def __init__(self, type = 0, isSimple = False, isAddStrenghth = False):
  392. self.isSimple = isSimple
  393. self.isAddStrenghth = isAddStrenghth
  394. if isinstance(type, (list, tuple)):
  395. typeArr = type
  396. type = typeArr[random.randint(0, len(typeArr) - 1)]
  397. elif type == 0:
  398. typeArr = [4,4,3,3,3,2,2,2,1,1]
  399. type = typeArr[random.randint(0, len(typeArr) - 1)]
  400. elif type == 5:
  401. typeArr = [2,1]
  402. type = typeArr[random.randint(0, len(typeArr) - 1)]
  403. if type == 1:
  404. self.type = monster_img.meat
  405. self.line = monster_img.line2
  406. super().__init__(f"采集肉")
  407. elif type == 2:
  408. self.type = monster_img.wood
  409. self.line = monster_img.line3
  410. super().__init__(f"采集木头")
  411. elif type == 3:
  412. self.type = monster_img.mine
  413. self.line = monster_img.line4
  414. super().__init__(f"采矿石")
  415. elif type == 4:
  416. self.type = monster_img.iron
  417. self.line = monster_img.line5
  418. super().__init__(f"采集铁矿石")
  419. else:
  420. self.type = None
  421. self.line = None
  422. super().__init__(f"采集None")
  423. if isSimple:
  424. self.line = None
  425. def run(self):
  426. global g_task_lineCheck
  427. if self.type == None:
  428. return True
  429. basic_operate.go_outside()
  430. maxLineNum = 6
  431. if self.isSimple:
  432. if self.isAddStrenghth or g_task_lineCheck:
  433. maxLineNum = 3
  434. else:
  435. maxLineNum = 4
  436. else:
  437. if self.isAddStrenghth or g_task_lineCheck:
  438. maxLineNum = 5
  439. else:
  440. maxLineNum = 6
  441. if basic_operate.get_line_num() >= maxLineNum:
  442. return False
  443. if False == basic_operate.click_outside_search():
  444. return False
  445. if waitFindImg_withBool(monster_img.search, 2, 1):
  446. myTimeSleep_big()
  447. yys_dragAuto(monster_img.move_right)
  448. if waitClickImg_noWait_withBool(self.type, 2, 1) == False:
  449. return False
  450. if waitClickImg_noWait_withBool(monster_img.search, 2, 1) == False:
  451. return False
  452. if waitClickImg_withBool(monster_img.collect, 2, 1) == False:
  453. return False
  454. if self.line != None:
  455. waitClickImg_noWait_withBool(self.line, 2, 1)
  456. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  457. return False
  458. waitClickImg_noWait_withBool(monster_img.all_select, 2, 1)
  459. maxTryTimes = 3
  460. while maxTryTimes > 0:
  461. maxTryTimes -= 1
  462. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  463. waitClickImg_noWait_withBool(monster_img.all_select, 1, 1)
  464. if waitFindImg_withBool(monster_img.all_select, 1, 1) == False:
  465. break
  466. return True
  467. class task_train(dongri_task):
  468. def __init__(self, train_type = None):
  469. super().__init__(f"检查训练{train_type}")
  470. self.train_type = train_type
  471. def run(self):
  472. basic_operate.go_town()
  473. if self.train_type == 'None':
  474. return True
  475. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  476. return False
  477. if waitClickImg_noWait_withBool(train_img.train_success, 2, 1) == False:
  478. return False
  479. tryTimes = 3
  480. isSuccess = False
  481. while tryTimes > 0:
  482. tryTimes -= 1
  483. waitClickImg_noWait_withBool([train_img.dun, train_img.gong, train_img.mao], 2, 1)
  484. if waitClickImg_noWait_withBool(train_img.train, 2, 1):
  485. isSuccess = True
  486. break
  487. if isSuccess == False:
  488. pcacc_mouse.quickclick_current()
  489. myTimeSleep_big()
  490. pcacc_mouse.quickclick_current()
  491. if waitClickImg_noWait_withBool(train_img.train, 2, 1) == False:
  492. return False
  493. if self.train_type == 'lv1':
  494. myTimeSleep_big()
  495. yys_dragAuto(train_img.move_left)
  496. yys_dragAuto(train_img.move_left)
  497. waitClickImg_noWait_withBool(train_img.soilder_lv1, 2, 1)
  498. elif self.train_type == 'lv8':
  499. waitClickImg_noWait_withBool(train_img.soilder_lv8, 2, 1)
  500. elif self.train_type == 'lv9':
  501. waitClickImg_noWait_withBool(train_img.soilder_lv9, 2, 1)
  502. elif self.train_type == 'upgrade':
  503. waitClickImg_noWait_withBool(train_img.upgrade_small, 2, 1)
  504. waitClickImg_noWait_withBool(train_img.upgrade_big, 2, 1)
  505. return basic_operate.enter_auto_supply_resource([train_img.begin_train,train_img.begin_train2])
  506. class task_checkHelp(dongri_task):
  507. def __init__(self, isOutSide = False):
  508. super().__init__(f"检查帮助")
  509. self.isOutSide = isOutSide
  510. def run(self):
  511. if self.isOutSide:
  512. basic_operate.go_outside()
  513. else:
  514. basic_operate.go_town()
  515. waitClickImg_noWait_withBool(place_img.help, 2, 1)
  516. return True
  517. class task_gotoTree(dongri_task):
  518. def __init__(self):
  519. super().__init__(f"查看生命之树")
  520. def run(self):
  521. basic_operate.go_town()
  522. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  523. return False
  524. myTimeSleep_big()
  525. yys_dragAuto(check_img.move_down)
  526. yys_dragAuto(check_img.move_down)
  527. myTimeSleep_big()
  528. if waitClickImg_noWait_withBool(check_img.life_tree, 2, 1) == False:
  529. return False
  530. myTimeSleep_big()
  531. pcacc_mouse.quickclick_current()
  532. myTimeSleep_big()
  533. waitClickImg_noWait_withBool(check_img.life_jam, 2, 1)
  534. waitClickImg_noWait_withBool(check_img.life_jam, 2, 1)
  535. return True
  536. class task_checkStoreRoom(dongri_task):
  537. def __init__(self):
  538. super().__init__(f"检查仓库或招募")
  539. def run(self):
  540. basic_operate.go_town()
  541. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  542. return False
  543. myTimeSleep_big()
  544. yys_dragAuto(check_img.move_down)
  545. yys_dragAuto(check_img.move_down)
  546. myTimeSleep_big()
  547. if waitClickImg_noWait_withBool((train_img.train_success, check_img.needgo), 2, 1) == False:
  548. return False
  549. myTimeSleep_big()
  550. if waitFindImg_withBool(check_img.pet_findtreature, 2, 1) == False:
  551. waitClickImg_noWait_withBool(check_img.bigGet, 2, 1)
  552. pcacc_mouse.quickclick_current()
  553. myTimeSleep_big()
  554. if waitClickImg_noWait_withBool((check_img.detail,check_img.detail2), 2, 1):
  555. myTimeSleep_big()
  556. basic_operate.go_town()
  557. myTimeSleep_big()
  558. if waitClickImg_noWait_withBool((check_img.storeroom, check_img.storeroom2, check_img.invite_free), 2, 1) == False:
  559. return False
  560. myTimeSleep_big()
  561. pcacc_mouse.quickclick_current()
  562. myTimeSleep_big()
  563. waitClickImg_noWait_withBool(check_img.store_strength, 2, 1)
  564. waitClickImg_noWait_withBool((check_img.get,check_img.bigGet), 2, 1)
  565. else:
  566. if waitClickImg_noWait_withBool(check_img.pet_success, 2, 1):
  567. myTimeSleep_big()
  568. dstPos = get_yys_random_point(check_img.pet_getRegion)
  569. pcacc_mouse.click(dstPos[0], dstPos[1])
  570. myTimeSleep_big()
  571. elif waitClickImg_noWait_withBool((check_img.pet_advance, check_img.pet_senior, check_img.pet_junior), 2, 1):
  572. waitClickImg_noWait_withBool(check_img.pet_gotreature, 2, 1)
  573. waitClickImg_noWait_withBool(check_img.pet_begintreature, 2, 1)
  574. return True
  575. class task_checkConfilits(dongri_task):
  576. def __init__(self):
  577. super().__init__(f"检查集结")
  578. def run(self):
  579. basic_operate.go_outside()
  580. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  581. return False
  582. if waitClickImg_noWait_withBool(check_img.paticipate, 2, 1) == False:
  583. return False
  584. if waitClickImg_noWait_withBool(check_img.auto_confilit, 2, 1) == False:
  585. return False
  586. return True
  587. class task_checkDonata(dongri_task):
  588. def __init__(self):
  589. super().__init__(f"检查捐献")
  590. def run(self):
  591. basic_operate.go_town()
  592. if waitClickImg_noWait_withBool(check_img.union, 2, 1) == False:
  593. return False
  594. if waitClickImg_noWait_withBool(check_img.union_technology, 2, 1) == False:
  595. return False
  596. if waitClickImg_noWait_withBool(check_img.technology_better, 2, 1) == False:
  597. return False
  598. if waitClickImg_withBool([check_img.donate, check_img.donate2], 2, 1) == False:
  599. return False
  600. else:
  601. maxTryTimes = 3
  602. while waitClickImg_withBool([check_img.donate, check_img.donate2], 1, 0) and maxTryTimes > 0:
  603. maxTryTimes -= 1
  604. return True
  605. class task_checkAdventure(dongri_task):
  606. def __init__(self):
  607. super().__init__(f"检查冒险")
  608. def run(self):
  609. basic_operate.go_town()
  610. if waitClickImg_noWait_withBool(check_img.adventure, 2, 1) == False:
  611. return False
  612. if waitClickImg_noWait_withBool(check_img.get, 2, 1) == False:
  613. return False
  614. if waitClickImg_noWait_withBool(check_img.bigGet, 2, 1) == False:
  615. return False
  616. return True
  617. class task_waitTime(dongri_task):
  618. def __init__(self):
  619. super().__init__(f"等待时间")
  620. def run(self):
  621. myTimeSleep(300)
  622. class check_buildOrResearch(dongri_task):
  623. def __init__(self):
  624. super().__init__(f"检查建筑或研究")
  625. def run(self):
  626. basic_operate.go_town()
  627. if waitClickImg_noWait_withBool(train_img.quick_panel, 2, 1) == False:
  628. return False
  629. if waitClickImg_noWait_withBool(check_img.needgo, 2, 1) == False:
  630. return False
  631. dstType = 'none'
  632. while True:
  633. 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):
  634. dstType = 'build'
  635. break
  636. handRet, handPos = waitFindImg(check_img.hand, 2, 1)
  637. if not handRet:
  638. return False
  639. detailRet, detailPos = waitFindImg((check_img.detail,check_img.detail2), 2, 1)
  640. dstPos = [0, 0]
  641. if not detailRet:
  642. # 如果找不到详细信息,兵营之类的,需点中间
  643. dstPos = [handPos[0] - 70, handPos[1] + 120]
  644. else:
  645. dstPos = [detailPos[0] + 70, detailPos[1] - 100]
  646. tryTimes = 5
  647. while tryTimes > 0:
  648. tryTimes -= 1
  649. myTimeSleep_big()
  650. pcacc_mouse.click(dst_x=dstPos[0], dst_y=dstPos[1])
  651. if waitClickImg_noWait_withBool(check_img.research, 2, 1):
  652. dstType = 'research'
  653. break
  654. elif waitClickImg_noWait_withBool(check_img.build_upgrade, 2, 1):
  655. dstType = 'build'
  656. break
  657. break
  658. if dstType == 'none':
  659. print('没有找到建筑或研究')
  660. return False
  661. elif dstType == 'build':
  662. buildtimes = 4
  663. 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]):
  664. buildtimes -= 1
  665. if buildtimes == 0:
  666. break
  667. continue
  668. elif dstType == 'research':
  669. if waitClickImg_withBool([check_img.research_type1, check_img.research_type2], 2, 1) == False:
  670. return False
  671. if basic_operate.enter_auto_supply_resource(check_img.research_done) == False:
  672. return False
  673. waitClickImg_withBool([check_img.help, check_img.help2, check_img.help3], 2, 2)
  674. return True
  675. class task_information(dongri_task):
  676. def __init__(self, isAddStrengh = False):
  677. super().__init__(f"检查情报")
  678. self.isAddStrengh = isAddStrengh
  679. def run(self):
  680. basic_operate.go_outside()
  681. if False == waitFindImg_withBool(monster_img.enough_strengh, 2, 1):
  682. if self.isAddStrengh:
  683. basic_operate.add_strength()
  684. basic_operate.go_outside()
  685. else:
  686. print("没有足够的体力了")
  687. return False
  688. if waitClickImg_noWait_withBool(information_img.information, 1, 1) == False:
  689. return False
  690. hero_arr = [information_img.hero0, information_img.hero1, information_img.hero2]
  691. camp_arr = [information_img.camp1, information_img.camp2]
  692. wolf_arr = [information_img.wolf0, information_img.wolf1, information_img.wolf2]
  693. total_arr = []
  694. total_arr.append(hero_arr)
  695. total_arr.append(camp_arr)
  696. total_arr.append(wolf_arr)
  697. if waitFindImg_withBool(total_arr, 2, 1) == False:
  698. return False
  699. if waitClickImg_noWait_withBool(hero_arr, 0.5, 0.5):
  700. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  701. return False
  702. if waitClickImg_noWait_withBool(information_img.explore, 1, 1) == False:
  703. return False
  704. if waitClickImg_noWait_withBool(information_img.hero_fight, 1, 1) == False:
  705. return False
  706. myTimeSleep_big()
  707. return True
  708. elif waitClickImg_noWait_withBool(camp_arr, 0.5, 0.5):
  709. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  710. return False
  711. if waitClickImg_noWait_withBool(information_img.survive, 1, 1) == False:
  712. return False
  713. return True
  714. elif waitClickImg_noWait_withBool(wolf_arr, 0.5, 0.5):
  715. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  716. return False
  717. if waitClickImg_noWait_withBool(information_img.fight, 1, 1) == False:
  718. return False
  719. if waitClickImg_noWait_withBool(monster_img.line1, 1, 1) == False:
  720. return False
  721. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  722. return False
  723. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  724. maxTryTimes = 3
  725. while maxTryTimes > 0:
  726. maxTryTimes -= 1
  727. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  728. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  729. break
  730. return True
  731. else:
  732. return False
  733. class task_returnAllLine(dongri_task):
  734. def __init__(self):
  735. super().__init__(f"返回所有路线")
  736. def run(self):
  737. basic_operate.go_outside()
  738. basic_operate.return_line()
  739. basic_operate.return_line()
  740. basic_operate.return_line()
  741. basic_operate.return_line()
  742. basic_operate.return_line()
  743. basic_operate.return_line()
  744. return True
  745. class task_paticipateInTeam(dongri_task):
  746. def __init__(self):
  747. super().__init__(f"参与队伍")
  748. def run(self):
  749. basic_operate.go_outside()
  750. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  751. return False
  752. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1) == False:
  753. return False
  754. while True:
  755. if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
  756. break
  757. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  758. break
  759. if waitClickImg_noWait_withBool(monster_img.line4, 0.1, 1) == False:
  760. break
  761. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  762. break
  763. break
  764. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  765. return False
  766. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  767. maxTryTimes = 3
  768. while maxTryTimes > 0:
  769. maxTryTimes -= 1
  770. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  771. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  772. break
  773. return True
  774. class task_cure(dongri_task):
  775. def __init__(self, continueCure = False, cureNum = None):
  776. cureStr = ""
  777. if continueCure:
  778. cureStr = "50次连续"
  779. super().__init__(f"{cureStr}治疗{cureNum}")
  780. self.continueCure = continueCure
  781. self.cureNum = cureNum
  782. def run(self):
  783. basic_operate.go_town()
  784. basic_operate.go_outside()
  785. if waitClickImg_noWait_withBool(check_img.soilder_cure, 2, 1) == False:
  786. return False
  787. while waitFindImg_withBool(special_activity_img.done_immediately, 1, 0.5) == False:
  788. if waitClickImg_noWait_withBool(special_activity_img.quick_choose, 1, 0.5) == False:
  789. return False
  790. while waitFindImg_withBool(special_activity_img.done_immediately, 1, 0.5):
  791. if waitClickImg_noWait_withBool(special_activity_img.choose_zero, 1, 0.5) == False:
  792. return False
  793. else:
  794. myTimeSleep_big()
  795. pcacc_mouse.input_string(str(self.cureNum))
  796. if self.continueCure == False:
  797. if waitClickImg_noWait_withBool(check_img.cure, 2, 1) == False:
  798. return False
  799. if waitClickImg_noWait_withBool(check_img.help4, 2, 1) == False:
  800. return False
  801. else:
  802. maxTryTimes = 50 * 2
  803. while waitClickImg_noWait_withBool((check_img.cure, check_img.help4), 30, 0.2) and maxTryTimes >= 0:
  804. maxTryTimes -= 1
  805. continue
  806. waitClickImg_noWait_withBool(check_img.help4, 1, 1)
  807. return True
  808. class task_useAnnimalSkill(dongri_task):
  809. def __init__(self):
  810. super().__init__(f"使用动物技能")
  811. def run(self):
  812. basic_operate.go_outside()
  813. if waitClickImg_noWait_withBool(check_img.annimal_skill, 2, 1) == False:
  814. return False
  815. if waitClickImg_noWait_withBool((check_img.wolf_skill, check_img.elephant_skill), 2, 1) == False:
  816. return False
  817. if waitClickImg_noWait_withBool((check_img.use, check_img.use2), 2, 1) == False:
  818. return False
  819. class task_activity_lianmeng(dongri_task):
  820. def __init__(self):
  821. super().__init__(f"联盟总动员")
  822. def run(self):
  823. basic_operate.go_town()
  824. if waitClickImg_noWait_withBool(special_activity_img.normal, 2, 1) == False:
  825. return False
  826. if waitClickImg_noWait_withBool((special_activity_img.lianmeng,special_activity_img.lianmeng2), 2, 1) == False:
  827. return False
  828. waitClickImg_noWait_withBool(special_activity_img.task_done, 2, 1)
  829. if waitFindImg_withBool(special_activity_img.doing_task, 2, 1) == False:
  830. if waitClickImg_noWait_withBool((special_activity_img.shili_120, special_activity_img.shili_860_3, special_activity_img.bigMonster), 2, 1) == True:
  831. if waitClickImg_noWait_withBool(special_activity_img.accept_task, 2, 1) == False:
  832. return False
  833. if waitFindImg_withBool((special_activity_img.shili_120, special_activity_img.shili_860_3), 2, 1) == False:
  834. maxTryTimes = 2
  835. while waitClickImg_noWait_withBool((special_activity_img.owning), 2, 1) == True:
  836. waitClickImg_noWait_withBool(special_activity_img.refresh_task, 2, 1)
  837. waitClickImg_noWait_withBool(special_activity_img.refresh, 2, 1)
  838. maxTryTimes -= 1
  839. if maxTryTimes <= 0:
  840. break
  841. return True
  842. class task_checkMaster(dongri_task):
  843. def __init__(self):
  844. super().__init__(f"检查统帅")
  845. def run(self):
  846. basic_operate.go_town()
  847. if waitClickImg_noWait_withBool(check_img.master, 2, 1) == False:
  848. return False
  849. if waitClickImg_noWait_withBool(check_img.master_get, 2, 1) == False:
  850. return False
  851. myTimeSleep_big()
  852. pcacc_mouse.quickclick_current()
  853. if waitClickImg_noWait_withBool(check_img.little_treasure, 2, 1) == False:
  854. return False
  855. return True
  856. class task_checkActivities(dongri_task):
  857. def __init__(self):
  858. super().__init__(f"检查各种活动时间")
  859. def find_all_matching_events(self, parts, input_word):
  860. results = []
  861. # 查找所有包含输入关键词的项
  862. matches = [i for i, part in enumerate(parts) if input_word in part]
  863. for match_index in matches:
  864. # 从匹配项开始向后查找第一个时间或状态
  865. for i in range(match_index + 1, len(parts)):
  866. current_part = parts[i]
  867. # 检查是否是时间(如 19:30)或状态(如 已结束)
  868. if re.match(r'^\d{1,2}:\d{2}$', current_part) or current_part in ["已结束"]:
  869. dst = {"item":parts[match_index], "time":current_part}
  870. results.append(dst)
  871. break # 找到第一个匹配就停止
  872. return results
  873. def run(self):
  874. global todo_msg, todo_list
  875. basic_operate.go_outside()
  876. if waitClickImg_noWait_withBool(check_img.activity_open, 2, 1) == False:
  877. return False
  878. if waitFindImg_withBool(check_img.todoList, 2, 1) == False:
  879. return False
  880. activityStr = yys_ocrAuto(check_img.todo_region)
  881. if activityStr:
  882. todo_msg = activityStr
  883. print(todo_msg)
  884. result = []
  885. judianArr = self.find_all_matching_events(activityStr, "据点")
  886. result.extend(judianArr)
  887. baoleiArr = self.find_all_matching_events(activityStr, "堡垒")
  888. result.extend(baoleiArr)
  889. juxiongArr = self.find_all_matching_events(activityStr, "巨熊")
  890. result.extend(juxiongArr)
  891. yaosaiArr = self.find_all_matching_events(activityStr, "要塞")
  892. result.extend(yaosaiArr)
  893. todo_list = result
  894. print(todo_list)
  895. return activityStr
  896. class task_visit_island(dongri_task):
  897. def __init__(self):
  898. super().__init__(f"访问岛屿")
  899. def run(self):
  900. basic_operate.go_outside()
  901. if waitClickImg_noWait_withBool(check_img.visit_island_small, 2, 1) == False:
  902. return False
  903. if waitClickImg_noWait_withBool(check_img.visit_enter, 2, 1) == False:
  904. return False
  905. if waitClickImg_noWait_withBool(check_img.visit_island_big, 2, 1) == False:
  906. return False
  907. return True
  908. class task_fight_ranshuang(dongri_task):
  909. def __init__(self):
  910. super().__init__(f"打燃霜")
  911. def run(self):
  912. basic_operate.backToGame()
  913. maxTime = 4
  914. while waitClickImg_noWait_withBool([monster_img.ranshuang_attack, monster_img.ranshuang_search], 1, 1) and maxTime > 0:
  915. maxTime -= 1
  916. continue
  917. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 1, 1) == False:
  918. return False
  919. return True
  920. class task_fight_enemy(dongri_task):
  921. def __init__(self):
  922. super().__init__(f"打敌人or王城")
  923. def run(self):
  924. basic_operate.go_town()
  925. basic_operate.go_outside()
  926. if waitClickImg_noWait_withBool(special_activity_img.collection, 2, 1) == False:
  927. return False
  928. if waitClickImg_noWait_withBool(special_activity_img.enemy, 2, 1) == False:
  929. return False
  930. attackArr = [monster_img.attack, monster_img.attack2, monster_img.ranshuang_attack]
  931. myTimeSleep_big()
  932. firstPos = get_yys_random_point(special_activity_img.first_enemy_region)
  933. pcacc_mouse.click(firstPos[0], firstPos[1])
  934. maxTryTimes = 5
  935. while waitFindImg_withBool(attackArr, 2, 1) == False and maxTryTimes > 0:
  936. maxTryTimes -= 1
  937. myTimeSleep_big()
  938. mid_enemy_pos = get_yys_random_point(special_activity_img.mid_enemy_region)
  939. pcacc_mouse.click(mid_enemy_pos[0], mid_enemy_pos[1])
  940. myTimeSleep_big()
  941. if waitClickImg_noWait_withBool(attackArr, 2, 1) == False:
  942. return False
  943. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  944. return False
  945. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  946. return False
  947. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 2, 1) == False:
  948. return False
  949. return True
  950. if __name__ == '__main__':
  951. #task_cure(True, 85).run()
  952. #task_fight_enemy().run()
  953. #task_fight_ranshuang().run()
  954. #task_gotoTree().run()
  955. #task_fight_jina_only().run()
  956. #task_checkConfilits().run()
  957. #task_checkActivities().run()
  958. #task_checkMaster().run()
  959. #basic_operate.get_line_num()
  960. #yys_ocrAuto(check_img.line_orc)
  961. #basic_operate.go_town()
  962. #basic_operate.add_strength()
  963. #task_fightMonster(False, False,False).run()
  964. #task_checkHelp().run()
  965. #task_checkStoreRoom().run()
  966. task_activity_lianmeng().run()
  967. #task_fight_yongbing(True).run()
  968. #task_collect([4,3,2,1]).run()
  969. #task_train("upgrade").run()
  970. #task_information().run()
  971. #check_buildOrResearch().run()
  972. #task_checkDonata().run()
  973. #task_collect(1).run()
  974. #task_collect(2).run()
  975. #task_collect(3).run()
  976. #task_collect(4).run()
  977. #task_returnAllLine().run()
  978. #task_paticipateInTeam().run()
  979. #task_fight_jina(True).run()