script_task.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import time
  5. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  6. from tasks.Exploration.assets import ExplorationAssets
  7. from tasks.Exploration.config import ChooseRarity, AutoRotate, AttackNumber
  8. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  9. from tasks.GameUi.game_ui import GameUi
  10. from tasks.GameUi.page import page_exploration, page_shikigami_records, page_main
  11. from module.logger import logger
  12. from module.exception import RequestHumanTakeover
  13. from module.atom.image_grid import ImageGrid
  14. class ScriptTask(GeneralBattle, GameUi, SwitchSoul, ExplorationAssets):
  15. medal_grid: ImageGrid = None
  16. def run(self):
  17. """
  18. 执行
  19. :return:
  20. """
  21. # 探索的 config
  22. explorationConfig = self.config.exploration
  23. # 切换御魂
  24. if explorationConfig.switch_soul_config.enable:
  25. self.ui_get_current_page()
  26. self.ui_goto(page_shikigami_records)
  27. self.run_switch_soul(explorationConfig.switch_soul_config.switch_group_team)
  28. if explorationConfig.switch_soul_config.enable_switch_by_name:
  29. self.ui_get_current_page()
  30. self.ui_goto(page_shikigami_records)
  31. self.run_switch_soul_by_name(explorationConfig.switch_soul_config.group_name,
  32. explorationConfig.switch_soul_config.team_name)
  33. # 开启加成
  34. con = self.config.exploration.exploration_config
  35. if con.buff_gold_50_click or con.buff_gold_100_click:
  36. self.ui_get_current_page()
  37. self.ui_goto(page_main)
  38. self.open_buff()
  39. if con.buff_gold_50_click:
  40. self.gold_50()
  41. if con.buff_gold_100_click:
  42. self.gold_100()
  43. self.close_buff()
  44. self.ui_get_current_page()
  45. # 探索页面
  46. self.ui_goto(page_exploration)
  47. # ************************* 跳转至对应指定章节并进入 *******************
  48. # 默认全部解锁, 当前处于第二十八章
  49. # 查找指定的章节:
  50. if not self.open_expect_level():
  51. logger.critical(f'Not find {explorationConfig.exploration_config.exploration_level} or'
  52. f' Enter {explorationConfig.exploration_config.exploration_level} failed!')
  53. raise RequestHumanTakeover
  54. # 只探索7次
  55. if explorationConfig.exploration_config.attack_number == AttackNumber.SEVEN:
  56. count = 0
  57. while count < 7:
  58. self.screenshot()
  59. time.sleep(0.5)
  60. if self.appear_then_click(self.I_E_EXPLORATION_CLICK):
  61. count += 1
  62. # 进入战斗环节
  63. self.battle_process()
  64. if self.appear_then_click(self.I_EXPLORATION_TITLE):
  65. self.open_expect_level()
  66. # 查找指定的章节:
  67. def open_expect_level(self):
  68. swipeCount = 0
  69. while 1:
  70. # 探索的 config
  71. explorationConfig = self.config.exploration
  72. # 判断有无目标章节
  73. self.screenshot()
  74. # 获取当前章节名
  75. results = self.O_E_EXPLORATION_LEVEL_NUMBER.detect_and_ocr(self.device.image)
  76. text1 = [result.ocr_text for result in results]
  77. # 判断当前章节有无目标章节
  78. result = set(text1).intersection({explorationConfig.exploration_config.exploration_level})
  79. # 有则跳出检测
  80. if result and len(result) > 0:
  81. break
  82. self.device.click_record_clear()
  83. self.swipe(self.S_SWIPE_LEVEL_UP)
  84. swipeCount += 1
  85. if swipeCount >= 25:
  86. return False
  87. # 选中对应章节
  88. while 1:
  89. self.screenshot()
  90. self.O_E_EXPLORATION_LEVEL_NUMBER.keyword = explorationConfig.exploration_config.exploration_level
  91. if self.ocr_appear_click(self.O_E_EXPLORATION_LEVEL_NUMBER):
  92. self.wait_until_appear(self.I_E_EXPLORATION_CLICK)
  93. if self.appear(self.I_E_EXPLORATION_CLICK):
  94. break
  95. return True
  96. # 候补:
  97. def enter_settings_and_do_operations(self):
  98. # 打开设置
  99. self.click(self.C_CLICK_SETTINGS)
  100. while 1:
  101. self.screenshot()
  102. if self.appear(self.I_E_OPEN_SETTINGS):
  103. break
  104. else:
  105. self.click(self.C_CLICK_SETTINGS)
  106. if self.wait_until_appear(self.I_E_OPEN_SETTINGS):
  107. break
  108. # 候补出战数量识别
  109. self.screenshot()
  110. cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
  111. if cu >= 40:
  112. self.appear_then_click(self.I_E_SURE_BUTTON)
  113. return
  114. else:
  115. self.add_shiki()
  116. # 添加式神
  117. def add_shiki(self):
  118. self.screenshot()
  119. # 点击展开式神稀有度选择界面
  120. self.click(self.C_CLICK_ALL_SHIKI)
  121. while 1:
  122. self.screenshot()
  123. # 成功进入稀有度选择界面
  124. if self.appear(self.I_E_ENTER_CHOOSE_RARITY):
  125. if self.config.exploration.exploration_config.choose_rarity == ChooseRarity.N:
  126. # N 卡
  127. self.click(self.C_CLICK_N_SHIKI)
  128. else:
  129. # 素材卡
  130. self.appear_then_click(self.I_E_ENTER_CHOOSE_RARITY)
  131. self.screenshot()
  132. if self.appear(self.I_E_N_RARITY):
  133. # 进入N卡添加界面 退出
  134. break
  135. if self.appear(self.I_E_S_RARITY):
  136. # 进入素材添加界面 退出
  137. break
  138. # 选中候补出战框
  139. self.click(self.C_CLICK_STANDBY_TEAM)
  140. # 移动至未候补的狗粮
  141. while 1:
  142. # 慢一点
  143. time.sleep(0.5)
  144. self.screenshot()
  145. if self.appear(self.I_E_RATATE_EXSIT):
  146. self.swipe(self.S_SWIPE_SHIKI_TO_LEFT)
  147. else:
  148. break
  149. while 1:
  150. # 候补出战数量识别
  151. self.screenshot()
  152. cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
  153. if cu >= 40:
  154. break
  155. self.swipe(self.S_SWIPE_SHIKI_TO_LEFT_ONE)
  156. # 慢一点
  157. time.sleep(0.5)
  158. self.screenshot()
  159. self.click(self.C_CLICK_ROTATE_1)
  160. self.device.click_record_clear()
  161. self.appear_then_click(self.I_E_SURE_BUTTON)
  162. # 探索战斗流程
  163. def do_battle(self):
  164. while 1:
  165. self.screenshot()
  166. # boss 战
  167. if self.appear_then_click(self.I_BOSS_BATTLE_BUTTON):
  168. self.run_general_battle(self.config.exploration.general_battle_config)
  169. self.screenshot()
  170. if self.wait_until_appear(self.I_E_SETTINGS_BUTTON):
  171. while 1:
  172. self.screenshot()
  173. if self.appear_then_click(self.I_BATTLE_REWARD):
  174. self.screenshot()
  175. self.click(self.C_CLICK_ROTATE_1)
  176. time.sleep(0.5)
  177. if self.appear(self.I_EXPLORATION_TITLE):
  178. break
  179. if self.appear(self.I_E_EXPLORATION_CLICK):
  180. break
  181. if self.appear(self.I_E_EXPLORATION_CLICK) or self.appear(self.I_EXPLORATION_TITLE):
  182. break
  183. # 小怪 战
  184. if self.appear_then_click(self.I_NORMAL_BATTLE_BUTTON):
  185. self.screenshot()
  186. if self.appear_then_click(self.I_NORMAL_BATTLE_BUTTON):
  187. self.run_general_battle(self.config.exploration.general_battle_config)
  188. else:
  189. self.run_general_battle(self.config.exploration.general_battle_config)
  190. self.screenshot()
  191. while self.appear(self.I_BATTLE_REWARD):
  192. self.screenshot()
  193. self.appear_then_click(self.I_BATTLE_REWARD)
  194. self.screenshot()
  195. else:
  196. self.swipe(self.S_SWIPE_BACKGROUND_RIGHT)
  197. # 战斗流程
  198. def battle_process(self):
  199. # 进入指定章节
  200. self.screenshot()
  201. if self.appear_then_click(self.I_E_EXPLORATION_CLICK):
  202. self.appear_then_click(self.I_E_SETTINGS_BUTTON)
  203. # ************************* 进入设置并操作 *******************
  204. # 候补以及自动轮换打开:
  205. # 自动轮换功能打开
  206. while 1:
  207. self.screenshot()
  208. # 自动轮换开着 则跳过
  209. if self.appear(self.I_E_AUTO_ROTATE_ON):
  210. break
  211. # 自动轮换关着 则打开
  212. if self.appear_then_click(self.I_E_AUTO_ROTATE_OFF):
  213. if self.appear(self.I_E_AUTO_ROTATE_ON):
  214. break
  215. # 自动添加候补式神
  216. if self.config.exploration.exploration_config.auto_rotate == AutoRotate.yes:
  217. self.enter_settings_and_do_operations()
  218. # 进入战斗环节
  219. self.do_battle()
  220. if __name__ == "__main__":
  221. from module.config.config import Config
  222. from module.device.device import Device
  223. config = Config('oas1')
  224. device = Device(config)
  225. t = ScriptTask(config, device)
  226. t.config.exploration.exploration_config.exploration_level = '第二十八章'
  227. t.run()
  228. # t.battle_process()
  229. # t.enter_settings_and_do_operations()