script_task.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from datetime import datetime, timedelta
  5. from module.exception import TaskEnd
  6. from module.logger import logger
  7. from tasks.GameUi.game_ui import GameUi, Page
  8. from tasks.GameUi.page import page_soul_zones, page_shikigami_records
  9. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  10. from tasks.Component.GeneralRoom.general_room import GeneralRoom
  11. from tasks.Component.GeneralInvite.general_invite import GeneralInvite
  12. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  13. from tasks.EternitySea.assets import EternitySeaAssets
  14. from tasks.Orochi.config import UserStatus
  15. from tasks.EternitySea.config import EternitySea
  16. from module.exception import RequestHumanTakeover
  17. class ScriptTask(
  18. GameUi, GeneralBattle, GeneralRoom, GeneralInvite, SwitchSoul, EternitySeaAssets
  19. ):
  20. @property
  21. def task_name(self):
  22. return "EternitySea"
  23. def _two_teams_switch_sous(self, config):
  24. if config.enable:
  25. self.ui_get_current_page()
  26. self.ui_goto(page_shikigami_records)
  27. self.run_switch_soul(config.switch_group_team)
  28. if config.enable_switch_by_name:
  29. self.ui_get_current_page()
  30. self.ui_goto(page_shikigami_records)
  31. self.run_switch_soul_by_name(config.group_name, config.team_name)
  32. def run(self) -> None:
  33. self._two_teams_switch_sous(self._task_config.switch_soul_config_1)
  34. self._two_teams_switch_sous(self._task_config.switch_soul_config_2)
  35. match self._task_config.eternity_sea_config.user_status:
  36. case UserStatus.ALONE:
  37. success = self.run_alone()
  38. case _:
  39. logger.critical(
  40. f"UserStatus {self._task_config.eternity_sea_config.user_status} not support"
  41. )
  42. raise RequestHumanTakeover
  43. if success:
  44. self.set_next_run(self.task_name, finish=True, success=True)
  45. else:
  46. self.set_next_run(self.task_name, finish=False, success=False)
  47. raise TaskEnd(self.task_name)
  48. def run_alone(self) -> bool:
  49. logger.info("Start run alone")
  50. self._navigate_to_soul_zones()
  51. self._enter_eternity_sea()
  52. if self._task_config.general_battle_config.lock_team_enable == False:
  53. logger.critical(f"Only supports lock team mode")
  54. raise RequestHumanTakeover
  55. while 1:
  56. self.screenshot()
  57. if not self._is_in_eternity_sea():
  58. continue
  59. if self.current_count >= self._task_config.eternity_sea_config.limit_count:
  60. logger.info("EternitySea count limit out")
  61. break
  62. if datetime.now() - self.start_time >= self._limit_time:
  63. logger.info("EternitySea time limit out")
  64. break
  65. # 点击挑战
  66. while 1:
  67. self.screenshot()
  68. if self.appear_then_click(self.I_ETERNITY_SEA_FIRE, interval=1):
  69. pass
  70. if not self.appear(self.I_ETERNITY_SEA_FIRE):
  71. self.run_general_battle(
  72. config=self._task_config.general_battle_config
  73. )
  74. break
  75. def _is_in_eternity_sea(self) -> bool:
  76. self.screenshot()
  77. return self.appear(self.I_ETERNITY_SEA_FIRE)
  78. @property
  79. def _limit_time(self) -> timedelta:
  80. limit_time = self._task_config.eternity_sea_config.limit_time
  81. return timedelta(
  82. hours=limit_time.hour, minutes=limit_time.minute, seconds=limit_time.second
  83. )
  84. def _enter_eternity_sea(self) -> None:
  85. logger.info("Enter eternity_sea")
  86. while True:
  87. self.screenshot()
  88. if self.appear_then_click(self.I_ETERNITY_SEA, interval=1):
  89. break
  90. while True:
  91. self.screenshot()
  92. if self.appear(self.I_FORM_TEAM):
  93. return
  94. def _navigate_to_soul_zones(self) -> None:
  95. self.ui_get_current_page()
  96. self.ui_goto(page_soul_zones)
  97. def _navigate_to_game_page(self, destination: Page) -> None:
  98. self.ui_get_current_page()
  99. self.ui_goto(destination)
  100. @property
  101. def _task_config(self) -> EternitySea:
  102. return self.config.model.eternity_sea
  103. if __name__ == "__main__":
  104. from module.config.config import Config
  105. from module.device.device import Device
  106. c = Config("oas1")
  107. d = Device(c)
  108. t = ScriptTask(c, d)
  109. t.screenshot()
  110. t.run()