script_task.py 8.7 KB

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