script_task.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from cached_property import cached_property
  5. from datetime import datetime
  6. from time import sleep
  7. from tasks.Component.config_base import ConfigBase, TimeDelta, DateTime, Time
  8. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  9. from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
  10. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  11. from tasks.GameUi.game_ui import GameUi
  12. from tasks.GameUi.page import page_main, page_shikigami_records
  13. from tasks.MetaDemon.config import MetaDemon
  14. from tasks.MetaDemon.assets import MetaDemonAssets
  15. from module.logger import logger
  16. from module.exception import TaskEnd
  17. from tasks.Restart.assets import RestartAssets
  18. from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
  19. from module.base.timer import Timer
  20. """超鬼王"""
  21. class ScriptTask(GeneralBattle, SwitchSoul, GameUi, MetaDemonAssets):
  22. def run(self):
  23. if self.config.meta_demon.switch_soul.enable:
  24. self.ui_get_current_page()
  25. self.ui_goto(page_shikigami_records)
  26. self.run_switch_soul(self.config.meta_demon.switch_soul.switch_group_team)
  27. if self.config.meta_demon.switch_soul.enable_switch_by_name:
  28. self.ui_get_current_page()
  29. self.ui_goto(page_shikigami_records)
  30. self.run_switch_soul_by_name(self.config.meta_demon.switch_soul.group_name,
  31. self.config.meta_demon.switch_soul.team_name)
  32. self.ui_get_current_page()
  33. self.ui_goto(page_main)
  34. boss_timer = Timer(200)
  35. boss_timer.start()
  36. while 1:
  37. self.screenshot()
  38. sleep(0.1)
  39. if boss_timer.reached():
  40. self.config.notifier.push(title='超鬼王', message='识别超时退出')
  41. break
  42. if self.appear(self.I_BACK_CHECK):
  43. self.click(self.I_RED_BACK, interval=1.5)
  44. break
  45. if self.appear_then_click(RestartAssets.I_HARVEST_CHAT_CLOSE):
  46. boss_timer.reset()
  47. continue
  48. if self.appear_then_click(ActivityShikigamiAssets.I_SHI, interval=1):
  49. boss_timer.reset()
  50. continue
  51. if self.appear_then_click(self.I_A2):
  52. boss_timer.reset()
  53. continue
  54. if self.appear_then_click(self.I_A3, interval=1):
  55. boss_timer.reset()
  56. continue
  57. if self.appear_then_click(self.I_A4, interval=1):
  58. boss_timer.reset()
  59. continue
  60. if self.appear_then_click(self.I_A5, interval=1):
  61. self.device.stuck_record_clear()
  62. self.device.stuck_record_add('BATTLE_STATUS_S')
  63. boss_timer.reset()
  64. continue
  65. if self.appear_then_click(self.I_A6, interval=1):
  66. boss_timer.reset()
  67. continue
  68. config: MetaDemon = self.config.model.meta_demon
  69. # 主循环
  70. while 1:
  71. self.screenshot()
  72. if self.appear(self.I_CHECK_MAIN):
  73. logger.info('Exit MetaDemon')
  74. break
  75. if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
  76. continue
  77. self.set_next_run(task="MetaDemon", success=True)
  78. raise TaskEnd
  79. @cached_property
  80. def battle_config(self):
  81. config = GeneralBattleConfig()
  82. config.lock_team_enable = False
  83. return config
  84. def ensure_ticket(self, screenshot: bool = False) -> bool:
  85. if screenshot:
  86. self.screenshot()
  87. cu, res, total = self.O_MD_TICKET.ocr(self.device.image)
  88. if cu <= 0:
  89. return False
  90. return True
  91. def check_exhaustion(self, screenshot: bool = False) -> bool:
  92. # EXHAUSTION
  93. if screenshot:
  94. self.screenshot()
  95. cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
  96. if cu >= 100:
  97. return False
  98. return True
  99. def current_exhaustion(self) -> int:
  100. self.screenshot()
  101. cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
  102. return int(cu)
  103. def click_fire(self):
  104. while 1:
  105. self.screenshot()
  106. if not self.appear(self.I_MD_FIRE):
  107. self.screenshot()
  108. if not self.appear(self.I_MD_FIRE):
  109. break
  110. if self.appear_then_click(self.I_MD_FIRE, interval=2):
  111. continue
  112. def buy_tea(self):
  113. pass
  114. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  115. # 重写
  116. self.device.stuck_record_add('BATTLE_STATUS_S')
  117. self.device.click_record_clear()
  118. logger.info("Start battle process")
  119. while 1:
  120. self.screenshot()
  121. # if self.appear_then_click(self.I_WIN, interval=1):
  122. # continue
  123. if self.appear(self.I_WIN):
  124. logger.info('Win battle')
  125. self.ui_click_until_disappear(self.I_WIN)
  126. return True
  127. if self.appear(self.I_MD_BATTLE_FAILURE):
  128. logger.warning('False battle')
  129. self.ui_click_until_disappear(self.I_MD_BATTLE_FAILURE)
  130. return False
  131. if __name__ == '__main__':
  132. from module.config.config import Config
  133. from module.device.device import Device
  134. c = Config('oas1')
  135. d = Device(c)
  136. t = ScriptTask(c, d)
  137. t.run()