dongri_task.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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. class task_fight_enemy(dongri_task):
  876. def __init__(self):
  877. super().__init__(f"打敌人or王城")
  878. def run(self):
  879. basic_operate.go_town()
  880. basic_operate.go_outside()
  881. if waitClickImg_noWait_withBool(special_activity_img.collection, 2, 1) == False:
  882. return False
  883. if waitClickImg_noWait_withBool(special_activity_img.enemy, 2, 1) == False:
  884. return False
  885. myTimeSleep_big()
  886. firstPos = get_yys_random_point(special_activity_img.first_enemy_region)
  887. pcacc_mouse.click(firstPos[0], firstPos[1])
  888. myTimeSleep_big()
  889. mid_enemy_pos = get_yys_random_point(special_activity_img.mid_enemy_region)
  890. pcacc_mouse.click(mid_enemy_pos[0], mid_enemy_pos[1])
  891. myTimeSleep_big()
  892. if waitClickImg_noWait_withBool([monster_img.attack, monster_img.attack2, monster_img.ranshuang_attack], 2, 1) == False:
  893. return False
  894. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  895. return False
  896. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  897. return False
  898. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 2, 1) == False:
  899. return False
  900. return True
  901. if __name__ == '__main__':
  902. task_fight_enemy().run()
  903. #task_fight_ranshuang().run()
  904. #task_gotoTree().run()
  905. #task_fight_jina_only().run()
  906. #task_checkConfilits().run()
  907. #task_checkActivities().run()
  908. #task_checkMaster().run()
  909. #basic_operate.get_line_num()
  910. #yys_ocrAuto(check_img.line_orc)
  911. #basic_operate.go_town()
  912. #basic_operate.add_strength()
  913. #task_fightMonster(False, False,False).run()
  914. #task_checkHelp().run()
  915. #task_checkStoreRoom().run()
  916. #task_activity_lianmeng().run()
  917. #task_fight_yongbing(True).run()
  918. #task_collect([4,3,2,1]).run()
  919. #task_train("lv9").run()
  920. #task_information().run()
  921. #check_buildOrResearch().run()
  922. #task_checkDonata().run()
  923. #task_collect(1).run()
  924. #task_collect(2).run()
  925. #task_collect(3).run()
  926. #task_collect(4).run()
  927. #task_returnAllLine().run()
  928. #task_paticipateInTeam().run()
  929. #task_fight_jina(True).run()