explore.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. from cached_property import cached_property
  2. from module.atom.animate import RuleAnimate
  3. from module.atom.image import RuleImage
  4. from module.base.timer import Timer
  5. from module.logger import logger
  6. from tasks.Exploration.base import BaseExploration, Scene
  7. from tasks.Exploration.version import HighLight
  8. class ExploreWantedBoss(Exception):
  9. # 出现一种情况,要求的怪是仅仅最后的Boss,其他小怪不是
  10. pass
  11. class WQExplore(BaseExploration, HighLight):
  12. _cnt_exploration: int = 0
  13. @cached_property
  14. def _match_end(self):
  15. return RuleAnimate(self.I_SWIPE_END)
  16. def explore(self, goto: RuleImage, num: int):
  17. logger.info(f'Start exploring with number: {num}')
  18. explore_init = False
  19. explore_only_boss: bool = True
  20. _cnt_exploration = 0
  21. search_fail_cnt = 0
  22. search_fail_timer = Timer(3.2) # 这里设置的时间一定要大于S_SWIPE_BACKGROUND_RIGHT滑动的时间
  23. # https://github.com/runhey/OnmyojiAutoScript/pull/1697 云景阆苑 皮肤
  24. from tasks.Component.Costume.config import MainType
  25. if self.config.model.global_game.costume_config.costume_main_type == MainType.COSTUME_MAIN_13:
  26. self.TEMPLATE_GIF.match = self.TEMPLATE_GIF.match_with_multi_scale
  27. logger.info("Costume '云景阆苑' detected, enable multi-scale matching for highlight")
  28. else:
  29. self.TEMPLATE_GIF.match = self.TEMPLATE_GIF.match_origin
  30. while 1:
  31. self.screenshot()
  32. if self.appear(self.I_UI_BACK_YELLOW) and self.appear(self.I_E_EXPLORATION_CLICK):
  33. break
  34. if self.appear_then_click(goto, interval=2):
  35. continue
  36. while 1:
  37. scene = self.get_current_scene(reuse_screenshot=False)
  38. # 进入探索
  39. if scene == Scene.ENTRANCE:
  40. if _cnt_exploration >= num:
  41. logger.info('Execution exploration end')
  42. # --退出到探索大世界--
  43. self.ui_click(self.I_UI_BACK_YELLOW, stop=self.I_CHECK_EXPLORATION, interval=4)
  44. if explore_only_boss:
  45. raise ExploreWantedBoss
  46. break
  47. self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
  48. continue
  49. # 探索大世界
  50. elif scene == Scene.WORLD:
  51. self.wait_until_stable(
  52. self.I_CHECK_EXPLORATION,
  53. timer=Timer(limit=0.5, count=2),
  54. timeout=Timer(2, count=10)
  55. )
  56. curr_scene = self.get_current_scene(reuse_screenshot=False)
  57. if curr_scene == Scene.WORLD and _cnt_exploration >= num:
  58. logger.info('All Done')
  59. break
  60. continue
  61. # 探索里面
  62. elif scene == Scene.MAIN:
  63. # if not explore_init:
  64. # count = 0
  65. # while count < 5:
  66. # if self.appear(self.I_E_AUTO_ROTATE_ON):
  67. # break
  68. # if self.appear(self.I_E_AUTO_ROTATE_OFF, interval=1.5):
  69. # self.click(self.I_E_AUTO_ROTATE_OFF)
  70. # count += 1
  71. # explore_init = True
  72. # continue
  73. # 小纸人
  74. if self.appear(self.I_BATTLE_REWARD):
  75. if self.ui_get_reward(self.I_BATTLE_REWARD):
  76. continue
  77. # boss
  78. if self.appear(self.I_BOSS_BATTLE_BUTTON):
  79. if self.fire(self.I_BOSS_BATTLE_BUTTON):
  80. logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
  81. _cnt_exploration += 1
  82. explore_only_boss = False
  83. continue
  84. # 小怪
  85. if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
  86. explore_only_boss = False
  87. logger.info(f'Fight, minions cnt {self.minions_cnt}')
  88. continue
  89. # 向后拉,寻找怪
  90. if search_fail_timer.reached():
  91. search_fail_timer.reset()
  92. if self._match_end.stable(self.device.image, refresh_after_stable=True):
  93. _cnt_exploration += 1
  94. self.quit_explore()
  95. continue
  96. if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
  97. continue
  98. if not search_fail_timer.started():
  99. search_fail_timer.start()
  100. elif scene == Scene.BATTLE_PREPARE:
  101. self.ui_click_until_disappear(self.I_PREPARE_HIGHLIGHT, interval=0.5)
  102. elif scene == Scene.UNKNOWN:
  103. continue
  104. if __name__ == '__main__':
  105. from module.config.config import Config
  106. from module.device.device import Device
  107. from tasks.WantedQuests.assets import WantedQuestsAssets
  108. config = Config('oas1')
  109. device = Device(config)
  110. t = WQExplore(config, device)
  111. t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)