shrine.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.logger import logger
  6. from module.base.timer import Timer
  7. from tasks.GameUi.page import page_main, page_summon
  8. from tasks.GameUi.game_ui import GameUi
  9. from tasks.RichMan.assets import RichManAssets
  10. from tasks.RichMan.config import Shrine as ConfigShrine
  11. class Shrine(GameUi, RichManAssets):
  12. def execute_shrine(self, con: ConfigShrine):
  13. logger.hr('Start Shrine')
  14. if not con.enable:
  15. logger.info('Shrine is disabled')
  16. return
  17. self.goto_page(page_summon)
  18. while 1:
  19. self.screenshot()
  20. if self.appear(self.I_S_NEXT_PERIOD):
  21. break
  22. if self.click(self.C_C_SHRINE, interval=2):
  23. continue
  24. # if self.appear_then_click(self.I_CENTER1, interval=1):
  25. # continue
  26. # if self.appear_then_click(self.I_CENTER2, interval=1):
  27. # continue
  28. logger.info('Enter Shrine')
  29. time.sleep(0.5)
  30. if con.black_daruma:
  31. self.shrine_black_daruma()
  32. if con.white_daruma_five:
  33. self.shrine_white_five()
  34. if con.white_daruma_four:
  35. self.shrine_white_four()
  36. def shrine_check_money(self, mix: int) -> bool:
  37. self.screenshot()
  38. current = self.O_TT_TOTOL.ocr(self.device.image)
  39. if not isinstance(current, int):
  40. logger.warning('OCR current money failed')
  41. return False
  42. if current >= mix:
  43. logger.info('Money is enough')
  44. return True
  45. logger.info('Money is not enough')
  46. return False
  47. def _check_bought(self, target) -> bool:
  48. """
  49. 检查是否已经购买, 弃用,无法识别任何文字
  50. :return: True 已经购买
  51. """
  52. self.screenshot()
  53. result = target.ocr(self.device.image)
  54. if '已' in result or '兑' in result or '换' in result:
  55. logger.info('Already bought')
  56. return True
  57. logger.info('Not bought')
  58. return False
  59. def shrine_black_daruma(self):
  60. logger.hr('Shrine black daruma', 2)
  61. self.screenshot()
  62. if not self.shrine_check_money(1500):
  63. return
  64. if not self.appear(self.I_S_BLACK):
  65. logger.info('Already bought black daruma')
  66. return
  67. # self.ui_click(self.I_S_BLACK, self.I_S_BUY_BLACK, interval=2, timeout=5)
  68. # self.screenshot()
  69. # if not self.appear(self.I_S_BUY_BLACK, threshold=0.6):
  70. # logger.info('Already bought black daruma')
  71. # self.ui_click_until_disappear(self.I_UI_BACK_RED)
  72. # time.sleep(0.5)
  73. # return
  74. # self.ui_click(self.I_S_BUY_BLACK, self.I_S_CONFIRM_BLACK)
  75. # self.ui_get_reward(self.I_S_CONFIRM_BLACK)
  76. timer = Timer(10).start()
  77. while 1:
  78. self.screenshot()
  79. if timer.reached():
  80. logger.warning('Reached time')
  81. break
  82. if self.ui_reward_appear_click():
  83. logger.info('Reward appear')
  84. break
  85. if self.appear_then_click(self.I_S_CONFIRM_BLACK, interval=1):
  86. continue
  87. if self.appear_then_click(self.I_S_BUY_BLACK, interval=1):
  88. continue
  89. if self.appear_then_click(self.I_S_BLACK, interval=2.5):
  90. continue
  91. self.ui_click_until_disappear(self.I_UI_BACK_RED)
  92. time.sleep(1)
  93. def shrine_white_five(self):
  94. logger.hr('Shrine white five', 2)
  95. self.screenshot()
  96. if not self.appear(self.I_S_WHITE_FIVE):
  97. logger.info('White five is not available')
  98. return
  99. if not self.shrine_check_money(1200):
  100. return
  101. timer = Timer(10).start()
  102. while 1:
  103. self.screenshot()
  104. if timer.reached():
  105. logger.warning('Reached time')
  106. break
  107. if self.ui_reward_appear_click():
  108. logger.info('Reward appear')
  109. break
  110. if self.appear_then_click(self.I_S_CONFIRM_WHITE_FIVE, interval=1):
  111. continue
  112. if self.appear_then_click(self.I_S_BUY_WHITE_FIVE, interval=1):
  113. continue
  114. if self.appear_then_click(self.I_S_WHITE_FIVE, interval=2.5):
  115. continue
  116. self.ui_click_until_disappear(self.I_UI_BACK_RED)
  117. time.sleep(1)
  118. def shrine_white_four(self):
  119. logger.hr('Shrine white four', 2)
  120. self.screenshot()
  121. if not self.appear(self.I_S_WHITE_FOUR):
  122. logger.info('White four is not available')
  123. return
  124. if not self.shrine_check_money(400):
  125. return
  126. timer = Timer(10).start()
  127. while 1:
  128. self.screenshot()
  129. if timer.reached():
  130. logger.warning('Reached time')
  131. break
  132. if self.ui_reward_appear_click():
  133. logger.info('Reward appear')
  134. break
  135. if self.appear_then_click(self.I_S_CONFIRM_WHITE_FOUR, interval=1):
  136. continue
  137. if self.appear_then_click(self.I_S_BUY_WHITE_FOUR, interval=1):
  138. continue
  139. if self.appear_then_click(self.I_S_WHITE_FOUR, interval=2.5):
  140. continue
  141. self.ui_click_until_disappear(self.I_UI_BACK_RED)
  142. time.sleep(1)
  143. if __name__ == '__main__':
  144. from module.config.config import Config
  145. from module.device.device import Device
  146. c = Config('oas1')
  147. d = Device(c)
  148. t = Shrine(c, d)
  149. # t.shrine_white_four()
  150. t.execute_shrine(t.config.model.rich_man.shrine)
  151. # t.screenshot()
  152. # print(t.appear(t.I_S_BUY_WHITE_FIVE, threshold=0.9))