script_task.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # This Python file uses the following encoding: utf-8
  2. import time
  3. from module.exception import TaskEnd
  4. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  5. from tasks.GameUi.game_ui import GameUi
  6. from tasks.GameUi.page import page_exploration
  7. from tasks.DevExploration.assets import DevExplorationAssets
  8. from module.logger import logger
  9. from tasks.Secret.assets import SecretAssets
  10. from tasks.DevExploration.config import ExplorationMode
  11. class ScriptTask(GeneralBattle, GameUi, DevExplorationAssets):
  12. def run(self):
  13. options = self.config.dev_exploration
  14. if options.exploration_config.mode == ExplorationMode.CAPTAIN:
  15. return self._run_captain()
  16. elif options.exploration_config.mode == ExplorationMode.MEMBER:
  17. return self._run_member()
  18. else:
  19. logger.exception("Invalid mode, please choice [captain] or [member]")
  20. self._run_member()
  21. def _run_captain(self):
  22. options = self.config.dev_exploration
  23. self.ui_get_current_page()
  24. self.ui_goto(page_exploration)
  25. while True:
  26. self.screenshot()
  27. if self.ocr_appear(self.O_TEAM_BUTTON):
  28. break
  29. if self.appear_then_click(self.I_CHAPTER, interval=2):
  30. continue
  31. while True:
  32. self.screenshot()
  33. if self.ocr_appear(self.O_CREATE_BUTTON):
  34. break
  35. if self.ocr_appear_click(self.O_TEAM_BUTTON, interval=2):
  36. continue
  37. while True:
  38. self.screenshot()
  39. if self.appear(self.I_SMILE):
  40. break
  41. if self.ocr_appear_click(self.O_CREATE_BUTTON, interval=2):
  42. continue
  43. while True:
  44. self.screenshot()
  45. if self.ocr_appear(self.O_INVITE):
  46. break
  47. if self.click(self.C_ADD_AREA, interval=2):
  48. continue
  49. friend_name = options.exploration_config.friend
  50. logger.info("准备邀请队员:%s" % friend_name)
  51. self.O_FRIEND.keyword = friend_name
  52. time.sleep(2)
  53. self.screenshot()
  54. if not self.ocr_appear_click(self.O_FRIEND):
  55. logger.error("无法找到队员:%s" % friend_name)
  56. raise TaskEnd
  57. time.sleep(2)
  58. self.screenshot()
  59. self.ocr_appear_click(self.O_INVITE)
  60. self.wait_until_disappear(self.I_ADD_IMAGE)
  61. # 进入探索
  62. self.appear_then_click(self.I_START)
  63. time.sleep(3)
  64. while True:
  65. self.screenshot()
  66. if self.in_fight():
  67. logger.info("检测到进入战斗")
  68. self.battle_wait(random_click_swipt_enable=False)
  69. if self.in_room():
  70. self.wait_until_disappear(self.I_ADD_IMAGE)
  71. self.appear_then_click(self.I_START)
  72. if self.ocr_appear_click(self.O_QUEREN):
  73. pass
  74. if self.ocr_appear_click(self.O_QUEDING):
  75. pass
  76. time.sleep(0.2)
  77. def _run_member(self):
  78. count = 0
  79. while True:
  80. self.screenshot()
  81. if self.appear_then_click(self.I_ACCEPT):
  82. time.sleep(2)
  83. if self.in_fight():
  84. count += 1
  85. logger.info("检测到进入战斗 %s" % str(count))
  86. self.battle_wait(random_click_swipt_enable=False)
  87. if self.appear(self.I_EXIT_SIGN) or self.appear(self.I_EXIT_SIGN_2):
  88. self.appear_then_click(self.I_EXIT_TANSUO)
  89. if self.ocr_appear_click(self.O_QUEREN_2):
  90. pass
  91. time.sleep(0.2)
  92. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  93. # 重写
  94. self.device.stuck_record_add('BATTLE_STATUS_S')
  95. self.device.click_record_clear()
  96. # 战斗过程 随机点击和滑动 防封
  97. logger.info("Start battle process")
  98. while 1:
  99. self.screenshot()
  100. if self.appear(SecretAssets.I_SE_BATTLE_WIN):
  101. logger.info('Win battle')
  102. self.ui_click_until_disappear(SecretAssets.I_SE_BATTLE_WIN)
  103. return True
  104. if self.appear_then_click(self.I_WIN, interval=1):
  105. continue
  106. if self.appear(self.I_REWARD):
  107. logger.info('Win battle')
  108. self.ui_click_until_disappear(self.I_REWARD)
  109. return True
  110. if self.appear(self.I_FALSE):
  111. logger.warning('False battle')
  112. self.ui_click_until_disappear(self.I_FALSE)
  113. return False
  114. def in_fight(self):
  115. self.screenshot()
  116. if self.appear(self.I_EXIT):
  117. return True
  118. else:
  119. return False
  120. def in_room(self):
  121. self.screenshot()
  122. if self.appear(self.I_SMILE):
  123. return True
  124. else:
  125. return False
  126. if __name__ == '__main__':
  127. from module.config.config import Config
  128. from module.device.device import Device
  129. config = Config('oas2')
  130. device = Device(config)
  131. t = ScriptTask(config, device)
  132. t.run()