script_task.py 7.5 KB

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