explore.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. from cached_property import cached_property
  2. from module.atom.image import RuleImage
  3. from module.atom.animate import RuleAnimate
  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_RED) 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_RED)
  35. if explore_only_boss:
  36. raise ExploreWantedBoss
  37. break
  38. self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
  39. continue
  40. # 探索大世界
  41. elif scene == Scene.WORLD:
  42. self.wait_until_stable(
  43. self.I_CHECK_EXPLORATION,
  44. timer=Timer(limit=0.5, count=2),
  45. timeout=Timer(2, count=10)
  46. )
  47. curr_scene = self.get_current_scene(reuse_screenshot=False)
  48. if curr_scene == Scene.WORLD and _cnt_exploration >= num:
  49. logger.info('All Done')
  50. break
  51. continue
  52. # 探索里面
  53. elif scene == Scene.MAIN:
  54. if not explore_init:
  55. self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
  56. explore_init = True
  57. continue
  58. # 小纸人
  59. if self.appear(self.I_BATTLE_REWARD):
  60. if self.ui_get_reward(self.I_BATTLE_REWARD):
  61. continue
  62. # boss
  63. if self.appear(self.I_BOSS_BATTLE_BUTTON):
  64. if self.fire(self.I_BOSS_BATTLE_BUTTON):
  65. logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
  66. _cnt_exploration += 1
  67. explore_only_boss = False
  68. continue
  69. # 小怪
  70. if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
  71. explore_only_boss = False
  72. logger.info(f'Fight, minions cnt {self.minions_cnt}')
  73. # 向后拉,寻找怪
  74. if search_fail_cnt >= 4:
  75. search_fail_cnt = 0
  76. if self._match_end.stable(self.device.image):
  77. _cnt_exploration += 1
  78. self.quit_explore()
  79. continue
  80. if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
  81. continue
  82. else:
  83. search_fail_cnt += 1
  84. elif scene == Scene.UNKNOWN:
  85. continue
  86. if __name__ == '__main__':
  87. from module.config.config import Config
  88. from module.device.device import Device
  89. from tasks.WantedQuests.assets import WantedQuestsAssets
  90. config = Config('oas1')
  91. device = Device(config)
  92. t = WQExplore(config, device)
  93. t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)