script_task.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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
  6. from time import sleep
  7. from module.base.timer import Timer
  8. from module.logger import logger
  9. from module.exception import TaskEnd
  10. from tasks.Component.RightActivity.right_activity import RightActivity
  11. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  12. from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
  13. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  14. from tasks.GameUi.game_ui import GameUi
  15. from tasks.GameUi.page import page_main, page_shikigami_records
  16. from tasks.MetaDemon.config import MetaDemon
  17. from tasks.MetaDemon.assets import MetaDemonAssets
  18. from tasks.Restart.assets import RestartAssets
  19. from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
  20. class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, GameUi, MetaDemonAssets):
  21. def run(self):
  22. if self.config.meta_demon.switch_soul.enable:
  23. self.ui_get_current_page()
  24. self.ui_goto(page_shikigami_records)
  25. self.run_switch_soul(self.config.meta_demon.switch_soul.switch_group_team)
  26. if self.config.meta_demon.switch_soul.enable_switch_by_name:
  27. self.ui_get_current_page()
  28. self.ui_goto(page_shikigami_records)
  29. self.run_switch_soul_by_name(self.config.meta_demon.switch_soul.group_name,
  30. self.config.meta_demon.switch_soul.team_name)
  31. self.enter(self.I_RIGHT_ENTER)
  32. while 1:
  33. self.screenshot()
  34. if self.appear(self.I_FIND_DEMON) or self.appear(self.I_BATTLE_DEMON):
  35. break
  36. if self.appear_then_click(self.I_ENTER2, interval=1):
  37. continue
  38. if self.config.meta_demon.meta_demon_config.meta_crafting_card:
  39. self.crafting()
  40. boss_timer = Timer(120)
  41. boss_timer.start()
  42. while 1:
  43. battle_processing = False
  44. self.screenshot()
  45. if not (self.appear(self.I_FIND_DEMON) or self.appear(self.I_BATTLE_DEMON)):
  46. continue
  47. # 先看自己有没有鬼王要打
  48. if not self.appear(self.I_BOSS_EMPTY):
  49. self.click(self.I_BOSS_EMPTY, interval=1.5)
  50. battle_processing = True
  51. # 看别人的是否给我共享鬼王
  52. if not battle_processing:
  53. if not self.appear(self.I_BOSS_EMPTY_1):
  54. self.click(self.I_BOSS_EMPTY_1, interval=1.5)
  55. battle_processing = True
  56. elif not self.appear(self.I_BOSS_EMPTY_2):
  57. self.click(self.I_BOSS_EMPTY_2, interval=1.5)
  58. battle_processing = True
  59. # 是否喝茶 疲劳满了就不打了
  60. current_exhaustion = self.current_exhaustion()
  61. if current_exhaustion > 99:
  62. if self.config.meta_demon.meta_demon_config.auto_tea:
  63. logger.info('Exhaustion is full, buy tea')
  64. boss_timer.reset()
  65. self.buy_tea()
  66. else:
  67. logger.info('Exhaustion is full, exit')
  68. break
  69. # 正式战斗
  70. if battle_processing and self.appear(self.I_BATTLE_DEMON):
  71. boss_timer.reset()
  72. self.battle_boss()
  73. continue
  74. # 自己召唤鬼王
  75. if self.find_demon():
  76. boss_timer.reset()
  77. continue
  78. # 退出
  79. self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MAIN, interval=1.4)
  80. logger.info('Exit MetaDemon')
  81. self.set_next_run(task="MetaDemon", success=True)
  82. raise TaskEnd
  83. def current_exhaustion(self) -> int:
  84. self.screenshot()
  85. cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
  86. return int(cu)
  87. def buy_tea(self):
  88. pass
  89. def crafting(self):
  90. """
  91. 把一星合成二星
  92. @return:
  93. """
  94. logger.info('Star crafting 1 star to 2 star')
  95. self.ui_click(self.I_CRAFTING_1, self.I_CRAFTING_START, interval=1.5)
  96. timer = Timer(3).start()
  97. count = 0
  98. while 1:
  99. self.screenshot()
  100. if self.ui_reward_appear_click():
  101. timer.reset()
  102. continue
  103. if timer.reached() or count > 3:
  104. break
  105. if not self.ocr_appear(self.O_CRAFTING_CARD_1):
  106. break
  107. if self.appear(self.I_CRAFTING_EMPTY) or self.appear(self.I_CRAFTING_EMPTY_NEW):
  108. if self.appear_then_click(self.I_CRAFTING_CARD_STAR_1, interval=1):
  109. timer.reset()
  110. continue
  111. else:
  112. self.appear_then_click(self.I_CRAFTING_START, interval=3)
  113. count += 1
  114. timer.reset()
  115. continue
  116. logger.info('Finish star crafting')
  117. self.ui_click_until_disappear(self.I_UI_BACK_RED, interval=1)
  118. def find_demon(self) -> bool:
  119. """
  120. 召唤鬼王
  121. @return:
  122. """
  123. logger.info('Find demon')
  124. while 1:
  125. self.screenshot()
  126. if self.appear(self.I_BATTLE_DEMON) and not self.appear(self.I_BOSS_EMPTY):
  127. break
  128. if self.appear_then_click(self.I_FIND_DEMON, interval=3.5):
  129. continue
  130. self.screenshot()
  131. return True
  132. def battle_boss(self) -> bool:
  133. logger.info('Battle boss')
  134. self.ui_click_until_disappear(self.I_BATTLE_DEMON, interval=1.8)
  135. battle_config = GeneralBattleConfig()
  136. battle_config.lock_team_enable = False
  137. if self.run_general_battle(battle_config):
  138. return True
  139. return False
  140. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  141. # 重写
  142. self.device.stuck_record_add('BATTLE_STATUS_S')
  143. self.device.click_record_clear()
  144. logger.info("Start battle process")
  145. while 1:
  146. self.screenshot()
  147. # if self.appear_then_click(self.I_WIN, interval=1):
  148. # continue
  149. if self.appear(self.I_WIN):
  150. logger.info('Win battle')
  151. self.ui_click_until_disappear(self.I_WIN)
  152. return True
  153. if self.appear(self.I_MD_BATTLE_FAILURE):
  154. logger.warning('False battle')
  155. self.ui_click_until_disappear(self.I_MD_BATTLE_FAILURE)
  156. return False
  157. if __name__ == '__main__':
  158. from module.config.config import Config
  159. from module.device.device import Device
  160. c = Config('oas1')
  161. d = Device(c)
  162. t = ScriptTask(c, d)
  163. t.run()
  164. # t.screenshot()
  165. # print(t.current_exhaustion())