explore.py 4.4 KB

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