script_task.py 7.8 KB

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