dongri_task.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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. if waitClickImg_noWait_withBool([information_img.hero0, information_img.hero1, information_img.hero2], 0.5, 0.5):
  691. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  692. return False
  693. if waitClickImg_noWait_withBool(information_img.explore, 1, 1) == False:
  694. return False
  695. if waitClickImg_noWait_withBool(information_img.hero_fight, 1, 1) == False:
  696. return False
  697. myTimeSleep_big()
  698. return True
  699. elif waitClickImg_noWait_withBool([information_img.camp1, information_img.camp2], 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.survive, 1, 1) == False:
  703. return False
  704. return True
  705. elif waitClickImg_noWait_withBool([information_img.wolf0, information_img.wolf1, information_img.wolf2], 0.5, 0.5):
  706. if waitClickImg_noWait_withBool(information_img.gotosee, 1, 1) == False:
  707. return False
  708. if waitClickImg_noWait_withBool(information_img.fight, 1, 1) == False:
  709. return False
  710. if waitClickImg_noWait_withBool(monster_img.line1, 1, 1) == False:
  711. return False
  712. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  713. return False
  714. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  715. maxTryTimes = 3
  716. while maxTryTimes > 0:
  717. maxTryTimes -= 1
  718. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  719. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  720. break
  721. return True
  722. else:
  723. return False
  724. class task_returnAllLine(dongri_task):
  725. def __init__(self):
  726. super().__init__(f"返回所有路线")
  727. def run(self):
  728. basic_operate.go_outside()
  729. basic_operate.return_line()
  730. basic_operate.return_line()
  731. basic_operate.return_line()
  732. basic_operate.return_line()
  733. basic_operate.return_line()
  734. basic_operate.return_line()
  735. return True
  736. class task_paticipateInTeam(dongri_task):
  737. def __init__(self):
  738. super().__init__(f"参与队伍")
  739. def run(self):
  740. basic_operate.go_outside()
  741. if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
  742. return False
  743. if waitClickImg_noWait_withBool(monster_img.participate, 1, 1) == False:
  744. return False
  745. while True:
  746. if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
  747. break
  748. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  749. break
  750. if waitClickImg_noWait_withBool(monster_img.line4, 0.1, 1) == False:
  751. break
  752. if waitFindImg_withBool(monster_img.no_hero, 0.1, 1) == False:
  753. break
  754. break
  755. if waitClickImg_noWait_withBool(monster_img.all_select, 2, 1) == False:
  756. return False
  757. waitClickImg_noWait_withBool(monster_img.all_select, 0.1, 1)
  758. maxTryTimes = 3
  759. while maxTryTimes > 0:
  760. maxTryTimes -= 1
  761. waitClickImg_withBool([monster_img.fight, monster_img.fight2], 1, 1)
  762. if False == waitClickImg_noWait_withBool(monster_img.all_select, 1, 1):
  763. break
  764. return True
  765. class task_cure(dongri_task):
  766. def __init__(self, continueCure = False, cureNum = None):
  767. cureStr = ""
  768. if continueCure:
  769. cureStr = "50次连续"
  770. super().__init__(f"{cureStr}治疗{cureNum}")
  771. self.continueCure = continueCure
  772. self.cureNum = cureNum
  773. def run(self):
  774. basic_operate.go_town()
  775. basic_operate.go_outside()
  776. if waitClickImg_noWait_withBool(check_img.soilder_cure, 2, 1) == False:
  777. return False
  778. while waitFindImg_withBool(special_activity_img.done_immediately, 1, 0.5) == False:
  779. if waitClickImg_noWait_withBool(special_activity_img.quick_choose, 1, 0.5) == False:
  780. return False
  781. while waitFindImg_withBool(special_activity_img.done_immediately, 1, 0.5):
  782. if waitClickImg_noWait_withBool(special_activity_img.choose_zero, 1, 0.5) == False:
  783. return False
  784. else:
  785. myTimeSleep_big()
  786. pcacc_mouse.input_string(str(self.cureNum))
  787. if self.continueCure == False:
  788. if waitClickImg_noWait_withBool(check_img.cure, 2, 1) == False:
  789. return False
  790. if waitClickImg_noWait_withBool(check_img.help4, 2, 1) == False:
  791. return False
  792. else:
  793. maxTryTimes = 50 * 2
  794. while waitClickImg_noWait_withBool((check_img.cure, check_img.help4, check_img.help5), 30, 0.2) and maxTryTimes >= 0:
  795. maxTryTimes -= 1
  796. continue
  797. waitClickImg_noWait_withBool((check_img.help4, check_img.help5), 1, 1)
  798. return True
  799. class task_useAnnimalSkill(dongri_task):
  800. def __init__(self):
  801. super().__init__(f"使用动物技能")
  802. def run(self):
  803. basic_operate.go_outside()
  804. if waitClickImg_noWait_withBool(check_img.annimal_skill, 2, 1) == False:
  805. return False
  806. if waitClickImg_noWait_withBool((check_img.wolf_skill, check_img.elephant_skill), 2, 1) == False:
  807. return False
  808. if waitClickImg_noWait_withBool((check_img.use, check_img.use2), 2, 1) == False:
  809. return False
  810. class task_activity_lianmeng(dongri_task):
  811. def __init__(self):
  812. super().__init__(f"联盟总动员")
  813. def run(self):
  814. basic_operate.go_town()
  815. if waitClickImg_noWait_withBool(special_activity_img.normal, 2, 1) == False:
  816. return False
  817. if waitClickImg_noWait_withBool((special_activity_img.lianmeng,special_activity_img.lianmeng2), 2, 1) == False:
  818. return False
  819. waitClickImg_noWait_withBool(special_activity_img.task_done, 2, 1)
  820. if waitFindImg_withBool(special_activity_img.doing_task, 2, 1) == False:
  821. if waitClickImg_noWait_withBool((special_activity_img.shili_120, special_activity_img.shili_860_2, special_activity_img.bigMonster), 2, 1) == True:
  822. if waitClickImg_noWait_withBool(special_activity_img.accept_task, 2, 1) == False:
  823. return False
  824. if waitFindImg_withBool((special_activity_img.shili_120, special_activity_img.shili_860_2), 2, 1) == False:
  825. maxTryTimes = 2
  826. while waitClickImg_noWait_withBool((special_activity_img.owning, special_activity_img.owning_120), 2, 1) == True:
  827. waitClickImg_noWait_withBool(special_activity_img.refresh_task, 2, 1)
  828. waitClickImg_noWait_withBool(special_activity_img.refresh, 2, 1)
  829. maxTryTimes -= 1
  830. if maxTryTimes <= 0:
  831. break
  832. return True
  833. class task_checkMaster(dongri_task):
  834. def __init__(self):
  835. super().__init__(f"检查统帅")
  836. def run(self):
  837. basic_operate.go_town()
  838. if waitClickImg_noWait_withBool(check_img.master, 2, 1) == False:
  839. return False
  840. if waitClickImg_noWait_withBool(check_img.master_get, 2, 1) == False:
  841. return False
  842. myTimeSleep_big()
  843. pcacc_mouse.quickclick_current()
  844. if waitClickImg_noWait_withBool(check_img.little_treasure, 2, 1) == False:
  845. return False
  846. return True
  847. class task_checkActivities(dongri_task):
  848. def __init__(self):
  849. super().__init__(f"检查各种活动时间")
  850. def find_all_matching_events(self, parts, input_word):
  851. results = []
  852. # 查找所有包含输入关键词的项
  853. matches = [i for i, part in enumerate(parts) if input_word in part]
  854. for match_index in matches:
  855. # 从匹配项开始向后查找第一个时间或状态
  856. for i in range(match_index + 1, len(parts)):
  857. current_part = parts[i]
  858. # 检查是否是时间(如 19:30)或状态(如 已结束)
  859. if re.match(r'^\d{1,2}:\d{2}$', current_part) or current_part in ["已结束"]:
  860. dst = {"item":parts[match_index], "time":current_part}
  861. results.append(dst)
  862. break # 找到第一个匹配就停止
  863. return results
  864. def run(self):
  865. global todo_msg, todo_list
  866. basic_operate.go_outside()
  867. if waitClickImg_noWait_withBool(check_img.activity_open, 2, 1) == False:
  868. return False
  869. if waitFindImg_withBool(check_img.todoList, 2, 1) == False:
  870. return False
  871. activityStr = yys_ocrAuto(check_img.todo_region)
  872. if activityStr:
  873. todo_msg = activityStr
  874. print(todo_msg)
  875. result = []
  876. judianArr = self.find_all_matching_events(activityStr, "据点")
  877. result.extend(judianArr)
  878. baoleiArr = self.find_all_matching_events(activityStr, "堡垒")
  879. result.extend(baoleiArr)
  880. juxiongArr = self.find_all_matching_events(activityStr, "巨熊")
  881. result.extend(juxiongArr)
  882. yaosaiArr = self.find_all_matching_events(activityStr, "要塞")
  883. result.extend(yaosaiArr)
  884. todo_list = result
  885. print(todo_list)
  886. return activityStr
  887. class task_visit_island(dongri_task):
  888. def __init__(self):
  889. super().__init__(f"访问岛屿")
  890. def run(self):
  891. basic_operate.go_outside()
  892. if waitClickImg_noWait_withBool(check_img.visit_island_small, 2, 1) == False:
  893. return False
  894. if waitClickImg_noWait_withBool(check_img.visit_enter, 2, 1) == False:
  895. return False
  896. if waitClickImg_noWait_withBool(check_img.visit_island_big, 2, 1) == False:
  897. return False
  898. return True
  899. class task_fight_ranshuang(dongri_task):
  900. def __init__(self):
  901. super().__init__(f"打燃霜")
  902. def run(self):
  903. basic_operate.backToGame()
  904. maxTime = 4
  905. while waitClickImg_noWait_withBool([monster_img.ranshuang_attack, monster_img.ranshuang_search], 1, 1) and maxTime > 0:
  906. maxTime -= 1
  907. continue
  908. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 1, 1) == False:
  909. return False
  910. return True
  911. class task_fight_enemy(dongri_task):
  912. def __init__(self):
  913. super().__init__(f"打敌人or王城")
  914. def run(self):
  915. basic_operate.go_town()
  916. basic_operate.go_outside()
  917. if waitClickImg_noWait_withBool(special_activity_img.collection, 2, 1) == False:
  918. return False
  919. if waitClickImg_noWait_withBool(special_activity_img.enemy, 2, 1) == False:
  920. return False
  921. attackArr = [monster_img.attack, monster_img.attack2, monster_img.ranshuang_attack]
  922. myTimeSleep_big()
  923. firstPos = get_yys_random_point(special_activity_img.first_enemy_region)
  924. pcacc_mouse.click(firstPos[0], firstPos[1])
  925. maxTryTimes = 5
  926. while waitFindImg_withBool(attackArr, 2, 1) == False and maxTryTimes > 0:
  927. maxTryTimes -= 1
  928. myTimeSleep_big()
  929. mid_enemy_pos = get_yys_random_point(special_activity_img.mid_enemy_region)
  930. pcacc_mouse.click(mid_enemy_pos[0], mid_enemy_pos[1])
  931. myTimeSleep_big()
  932. if waitClickImg_noWait_withBool(attackArr, 2, 1) == False:
  933. return False
  934. if waitClickImg_noWait_withBool(monster_img.line1, 2, 1) == False:
  935. return False
  936. if waitFindImg_withBool(monster_img.no_hero, 2, 1) == True:
  937. return False
  938. if waitClickImg_noWait_withBool([monster_img.fight, monster_img.fight2], 2, 1) == False:
  939. return False
  940. return True
  941. if __name__ == '__main__':
  942. #task_cure(True, 85).run()
  943. task_fight_enemy().run()
  944. #task_fight_ranshuang().run()
  945. #task_gotoTree().run()
  946. #task_fight_jina_only().run()
  947. #task_checkConfilits().run()
  948. #task_checkActivities().run()
  949. #task_checkMaster().run()
  950. #basic_operate.get_line_num()
  951. #yys_ocrAuto(check_img.line_orc)
  952. #basic_operate.go_town()
  953. #basic_operate.add_strength()
  954. #task_fightMonster(False, False,False).run()
  955. #task_checkHelp().run()
  956. #task_checkStoreRoom().run()
  957. #task_activity_lianmeng().run()
  958. #task_fight_yongbing(True).run()
  959. #task_collect([4,3,2,1]).run()
  960. #task_train("upgrade").run()
  961. #task_information().run()
  962. #check_buildOrResearch().run()
  963. #task_checkDonata().run()
  964. #task_collect(1).run()
  965. #task_collect(2).run()
  966. #task_collect(3).run()
  967. #task_collect(4).run()
  968. #task_returnAllLine().run()
  969. #task_paticipateInTeam().run()
  970. #task_fight_jina(True).run()