script_task.py 9.2 KB

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