script_task.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.goto_page(page_shikigami_records)
  17. con = self.config.souls_tidy
  18. if con.simple_tidy.enable_greed or con.simple_tidy.enable_maneki:
  19. self.goto_souls()
  20. self.greed_maneki()
  21. self.back_records()
  22. self.set_next_run(task='SoulsTidy', success=True, finish=False)
  23. raise TaskEnd('SoulsTidy')
  24. def goto_souls(self):
  25. """
  26. 进入到御魂的主界面
  27. :return:
  28. """
  29. while 1:
  30. self.screenshot()
  31. if self.appear(self.I_ST_GREED) and self.appear(self.I_ST_TIDY):
  32. break
  33. if self.appear_then_click(self.I_ST_REPLACE, interval=1):
  34. continue
  35. if self.appear_then_click(self.I_ST_SOULS, interval=1):
  36. continue
  37. if self.appear_then_click(self.I_ST_SOULS_CLOSE, interval=1):
  38. continue
  39. if self.click(self.C_ST_DETAIL, interval=2):
  40. continue
  41. # 御魂超过上限的提示
  42. self.ocr_appear_click(self.O_ST_OVERFLOW)
  43. logger.info('Enter souls page')
  44. def back_records(self):
  45. """
  46. 退回到式神录
  47. :return:
  48. """
  49. self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_RECORDS)
  50. def greed_maneki(self):
  51. """
  52. 贪吃鬼和招财猫
  53. :return:
  54. """
  55. # 先是贪吃鬼
  56. if self.config.souls_tidy.simple_tidy.enable_greed:
  57. logger.hr('Greed Ghost')
  58. self.ui_click(self.I_ST_GREED, self.I_ST_GREED_HABIT)
  59. self.ui_click(self.I_ST_GREED_HABIT, self.I_ST_FEED_NOW)
  60. logger.info('Feed greed ghost')
  61. feed_count = 0
  62. while 1:
  63. self.screenshot()
  64. if self.appear(self.I_ST_UNSELECTED):
  65. self.ui_click_until_disappear(self.I_ST_UNSELECTED)
  66. continue
  67. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
  68. continue
  69. if feed_count >= 3:
  70. break
  71. if self.appear_then_click(self.I_ST_FEED_NOW, interval=3.5):
  72. feed_count += 1
  73. continue
  74. logger.info('Feed greed ghost done')
  75. # 关闭贪吃鬼, 进入奉纳
  76. while 1:
  77. self.screenshot()
  78. if self.appear(self.I_ST_CAT):
  79. # 出现招财猫
  80. break
  81. # https://github.com/runhey/OnmyojiAutoScript/issues/662
  82. if self.appear(self.I_ST_UNSELECTED):
  83. self.ui_click_until_disappear(self.I_ST_UNSELECTED)
  84. continue
  85. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
  86. continue
  87. if self.appear_then_click(self.I_ST_GREED_CLOSE, interval=0.7):
  88. continue
  89. if self.appear_then_click(self.I_ST_BONGNA, interval=1, threshold=0.6):
  90. continue
  91. if self.config.souls_tidy.simple_tidy.enable_maneki:
  92. """
  93. """
  94. logger.hr('Enter bongna')
  95. # 确保已弃置界面
  96. while 1:
  97. self.screenshot()
  98. if self.appear(self.I_ST_ABANDONED_SELECTED):
  99. break
  100. self.click(self.I_ST_ABANDONED_SELECTED, interval=1.5)
  101. # 确保是按照等级来排序的
  102. while 1:
  103. self.screenshot()
  104. if self.ocr_appear(self.O_ST_SORT_LEVEL_1):
  105. break
  106. if self.ocr_appear_click(self.O_ST_SORT_LEVEL_2, interval=0.6):
  107. continue
  108. if self.ocr_appear_click(self.O_ST_SORT_TIME, interval=2):
  109. continue
  110. if self.ocr_appear_click(self.O_ST_SORT_TYPE, interval=2):
  111. continue
  112. if self.ocr_appear_click(self.O_ST_SORT_LOCATION, interval=2):
  113. continue
  114. logger.info('Sort by level')
  115. # 开始奉纳
  116. while 1:
  117. if (self.wait_until_appear(self.I_ST_SOUL_STACK, wait_time=2) or
  118. self.wait_until_appear(self.I_ST_SOUL_STACK_1, wait_time=2)):
  119. # 方式1. 御魂堆叠奉纳
  120. logger.info('Soul stack')
  121. else:
  122. # 方式2. 强化+0奉纳
  123. self.wait_until_appear(self.I_ST_LEVEL_0, wait_time=2)
  124. self.screenshot()
  125. # 非+0的不弃置 双保险
  126. if not self.appear(self.I_ST_LEVEL_0):
  127. logger.info("First Orichi isn't Level 0,quit")
  128. break
  129. firvel = self.O_ST_FIRSET_LEVEL.ocr(self.device.image)
  130. if firvel is None or firvel == '':
  131. logger.info('ocr result is Null')
  132. continue
  133. if (firvel != '古') and (firvel != '+0'):
  134. # 问就是 把 +0 识别成了 古
  135. logger.info('No zero level, bongna done')
  136. break
  137. # !!!!!! 这里没有检查金币是否足够
  138. # 长按
  139. self.click(self.L_ONE, interval=2.5)
  140. self.screenshot()
  141. gold_amount = self.O_ST_GOLD.ocr(self.device.image)
  142. if not isinstance(gold_amount, int):
  143. logger.warning('Gold amount not int, skip')
  144. continue
  145. if gold_amount == 0:
  146. continue
  147. # 点击奉纳收取奖励
  148. if not self.appear(self.I_ST_DONATE):
  149. logger.warning('Donate button not appear, skip')
  150. continue
  151. # 点击奉纳 及收取奖励
  152. while 1:
  153. self.screenshot()
  154. if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
  155. continue
  156. # 如果奉纳少就不是神赐而是获得奖励
  157. if self.ui_reward_appear_click():
  158. continue
  159. # 出现神赐, 就点击然后消失,
  160. if self.appear(self.I_ST_GOD_PRESENT):
  161. logger.info('God present appear')
  162. self.click(self.C_ST_GOD_PRSENT, interval=2)
  163. continue
  164. elif self.appear(self.I_ST_LUCK):
  165. # 出现吉运
  166. logger.info('luck appear')
  167. self.click(self.C_ST_SOUL_OFFERING_REWARD, interval=2)
  168. continue
  169. elif self.appear(self.I_ST_SMALL_LUCK):
  170. # 出现小吉运
  171. logger.info('small luck appear')
  172. self.click(self.C_ST_SOUL_OFFERING_REWARD, interval=2)
  173. continue
  174. if self.appear_then_click(self.I_ST_DONATE, interval=5.5):
  175. self.wait_until_appear(self.I_ST_GOLD, True, wait_time=5)
  176. continue
  177. if not self.appear(self.I_ST_GOLD):
  178. break
  179. logger.info('Donate one')
  180. logger.info('Bongna done')
  181. if __name__ == '__main__':
  182. from module.config.config import Config
  183. from module.device.device import Device
  184. c = Config('oas1')
  185. d = Device(c)
  186. t = ScriptTask(c, d)
  187. #t.greed_maneki()
  188. t.run()