script_task.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.goto_page(page_shikigami_records)
  21. self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
  22. if cfg.switch_soul_config.enable_switch_by_name:
  23. self.goto_page(page_shikigami_records)
  24. self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
  25. self.goto_page(page_main)
  26. self.get_all()
  27. self.goto_page(page_main)
  28. self.set_next_run(task='DyeTrials', success=True, finish=True)
  29. raise TaskEnd('DyeTrials')
  30. def get_all(self):
  31. while 1:
  32. self.screenshot()
  33. if self.appear(self.I_FP_CHALLENGE):
  34. break
  35. if self.appear_then_click(self.I_FP_ACCESS, interval=0.8):
  36. continue
  37. if self.appear_then_click(self.I_FP_ACCESS_1, interval=1.5):
  38. continue
  39. if self.appear_then_click(self.I_TOGGLE_BUTTON, interval=3):
  40. continue
  41. logger.info('Enter DyeTrials')
  42. boss_timer = Timer(60)
  43. boss_timer.start()
  44. battle_num = 0
  45. while 1:
  46. self.screenshot()
  47. time.sleep(0.1)
  48. if boss_timer.reached():
  49. self.config.notifier.push(title='超鬼王', message='识别超时退出')
  50. break
  51. # 获得奖励
  52. if self.ui_reward_appear_click():
  53. boss_timer.reset()
  54. if self.appear_then_click(RestartAssets.I_HARVEST_CHAT_CLOSE):
  55. boss_timer.reset()
  56. continue
  57. if self.appear(self.I_FP_CHALLENGE, interval=1):
  58. cu, res, total = self.O_BATTLE_NUM.ocr(image=self.device.image)
  59. if cu == total == 50 and cu + res == total:
  60. break
  61. if battle_num >= 50:
  62. logger.info(f'Battle {battle_num}, enough battle, break')
  63. break
  64. self.ui_click_until_disappear(self.I_FP_CHALLENGE)
  65. battle_num += 1
  66. logger.info(f'Battle num [{battle_num}]')
  67. self.device.stuck_record_clear()
  68. self.device.stuck_record_add('BATTLE_STATUS_S')
  69. boss_timer.reset()
  70. continue
  71. if self.appear_then_click(self.I_BATTLE_SUCCESS, interval=1):
  72. boss_timer.reset()
  73. continue
  74. if __name__ == '__main__':
  75. from module.config.config import Config
  76. from module.device.device import Device
  77. c = Config('DU')
  78. d = Device(c)
  79. t = ScriptTask(c, d)
  80. t.screenshot()
  81. t.run()