script_task.py 6.4 KB

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