dongri_task.py 40 KB

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