script_task.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. 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. # 御魂切换方式一
  26. if self.config.true_orochi.switch_soul.enable:
  27. self.ui_get_current_page()
  28. self.ui_goto(page_shikigami_records)
  29. self.run_switch_soul(self.config.true_orochi.switch_soul.switch_group_team)
  30. # 御魂切换方式二
  31. if self.config.true_orochi.switch_soul.enable_switch_by_name:
  32. self.ui_get_current_page()
  33. self.ui_goto(page_shikigami_records)
  34. self.run_switch_soul_by_name(self.config.true_orochi.switch_soul.group_name,
  35. self.config.true_orochi.switch_soul.team_name)
  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. # 修正已经挑战的次数, 注意这个是战斗开始之前的次数
  87. current, current_success, total = self.O_TIMES.ocr(self.device.image)
  88. if current_success < 0 or current_success > 2:
  89. continue
  90. logger.info(f'current: {current}, current_success: {current_success}, total: {total}')
  91. conf.current_success = current_success
  92. self.config.save()
  93. continue
  94. if self.appear_then_click(self.I_FIND_TS, interval=1):
  95. continue
  96. self.ensure_private()
  97. while 1:
  98. self.screenshot()
  99. if self.appear(self.I_ST_FIRE_PREPARE):
  100. break
  101. if self.appear_then_click(self.I_FIRE, interval=3, threshold=0.7):
  102. continue
  103. if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
  104. continue
  105. if self.appear_then_click(self.I_ST_CREATE_ROOM, interval=1):
  106. continue
  107. # 战斗准备
  108. logger.info('Battle prepare')
  109. self.ui_click(self.I_ST_FIRE_PREPARE, self.I_BUFF)
  110. while 1:
  111. self.screenshot()
  112. if not self.appear(self.I_BUFF):
  113. break
  114. if self.appear_then_click(self.I_ST_AUTO_FALSE, interval=1.8):
  115. continue
  116. # 下面代码 "点击准备" 会造成,点击了准备打第一层 循环 if not self.appear(self.I_BUFF): 时候跳出while循环,导致真蛇卡在第二层
  117. # if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.8):
  118. # continue
  119. self.device.stuck_record_add('BATTLE_STATUS_S')
  120. self.device.click_record_clear()
  121. logger.info("Start battle process")
  122. check_timer = Timer(280)
  123. check_timer.start()
  124. while 1:
  125. self.screenshot()
  126. if self.appear(self.I_GREED_GHOST):
  127. sleep(0.7)
  128. self.screenshot()
  129. if not self.appear(self.I_GREED_GHOST):
  130. continue
  131. # 左上角的贪吃鬼
  132. while 1:
  133. self.screenshot()
  134. if not self.appear(self.I_GREED_GHOST):
  135. break
  136. if self.appear_then_click(self.I_GREED_GHOST, interval=1):
  137. continue
  138. if self.appear_then_click(self.I_ST_FRAME, interval=1):
  139. continue
  140. break
  141. if self.appear_then_click(self.I_ST_FRAME, interval=1):
  142. continue
  143. if check_timer.reached():
  144. logger.warning('Battle timeout')
  145. check_timer.reset()
  146. self.device.stuck_record_clear()
  147. self.device.stuck_record_add('BATTLE_STATUS_S')
  148. sleep(0.5)
  149. logger.info("Battle process end")
  150. self.check_times(battle)
  151. raise TaskEnd('TrueOrochi')
  152. def check_true_orochi(self, screenshot=False) -> bool:
  153. """
  154. 检查是否出现真蛇(要求当前的界面必须是在御魂挑战的界面)
  155. :return:
  156. """
  157. if screenshot:
  158. self.screenshot()
  159. return self.appear(self.I_FIND_TS)
  160. def check_times(self, battle: bool):
  161. """
  162. 后续的次数和时间设置
  163. :param battle:
  164. :param current_success: 这周的成功次数
  165. :return:
  166. """
  167. now = datetime.now()
  168. now_year, now_week_number, now_weekday = now.isocalendar()
  169. if battle:
  170. next_run = now + self.config.true_orochi.scheduler.success_interval
  171. else:
  172. next_run = now + self.config.true_orochi.scheduler.failure_interval
  173. next_run_year, next_run_week_number, next_run_weekday = next_run.isocalendar()
  174. # 如果下次运行的时间是下一周,那么就重置成功次数
  175. if now_week_number != next_run_week_number:
  176. logger.info('Reset current_success')
  177. self.config.true_orochi.true_orochi_config.current_success = 0
  178. else:
  179. # 如果不是下一周,那么就加一
  180. logger.info('Add current_success by 1')
  181. self.config.true_orochi.true_orochi_config.current_success += 1
  182. self.config.true_orochi.true_orochi_config.current_success = min(2, self.config.true_orochi.true_orochi_config.current_success)
  183. self.config.save()
  184. self.set_next_run(task='TrueOrochi', target=next_run)
  185. # self.set_next_run('TrueOrochi', finish=True, success=True)
  186. def run_true_orochi(self) -> bool:
  187. pass
  188. if __name__ == '__main__':
  189. from module.config.config import Config
  190. from module.device.device import Device
  191. c = Config('oas1')
  192. d = Device(c)
  193. t = ScriptTask(c, d)
  194. t.screenshot()
  195. t.run()