explore.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_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. count=0
  56. while count<5:
  57. if self.appear(self.I_E_AUTO_ROTATE_ON):
  58. break
  59. if self.appear(self.I_E_AUTO_ROTATE_OFF, interval=1.5):
  60. self.click(self.I_E_AUTO_ROTATE_OFF)
  61. count+=1
  62. explore_init = True
  63. continue
  64. # 小纸人
  65. if self.appear(self.I_BATTLE_REWARD):
  66. if self.ui_get_reward(self.I_BATTLE_REWARD):
  67. continue
  68. # boss
  69. if self.appear(self.I_BOSS_BATTLE_BUTTON):
  70. if self.fire(self.I_BOSS_BATTLE_BUTTON):
  71. logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
  72. _cnt_exploration += 1
  73. explore_only_boss = False
  74. continue
  75. # 小怪
  76. if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
  77. explore_only_boss = False
  78. logger.info(f'Fight, minions cnt {self.minions_cnt}')
  79. # 向后拉,寻找怪
  80. if search_fail_cnt >= 4:
  81. search_fail_cnt = 0
  82. if self._match_end.stable(self.device.image):
  83. _cnt_exploration += 1
  84. self.quit_explore()
  85. continue
  86. if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
  87. continue
  88. else:
  89. search_fail_cnt += 1
  90. elif scene == Scene.UNKNOWN:
  91. continue
  92. if __name__ == '__main__':
  93. from module.config.config import Config
  94. from module.device.device import Device
  95. from tasks.WantedQuests.assets import WantedQuestsAssets
  96. config = Config('oas1')
  97. device = Device(config)
  98. t = WQExplore(config, device)
  99. t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)