script_task.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from time import sleep
  5. from datetime import datetime, time
  6. from module.logger import logger
  7. from module.exception import TaskEnd
  8. from module.base.timer import Timer
  9. from tasks.GameUi.game_ui import GameUi
  10. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  11. from tasks.Component.GeneralInvite.general_invite import GeneralInvite
  12. from tasks.Component.GeneralRoom.general_room import GeneralRoom
  13. from tasks.Orochi.script_task import ScriptTask as OrochiScriptTask
  14. from tasks.Orochi.config import Layer
  15. from tasks.GameUi.page import page_main, page_soul_zones,page_shikigami_records
  16. from tasks.TrueOrochi.assets import TrueOrochiAssets
  17. class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
  18. def run(self):
  19. # 御魂切换方式一
  20. if self.config.true_orochi.switch_soul.enable:
  21. self.ui_get_current_page()
  22. self.ui_goto(page_shikigami_records)
  23. self.run_switch_soul(self.config.true_orochi.switch_soul.switch_group_team)
  24. # 御魂切换方式二
  25. if self.config.true_orochi.switch_soul.enable_switch_by_name:
  26. self.ui_get_current_page()
  27. self.ui_goto(page_shikigami_records)
  28. self.run_switch_soul_by_name(self.config.true_orochi.switch_soul.group_name,
  29. self.config.true_orochi.switch_soul.team_name)
  30. conf = self.config.true_orochi.true_orochi_config
  31. if conf.current_success >= 2:
  32. # 超过两次就说明这周打完了没有必要再打了
  33. logger.warning('This week is full')
  34. self.check_times(True)
  35. raise TaskEnd('TrueOrochi')
  36. self.ui_get_current_page()
  37. self.ui_goto(page_soul_zones)
  38. self.orochi_enter()
  39. battle = self.check_true_orochi(True)
  40. if not battle:
  41. logger.warning('Not find true orochi')
  42. logger.warning('Try to battle orochi for ten times')
  43. # 判断是否需要挑战十层触发真蛇
  44. if not conf.find_true_orochi:
  45. logger.info('Not find_true_orochi_help')
  46. self.check_times(False)
  47. raise TaskEnd('TrueOrochi')
  48. self.check_layer(Layer.TEN)
  49. self.check_lock(False)
  50. count_orochi_ten = 0
  51. while 1:
  52. self.screenshot()
  53. # 检查猫咪奖励
  54. if self.appear_then_click(self.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
  55. continue
  56. if not self.appear(self.I_OROCHI_FIRE):
  57. continue
  58. if self.check_true_orochi(False):
  59. logger.info('Find true orochi')
  60. battle = True
  61. break
  62. if count_orochi_ten >= 10:
  63. logger.warning('Not find true orochi')
  64. battle = False
  65. break
  66. # 否则点击挑战
  67. if self.appear(self.I_OROCHI_FIRE):
  68. self.ui_click_until_disappear(self.I_OROCHI_FIRE)
  69. self.run_general_battle()
  70. count_orochi_ten += 1
  71. continue
  72. if not battle:
  73. # 如果还没有真蛇,那么就退出
  74. self.check_times(battle)
  75. raise TaskEnd('TrueOrochi')
  76. # 如果有真蛇,那么就开始战斗
  77. logger.hr('True Orochi Battle')
  78. conf.current_success += 1
  79. while 1:
  80. self.screenshot()
  81. if self.appear(self.I_ST_CREATE_ROOM):
  82. break
  83. if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
  84. continue
  85. if self.appear_then_click(self.I_ST_FIRE, interval=4):
  86. continue
  87. if self.appear_then_click(self.I_FIND_TS, interval=1):
  88. continue
  89. self.ensure_private()
  90. while 1:
  91. self.screenshot()
  92. if self.appear(self.I_ST_FIRE_PREPARE):
  93. break
  94. if self.appear_then_click(self.I_FIRE, interval=3, threshold=0.7):
  95. continue
  96. if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
  97. continue
  98. if self.appear_then_click(self.I_ST_CREATE_ROOM, interval=1):
  99. continue
  100. # 战斗准备
  101. logger.info('Battle prepare')
  102. self.ui_click(self.I_ST_FIRE_PREPARE, self.I_BUFF)
  103. while 1:
  104. self.screenshot()
  105. if not self.appear(self.I_BUFF):
  106. break
  107. if self.appear_then_click(self.I_ST_AUTO_FALSE, interval=0.8):
  108. continue
  109. if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.8):
  110. continue
  111. self.device.stuck_record_add('BATTLE_STATUS_S')
  112. self.device.click_record_clear()
  113. logger.info("Start battle process")
  114. check_timer = Timer(280)
  115. check_timer.start()
  116. while 1:
  117. self.screenshot()
  118. if self.appear(self.I_GREED_GHOST):
  119. sleep(0.7)
  120. self.screenshot()
  121. if not self.appear(self.I_GREED_GHOST):
  122. continue
  123. # 左上角的贪吃鬼
  124. while 1:
  125. self.screenshot()
  126. if not self.appear(self.I_GREED_GHOST):
  127. break
  128. if self.appear_then_click(self.I_GREED_GHOST, interval=1):
  129. continue
  130. if self.appear_then_click(self.I_ST_FRAME, interval=1):
  131. continue
  132. break
  133. if self.appear_then_click(self.I_ST_FRAME, interval=1):
  134. continue
  135. if check_timer.reached():
  136. logger.warning('Battle timeout')
  137. check_timer.reset()
  138. self.device.stuck_record_clear()
  139. self.device.stuck_record_add('BATTLE_STATUS_S')
  140. sleep(0.5)
  141. logger.info("Battle process end")
  142. self.check_times(battle)
  143. raise TaskEnd('TrueOrochi')
  144. def check_true_orochi(self, screenshot=False) -> bool:
  145. """
  146. 检查是否出现真蛇(要求当前的界面必须是在御魂挑战的界面)
  147. :return:
  148. """
  149. if screenshot:
  150. self.screenshot()
  151. return self.appear(self.I_FIND_TS)
  152. def check_times(self, battle: bool):
  153. """
  154. 后续的次数和时间设置
  155. :param battle:
  156. :param current_success: 这周的成功次数
  157. :return:
  158. """
  159. now = datetime.now()
  160. now_year, now_week_number, now_weekday = now.isocalendar()
  161. if battle:
  162. next_run = now + self.config.true_orochi.scheduler.success_interval
  163. else:
  164. next_run = now + self.config.true_orochi.scheduler.failure_interval
  165. next_run_year, next_run_week_number, next_run_weekday = next_run.isocalendar()
  166. self.set_next_run(task='TrueOrochi', target=next_run)
  167. # 如果下次运行的时间是下一周,那么就重置成功次数
  168. if now_week_number != next_run_week_number:
  169. self.config.true_orochi.true_orochi_config.current_success = 0
  170. else:
  171. # 如果不是下一周,那么就加一
  172. self.config.true_orochi.true_orochi_config.current_success += 1
  173. def run_true_orochi(self) -> bool:
  174. pass
  175. if __name__ == '__main__':
  176. from module.config.config import Config
  177. from module.device.device import Device
  178. c = Config('oas1')
  179. d = Device(c)
  180. t = ScriptTask(c, d)
  181. t.screenshot()
  182. t.run()