script_task.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from cached_property import cached_property
  5. from datetime import datetime, time
  6. from tasks.Component.config_base import ConfigBase, TimeDelta, DateTime, Time
  7. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  8. from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
  9. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  10. from tasks.GameUi.game_ui import GameUi
  11. from tasks.GameUi.page import page_main
  12. from tasks.MetaDemon.config import MetaDemon
  13. from tasks.MetaDemon.assets import MetaDemonAssets
  14. from module.logger import logger
  15. from module.exception import TaskEnd
  16. class ScriptTask(GeneralBattle, SwitchSoul, GameUi, MetaDemonAssets):
  17. def run(self):
  18. self.ui_get_current_page()
  19. self.ui_goto(page_main)
  20. while 1:
  21. self.screenshot()
  22. if self.appear(self.I_MD_FIND):
  23. break
  24. if self.appear(self.I_MD_FIRE):
  25. break
  26. if self.appear_then_click(self.I_MD_ENTER, interval=1.5):
  27. continue
  28. if self.appear_then_click(self.I_MD_MAIN, interval=1.5):
  29. continue
  30. config: MetaDemon = self.config.model.meta_demon
  31. # 主循环
  32. while 1:
  33. self.screenshot()
  34. if not self.appear(self.I_MD_GIFT_BOX):
  35. continue
  36. # 检查是否有票
  37. if not self.ensure_ticket():
  38. logger.info('There is no common ticket')
  39. self.set_next_run('MetaDemon', finish=True,
  40. target=config.scheduler.interval + datetime.now().replace(second=0, microsecond=0))
  41. break
  42. # 检查疲劳°
  43. if not self.check_exhaustion():
  44. logger.info('Exhaustion is more than 100')
  45. if config.meta_demon_config.auto_tea:
  46. logger.info('Try to buy tea')
  47. self.buy_tea()
  48. continue
  49. else:
  50. logger.info('Stop because of exhaustion is more than 100')
  51. interval_delta = TimeDelta(minutes=self.current_exhaustion())
  52. self.set_next_run('MetaDemon', finish=True,
  53. target=interval_delta + datetime.now().replace(second=0, microsecond=0))
  54. break
  55. # 寻找鬼王
  56. if self.appear_then_click(self.I_MD_FIND, interval=1.5):
  57. continue
  58. #
  59. if self.appear(self.I_MD_FIRE):
  60. self.click_fire()
  61. self.run_general_battle(config=self.battle_config)
  62. # exit
  63. while 1:
  64. self.screenshot()
  65. if self.appear(self.I_CHECK_MAIN):
  66. logger.info('Exit MetaDemon')
  67. break
  68. if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
  69. continue
  70. raise TaskEnd
  71. @cached_property
  72. def battle_config(self):
  73. config = GeneralBattleConfig()
  74. config.lock_team_enable = False
  75. return config
  76. def ensure_ticket(self, screenshot: bool = False) -> bool:
  77. if screenshot:
  78. self.screenshot()
  79. cu, res, total = self.O_MD_TICKET.ocr(self.device.image)
  80. if cu <= 0:
  81. return False
  82. return True
  83. def check_exhaustion(self, screenshot: bool = False) -> bool:
  84. # EXHAUSTION
  85. if screenshot:
  86. self.screenshot()
  87. cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
  88. if cu >= 100:
  89. return False
  90. return True
  91. def current_exhaustion(self) -> int:
  92. self.screenshot()
  93. cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
  94. return int(cu)
  95. def click_fire(self):
  96. while 1:
  97. self.screenshot()
  98. if not self.appear(self.I_MD_FIRE):
  99. self.screenshot()
  100. if not self.appear(self.I_MD_FIRE):
  101. break
  102. if self.appear_then_click(self.I_MD_FIRE, interval=1.5):
  103. continue
  104. def buy_tea(self):
  105. pass
  106. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  107. # 重写
  108. self.device.stuck_record_add('BATTLE_STATUS_S')
  109. self.device.click_record_clear()
  110. logger.info("Start battle process")
  111. while 1:
  112. self.screenshot()
  113. # if self.appear_then_click(self.I_WIN, interval=1):
  114. # continue
  115. if self.appear(self.I_WIN):
  116. logger.info('Win battle')
  117. self.ui_click_until_disappear(self.I_WIN)
  118. return True
  119. if self.appear(self.I_FALSE):
  120. logger.warning('False battle')
  121. self.ui_click_until_disappear(self.I_FALSE)
  122. return False
  123. if __name__ == '__main__':
  124. from module.config.config import Config
  125. from module.device.device import Device
  126. c = Config('oas1')
  127. d = Device(c)
  128. t = ScriptTask(c, d)
  129. t.run()