script_task.py 3.6 KB

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