explore.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. while 1:
  24. self.screenshot()
  25. if self.appear(self.I_UI_BACK_YELLOW) and self.appear(self.I_E_EXPLORATION_CLICK):
  26. break
  27. if self.appear_then_click(goto, interval=2):
  28. continue
  29. while 1:
  30. scene = self.get_current_scene(reuse_screenshot=False)
  31. # 进入探索
  32. if scene == Scene.ENTRANCE:
  33. if _cnt_exploration >= num:
  34. logger.info('Execution exploration end')
  35. # --退出到探索大世界--
  36. self.ui_click(self.I_UI_BACK_YELLOW, stop=self.I_CHECK_EXPLORATION, interval=4)
  37. if explore_only_boss:
  38. raise ExploreWantedBoss
  39. break
  40. self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
  41. continue
  42. # 探索大世界
  43. elif scene == Scene.WORLD:
  44. self.wait_until_stable(
  45. self.I_CHECK_EXPLORATION,
  46. timer=Timer(limit=0.5, count=2),
  47. timeout=Timer(2, count=10)
  48. )
  49. curr_scene = self.get_current_scene(reuse_screenshot=False)
  50. if curr_scene == Scene.WORLD and _cnt_exploration >= num:
  51. logger.info('All Done')
  52. break
  53. continue
  54. # 探索里面
  55. elif scene == Scene.MAIN:
  56. # if not explore_init:
  57. # count = 0
  58. # while count < 5:
  59. # if self.appear(self.I_E_AUTO_ROTATE_ON):
  60. # break
  61. # if self.appear(self.I_E_AUTO_ROTATE_OFF, interval=1.5):
  62. # self.click(self.I_E_AUTO_ROTATE_OFF)
  63. # count += 1
  64. # explore_init = True
  65. # continue
  66. # 小纸人
  67. if self.appear(self.I_BATTLE_REWARD):
  68. if self.ui_get_reward(self.I_BATTLE_REWARD):
  69. continue
  70. # boss
  71. if self.appear(self.I_BOSS_BATTLE_BUTTON):
  72. if self.fire(self.I_BOSS_BATTLE_BUTTON):
  73. logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
  74. _cnt_exploration += 1
  75. explore_only_boss = False
  76. continue
  77. # 小怪
  78. if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
  79. explore_only_boss = False
  80. logger.info(f'Fight, minions cnt {self.minions_cnt}')
  81. continue
  82. # 向后拉,寻找怪
  83. if search_fail_timer.reached():
  84. search_fail_timer.reset()
  85. if self._match_end.stable(self.device.image, refresh_after_stable=True):
  86. _cnt_exploration += 1
  87. self.quit_explore()
  88. continue
  89. if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
  90. continue
  91. if not search_fail_timer.started():
  92. search_fail_timer.start()
  93. elif scene == Scene.BATTLE_PREPARE:
  94. self.ui_click_until_disappear(self.I_PREPARE_HIGHLIGHT, interval=0.5)
  95. elif scene == Scene.UNKNOWN:
  96. continue
  97. if __name__ == '__main__':
  98. from module.config.config import Config
  99. from module.device.device import Device
  100. from tasks.WantedQuests.assets import WantedQuestsAssets
  101. config = Config('oas1')
  102. device = Device(config)
  103. t = WQExplore(config, device)
  104. t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)