dongri_task.py 38 KB

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