script_task.py 6.7 KB

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