script_task.py 9.3 KB

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