script_task.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 timedelta, datetime, time
  6. from cached_property import cached_property
  7. from module.exception import TaskEnd
  8. from module.logger import logger
  9. from module.base.timer import Timer
  10. from tasks.GameUi.game_ui import GameUi
  11. from tasks.GameUi.page import page_main, page_hunt, page_hunt_kirin, page_shikigami_records
  12. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  13. from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
  14. from tasks.Component.GeneralInvite.general_invite import GeneralInvite
  15. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  16. from tasks.Hunt.assets import HuntAssets
  17. class ScriptTask(GameUi, GeneralBattle, GeneralInvite, SwitchSoul, HuntAssets):
  18. kirin_day = True # 不是麒麟就是阴界之门
  19. tomorrow_kirin_day = True # 明天是麒麟还是阴界之门
  20. def run(self):
  21. self.con_time = self.config.hunt.hunt_time
  22. if not self.check_datetime():
  23. # 设置下次运行时间 为今天的晚上七点钟
  24. raise TaskEnd('Hunt')
  25. con = self.config.hunt.hunt_config
  26. if con.kirin_group_team != '-1,-1' or con.netherworld_group_team != '-1,-1':
  27. self.ui_get_current_page()
  28. self.ui_goto(page_shikigami_records)
  29. if self.kirin_day:
  30. if con.kirin_group_team != '-1,-1':
  31. self.run_switch_soul(con.kirin_group_team)
  32. else:
  33. if con.netherworld_group_team != '-1,-1':
  34. self.run_switch_soul(con.netherworld_group_team)
  35. self.ui_get_current_page()
  36. if self.kirin_day:
  37. self.ui_goto(page_hunt_kirin)
  38. self.kirin()
  39. else:
  40. self.ui_goto(page_hunt)
  41. self.netherworld()
  42. sleep(1)
  43. self.plan_tomorrow_hunt()
  44. raise TaskEnd('Hunt')
  45. def check_datetime(self) -> bool:
  46. """
  47. 检查日期和时间, 会设置是麒麟还是阴界之门
  48. :return: 符合麒麟19:00-21:00、阴界19:00-23:00的时间返回True, 否则返回False
  49. """
  50. now = datetime.now()
  51. day_of_week = now.weekday()
  52. if 0 <= day_of_week <= 3:
  53. self.kirin_day = True
  54. elif 4 <= day_of_week <= 6:
  55. self.kirin_day = False
  56. if 3 <= day_of_week <= 5:
  57. self.tomorrow_kirin_day = False
  58. else:
  59. self.tomorrow_kirin_day = True
  60. now = datetime.now()
  61. # 如果时间在可执行时间(麒麟日6:00、阴界日19:00)之前则设定时间为当天的自定义时间,返回False
  62. # 如果是在可执行时间则返回True
  63. if self.kirin_day:
  64. logger.info('Today is the Kirin day')
  65. if now.time() < time(6, 0):
  66. self.custom_next_run(task='Hunt', custom_time=self.con_time.kirin_time, time_delta=0)
  67. raise TaskEnd('Hunt')
  68. # 如果是麒麟日在23:00-23:59之间则设定时间为明天的自定义时间,返回False
  69. elif now.time() > time(23, 0):
  70. self.plan_tomorrow_hunt()
  71. raise TaskEnd('Hunt')
  72. else:
  73. return True
  74. else:
  75. logger.info('Today is the Netherworld day')
  76. if now.time() < time(19, 0):
  77. self.custom_next_run(task='Hunt', custom_time=self.con_time.netherworld_time, time_delta=0)
  78. raise TaskEnd('Hunt')
  79. # 如果是阴界日在23:00-23:59之间则设定时间为明天的自定义时间,返回False
  80. elif now.time() > time(23, 0):
  81. self.plan_tomorrow_hunt()
  82. raise TaskEnd('Hunt')
  83. else:
  84. return True
  85. def plan_tomorrow_hunt(self):
  86. # 安排次日狩猎战,便于复用
  87. if self.tomorrow_kirin_day:
  88. logger.info('Tomorrow is the Kirin day')
  89. self.custom_next_run(task='Hunt', custom_time=self.con_time.kirin_time, time_delta=1)
  90. else:
  91. logger.info('Tomorrow is the Netherworld day')
  92. self.custom_next_run(task='Hunt', custom_time=self.con_time.netherworld_time, time_delta=1)
  93. def kirin(self):
  94. logger.hr('kirin', 2)
  95. while 1:
  96. self.screenshot()
  97. if self.appear(self.I_PREPARE_HIGHLIGHT):
  98. break
  99. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.9):
  100. continue
  101. if self.appear_then_click(self.I_KIRIN_CHALLAGE, interval=1.5):
  102. continue
  103. if self.appear(self.I_KIRIN_END):
  104. # 今日已挑战
  105. logger.warning('Today have already challenged the Kirin')
  106. self.ui_click_until_disappear(self.I_UI_BACK_YELLOW)
  107. return
  108. logger.info('Start battle')
  109. self.run_general_battle()
  110. def netherworld(self):
  111. logger.hr('netherworld', 2)
  112. while 1:
  113. self.screenshot()
  114. if self.is_in_room(False):
  115. self.screenshot()
  116. if not self.appear(self.I_FIRE):
  117. continue
  118. self.click_fire()
  119. break
  120. if self.appear_then_click(self.I_NW, interval=0.9):
  121. continue
  122. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.9):
  123. continue
  124. if self.appear_then_click(self.I_NW_CHALLAGE, interval=1.5):
  125. continue
  126. if self.appear(self.I_NW_DONE):
  127. # 今日已挑战
  128. logger.warning('Today have already challenged the Netherworld')
  129. self.ui_click_until_disappear(self.I_UI_BACK_RED)
  130. return
  131. logger.info('Start battle')
  132. self.run_general_battle()
  133. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  134. """
  135. 重写,
  136. 阴界之门: 胜利后回到狩猎战的主界面
  137. 麒麟: 胜利后回到麒麟的主界面
  138. :param random_click_swipt_enable:
  139. :return:
  140. """
  141. # if self.kirin_day:
  142. # return super().battle_wait(random_click_swipt_enable)
  143. # 阴界之门
  144. self.device.stuck_record_add('BATTLE_STATUS_S')
  145. self.device.click_record_clear()
  146. # 战斗过程 随机点击和滑动 防封
  147. logger.info("Start battle process")
  148. stuck_timer = Timer(180)
  149. stuck_timer.start()
  150. while 1:
  151. self.screenshot()
  152. if self.appear(self.I_WIN):
  153. logger.info('Battle win')
  154. self.ui_click_until_disappear(self.I_WIN)
  155. return True
  156. # 如果出现失败 就点击,返回False
  157. if self.appear(self.I_FALSE, threshold=0.8):
  158. logger.info("Battle result is false")
  159. self.ui_click_until_disappear(self.I_FALSE)
  160. return False
  161. if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
  162. logger.info('Netherworld click prepare after maybe failed')
  163. continue
  164. # 如果三分钟还没打完,再延长五分钟
  165. if stuck_timer and stuck_timer.reached():
  166. stuck_timer = None
  167. self.device.stuck_record_clear()
  168. self.device.stuck_record_add('BATTLE_STATUS_S')
  169. if __name__ == '__main__':
  170. from module.config.config import Config
  171. from module.device.device import Device
  172. c = Config('oas1')
  173. d = Device(c)
  174. t = ScriptTask(c, d)
  175. t.screenshot()
  176. t.run()