script_task.py 8.0 KB

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