script_task.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from time import sleep
  5. from datetime import time, datetime, timedelta
  6. from random import randint
  7. from module.logger import logger
  8. from module.exception import TaskEnd
  9. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  10. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  11. from tasks.GameUi.game_ui import GameUi
  12. from tasks.GameUi.page import page_main, page_shikigami_records, page_goryou_realm
  13. from tasks.GoryouRealm.config import GoryouClass
  14. from tasks.GoryouRealm.assets import GoryouRealmAssets
  15. class ScriptTask(GeneralBattle, GameUi, SwitchSoul, GoryouRealmAssets):
  16. def run(self):
  17. con = self.config.goryou_realm
  18. limit_time = con.goryou_config.limit_time
  19. self.limit_time: timedelta = timedelta(hours=limit_time.hour, minutes=limit_time.minute,
  20. seconds=limit_time.second)
  21. if con.switch_soul_config.enable:
  22. self.ui_get_current_page()
  23. self.ui_goto(page_shikigami_records)
  24. self.run_switch_soul(con.switch_soul_config.switch_group_team)
  25. self.ui_get_current_page()
  26. self.ui_goto(page_goryou_realm)
  27. match_click = {
  28. GoryouClass.Dark_Divine_Dragon: self.C_GR_C_1,
  29. GoryouClass.Dark_Hakuzousu: self.C_GR_C_2,
  30. GoryouClass.Dark_Black_Panther: self.C_GR_C_3,
  31. GoryouClass.Dark_Peacock: self.C_GR_C_4,
  32. }
  33. while 1:
  34. self.screenshot()
  35. if self.appear(self.I_GR_FIRE):
  36. logger.info('Enter GoryouRealm')
  37. break
  38. if self.click(match_click[self.check_date(con.goryou_config.goryou_class)], interval=1):
  39. continue
  40. self.check_lock(con.general_battle_config.lock_team_enable, self.I_GR_LOCK, self.I_GR_UNLOCK)
  41. # 开始循环
  42. while 1:
  43. self.screenshot()
  44. if not self.appear(self.I_GR_FIRE):
  45. continue
  46. if self.current_count >= con.goryou_config.limit_count:
  47. logger.info('GoryouRealm count limit out')
  48. break
  49. if datetime.now() - self.start_time >= self.limit_time:
  50. logger.info('GoryouRealm time limit out')
  51. break
  52. ticket = self.O_GR_TICKET.ocr(self.device.image)
  53. if ticket == 0:
  54. break
  55. # 点击挑战
  56. while 1:
  57. self.screenshot()
  58. if self.appear_then_click(self.I_GR_FIRE, interval=1):
  59. pass
  60. if not self.appear(self.I_GR_FIRE):
  61. self.run_general_battle(config=con.general_battle_config)
  62. break
  63. self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_EXPLORATION)
  64. logger.info('Back to exploration')
  65. self.set_next_run(task='GoryouRealm', success=True, finish=True)
  66. raise TaskEnd
  67. def check_date(self, goryou_class: GoryouClass = GoryouClass.RANDOM) -> GoryouClass:
  68. day_of_week = self.start_time.weekday()
  69. if day_of_week == 0:
  70. # 周一不开放,退出
  71. logger.warning('Today is Monday and GoryouRealm is not open')
  72. self.set_next_run(task='GoryouRealm', success=False, finish=True)
  73. raise TaskEnd('GoryouRealm')
  74. match_day = {
  75. GoryouClass.RANDOM: [1, 2, 3, 4, 5, 6],
  76. GoryouClass.Dark_Divine_Dragon: [1, 5, 6],
  77. GoryouClass.Dark_Hakuzousu: [2, 5, 6],
  78. GoryouClass.Dark_Black_Panther: [3, 5, 6],
  79. GoryouClass.Dark_Peacock: [4, 5, 6],
  80. }
  81. match_class = {
  82. 1: GoryouClass.Dark_Divine_Dragon,
  83. 2: GoryouClass.Dark_Hakuzousu,
  84. 3: GoryouClass.Dark_Black_Panther,
  85. 4: GoryouClass.Dark_Peacock,
  86. }
  87. if goryou_class == GoryouClass.RANDOM:
  88. random_num = randint(1, 4)
  89. goryou_class = match_class[random_num]
  90. if day_of_week not in match_day[goryou_class]:
  91. logger.warning(f'Today is {day_of_week} that do not support {goryou_class.name}')
  92. logger.info(f'OAS will run {match_class[day_of_week].name} instead')
  93. goryou_class = match_class[day_of_week]
  94. return goryou_class
  95. if __name__ == '__main__':
  96. from module.config.config import Config
  97. from module.device.device import Device
  98. c = Config('oas1')
  99. d = Device(c)
  100. t = ScriptTask(c, d)
  101. t.screenshot()
  102. t.run()