script_task.py 8.0 KB

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