dongri_task.py 38 KB

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