script_task.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import time
  5. from module.base.timer import Timer
  6. from module.exception import TaskEnd
  7. from module.logger import logger
  8. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  9. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  10. from tasks.DyeTrials.assets import DyeTrialsAssets
  11. from tasks.GameUi.game_ui import GameUi
  12. from tasks.GameUi.page import page_main, page_shikigami_records
  13. from tasks.Restart.assets import RestartAssets
  14. """ 灵染 试炼 """
  15. class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DyeTrialsAssets):
  16. def run(self):
  17. cfg = self.config.dye_trials
  18. # 自动换御魂
  19. if cfg.switch_soul_config.enable:
  20. self.ui_get_current_page()
  21. self.ui_goto(page_shikigami_records)
  22. self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
  23. if cfg.switch_soul_config.enable_switch_by_name:
  24. self.ui_get_current_page()
  25. self.ui_goto(page_shikigami_records)
  26. self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
  27. self.ui_get_current_page()
  28. self.ui_goto(page_main)
  29. self.get_all()
  30. self.ui_get_current_page()
  31. self.ui_goto(page_main)
  32. self.set_next_run(task='DyeTrials', success=True, finish=True)
  33. raise TaskEnd('DyeTrials')
  34. def get_all(self):
  35. while 1:
  36. self.screenshot()
  37. if self.appear(self.I_FP_CHALLENGE):
  38. break
  39. if self.appear_then_click(self.I_FP_ACCESS, interval=0.8):
  40. continue
  41. if self.appear_then_click(self.I_FP_ACCESS_1, interval=1.5):
  42. continue
  43. if self.appear_then_click(self.I_TOGGLE_BUTTON, interval=3):
  44. continue
  45. logger.info('Enter DyeTrials')
  46. boss_timer = Timer(60)
  47. boss_timer.start()
  48. battle_num = 0
  49. while 1:
  50. self.screenshot()
  51. time.sleep(0.1)
  52. if boss_timer.reached():
  53. self.config.notifier.push(title='超鬼王', message='识别超时退出')
  54. break
  55. # 获得奖励
  56. if self.ui_reward_appear_click():
  57. boss_timer.reset()
  58. if self.appear_then_click(RestartAssets.I_HARVEST_CHAT_CLOSE):
  59. boss_timer.reset()
  60. continue
  61. if self.appear(self.I_FP_CHALLENGE, interval=1):
  62. cu, res, total = self.O_BATTLE_NUM.ocr(image=self.device.image)
  63. if cu == total == 50 and cu + res == total:
  64. break
  65. if battle_num >= 50:
  66. logger.info(f'Battle {battle_num}, enough battle, break')
  67. break
  68. self.ui_click_until_disappear(self.I_FP_CHALLENGE)
  69. battle_num += 1
  70. logger.info(f'Battle num [{battle_num}]')
  71. self.device.stuck_record_clear()
  72. self.device.stuck_record_add('BATTLE_STATUS_S')
  73. boss_timer.reset()
  74. continue
  75. if self.appear_then_click(self.I_BATTLE_SUCCESS, interval=1):
  76. boss_timer.reset()
  77. continue
  78. if __name__ == '__main__':
  79. from module.config.config import Config
  80. from module.device.device import Device
  81. c = Config('DU')
  82. d = Device(c)
  83. t = ScriptTask(c, d)
  84. t.screenshot()
  85. t.run()