script_task.py 6.5 KB

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