script_task.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 timedelta, datetime, time
  6. from cached_property import cached_property
  7. from module.exception import TaskEnd
  8. from module.logger import logger
  9. from module.base.timer import Timer
  10. from tasks.GameUi.game_ui import GameUi
  11. from tasks.GameUi.page import page_main, page_shikigami_records
  12. from tasks.SoulsTidy.assets import SoulsTidyAssets
  13. from tasks.SoulsTidy.config import SimpleTidy
  14. class ScriptTask(GameUi, SoulsTidyAssets):
  15. def run(self):
  16. self.ui_get_current_page()
  17. self.ui_goto(page_shikigami_records)
  18. con = self.config.souls_tidy
  19. if con.simple_tidy.greed_maneki:
  20. self.goto_souls()
  21. self.greed_maneki()
  22. self.back_records()
  23. self.set_next_run(task='SoulsTidy', success=True, finish=False)
  24. raise TaskEnd('SoulsTidy')
  25. def goto_souls(self):
  26. """
  27. 进入到御魂的主界面
  28. :return:
  29. """
  30. while 1:
  31. self.screenshot()
  32. if self.appear(self.I_ST_GREED) and self.appear(self.I_ST_TIDY):
  33. break
  34. if self.appear_then_click(self.I_ST_REPLACE, interval=1):
  35. continue
  36. if self.appear_then_click(self.I_ST_SOULS, interval=1):
  37. continue
  38. if self.click(self.C_ST_DETAIL, interval=1.5):
  39. continue
  40. logger.info('Enter souls page')
  41. def back_records(self):
  42. """
  43. 退回到式神录
  44. :return:
  45. """
  46. self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_RECORDS)
  47. def greed_maneki(self):
  48. """
  49. 贪吃鬼和招财猫
  50. :return:
  51. """
  52. # 先是贪吃鬼
  53. logger.hr('Greed Ghost')
  54. self.ui_click(self.I_ST_GREED, self.I_ST_GREED_HABIT)
  55. self.ui_click(self.I_ST_GREED_HABIT, self.I_ST_FEED_NOW)
  56. logger.info('Feed greed ghost')
  57. feed_count = 0
  58. while 1:
  59. self.screenshot()
  60. if self.appear(self.I_ST_UNSELECTED):
  61. self.ui_click_until_disappear(self.I_ST_UNSELECTED)
  62. continue
  63. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
  64. continue
  65. if feed_count >= 3:
  66. break
  67. if self.appear_then_click(self.I_ST_FEED_NOW, interval=1.9):
  68. feed_count += 1
  69. continue
  70. logger.info('Feed greed ghost done')
  71. # 关闭贪吃鬼, 进入奉纳
  72. while 1:
  73. self.screenshot()
  74. if self.appear(self.I_ST_CAT):
  75. # 出现招财猫
  76. break
  77. if self.appear_then_click(self.I_ST_GREED_CLOSE, interval=0.7):
  78. continue
  79. if self.appear_then_click(self.I_ST_BONGNA, interval=1, threshold=0.6):
  80. continue
  81. logger.hr('Enter bongna')
  82. # 确保是按照等级来排序的
  83. while 1:
  84. self.screenshot()
  85. if self.ocr_appear(self.O_ST_SORT_LEVEL_1):
  86. break
  87. if self.ocr_appear_click(self.O_ST_SORT_LEVEL_2, interval=0.6):
  88. continue
  89. if self.ocr_appear_click(self.O_ST_SORT_TIME, interval=2):
  90. continue
  91. if self.ocr_appear_click(self.O_ST_SORT_TYPE, interval=2):
  92. continue
  93. if self.ocr_appear_click(self.O_ST_SORT_LOCATION, interval=2):
  94. continue
  95. logger.info('Sort by level')
  96. # 开始奉纳
  97. while 1:
  98. self.screenshot()
  99. firvel = self.O_ST_FIRSET_LEVEL.ocr(self.device.image)
  100. if firvel != '古':
  101. # 问就是 把 +0 识别成了 古
  102. logger.info('No zero level, bongna done')
  103. break
  104. # !!!!!! 这里没有检查金币是否足够
  105. # 长按
  106. while 1:
  107. self.screenshot()
  108. self.click(self.L_ONE, interval=2.5)
  109. gold_amount = self.O_ST_GOLD.ocr(self.device.image)
  110. if not isinstance(gold_amount, int):
  111. logger.warning('Gold amount not int, skip')
  112. continue
  113. if gold_amount > 0:
  114. break
  115. # 点击奉纳收取奖励
  116. if not self.appear(self.I_ST_DONATE):
  117. logger.warning('Donate button not appear, skip')
  118. continue
  119. while 1:
  120. self.screenshot()
  121. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
  122. continue
  123. # 出现神赐, 就点击然后消失,
  124. if self.appear(self.I_ST_GOD_PRESENT):
  125. sleep(0.5)
  126. self.screenshot()
  127. if not self.appear(self.I_ST_GOD_PRESENT):
  128. continue
  129. while 1:
  130. self.screenshot()
  131. if not self.appear(self.I_ST_GOD_PRESENT):
  132. break
  133. if self.click(self.C_ST_GOD_PRSENT, interval=1):
  134. continue
  135. sleep(0.5)
  136. break
  137. if self.appear_then_click(self.I_ST_DONATE, interval=3.5):
  138. continue
  139. logger.info('Donate one')
  140. logger.info('Bongna done')
  141. if __name__ == '__main__':
  142. from module.config.config import Config
  143. from module.device.device import Device
  144. c = Config('oas1')
  145. d = Device(c)
  146. t = ScriptTask(c, d)
  147. t.screenshot()
  148. # t.greed_maneki()
  149. t.run()