moon_sea.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import time
  2. from module.logger import logger
  3. from cached_property import cached_property
  4. from datetime import datetime, timedelta
  5. from tasks.SixRealms.moon_sea.map import MoonSeaMap
  6. from tasks.SixRealms.moon_sea.l101 import MoonSeaL101
  7. from tasks.SixRealms.moon_sea.l102 import MoonSeaL102
  8. from tasks.SixRealms.moon_sea.l103 import MoonSeaL103
  9. from tasks.SixRealms.moon_sea.l104 import MoonSeaL104
  10. from tasks.SixRealms.moon_sea.l105 import MoonSeaL105
  11. from tasks.SixRealms.common import MoonSeaType
  12. class MoonSea(MoonSeaMap, MoonSeaL101, MoonSeaL102, MoonSeaL103, MoonSeaL104, MoonSeaL105):
  13. @cached_property
  14. def island_func(self) -> dict:
  15. return {
  16. MoonSeaType.island101: self.run_l101(),
  17. MoonSeaType.island102: self.run_l102(),
  18. MoonSeaType.island103: self.run_103(),
  19. MoonSeaType.island104: self.run_l104(),
  20. MoonSeaType.island105: self.run_l105(),
  21. }
  22. @property
  23. def _conf(self):
  24. return self.config.model.six_realms.six_realms_gate
  25. def _run_moon_sea(self):
  26. # 在六道界面
  27. limit_time = self._conf.limit_time
  28. max_cont = self._conf.limit_count
  29. max_time: timedelta = timedelta(
  30. hours=limit_time.hour,
  31. minutes=limit_time.minute,
  32. seconds=limit_time.second
  33. )
  34. cnt = 0
  35. while 1:
  36. if cnt >= max_cont:
  37. logger.info('Run out of count, exit')
  38. break
  39. if datetime.now() - self.start_time >= max_time:
  40. logger.info('Run out of time, exit')
  41. break
  42. self.one()
  43. cnt += 1
  44. logger.info('Exit Moon Sea')
  45. def one(self):
  46. self.cnt_skill101 = 1
  47. self._start()
  48. while 1:
  49. self.screenshot()
  50. if not self.in_main():
  51. continue
  52. isl_type, isl_num, isl_roi = self.decide()
  53. if isl_num == 1 and isl_type != MoonSeaType.island106:
  54. # 如果前一个,召唤一次宁息
  55. if self.cnt_skill101 >= 5:
  56. # 如果柔风满级就不召唤
  57. pass
  58. elif self.appear(self.I_M_STORE):
  59. # 如果没有三百块就不能召唤
  60. logger.info('There have no money to active store at the last island')
  61. pass
  62. else:
  63. self.activate_store()
  64. self.wait_animate_stable(self.C_MAIN_ANIMATE_KEEP, timeout=3)
  65. isl_type, isl_num, isl_roi = self.decide()
  66. # 文字检测不一定发现到宁息
  67. if isl_type != MoonSeaType.island101:
  68. logger.warning('OCR not found island101')
  69. logger.warning('Try to entry the island in the right randomly order')
  70. self.entry_island_random()
  71. # 如果是boss
  72. if isl_type == MoonSeaType.island106:
  73. self.boss_team_lock()
  74. if self.boss_battle():
  75. break
  76. else:
  77. continue
  78. self.enter_island(isl_type=isl_type, isl_roi=isl_roi)
  79. isl_type = self.island_name()
  80. match isl_type:
  81. case MoonSeaType.island101: self.run_l101()
  82. case MoonSeaType.island102: self.run_l102()
  83. case MoonSeaType.island103: self.run_103()
  84. case MoonSeaType.island104: self.run_l104()
  85. case MoonSeaType.island105: self.run_l105()
  86. self.wait_animate_stable(self.C_MAIN_ANIMATE_KEEP, timeout=3)
  87. continue
  88. def _continue(self):
  89. logger.warning('Moon Sea Continue')
  90. while 1:
  91. self.screenshot()
  92. if self.in_main():
  93. break
  94. if self.appear(self.I_SELECT_SHIKIGAMI_AND_CONFIRM):
  95. self.select_shikigami_and_confirm()
  96. continue
  97. if self.appear_then_click(self.I_MCONINUE, interval=1):
  98. continue
  99. def _start(self):
  100. logger.hr('Moon Sea', 1)
  101. while 1:
  102. self.screenshot()
  103. if self.appear(self.I_MSTART):
  104. break
  105. if self.appear_then_click(self.I_MENTER, interval=1):
  106. continue
  107. if self.appear(self.I_MCONINUE):
  108. # 继续上一把的
  109. self._continue()
  110. return
  111. logger.info("Ensure select ShouZu")
  112. while 1:
  113. self.screenshot()
  114. if self.appear(self.I_MSHOUZU):
  115. break
  116. if self.appear_then_click(self.I_MSHUTEN, interval=3):
  117. continue
  118. if self.appear_then_click(self.I_MSHOUZU_SELECT, interval=1):
  119. continue
  120. logger.info("Ensure selected ShouZu")
  121. while 1:
  122. self.screenshot()
  123. if self.appear(self.I_PREPARE_BATTLE):
  124. break
  125. if self.appear_then_click(self.I_MSTART_UNCHECK, interval=0.6):
  126. continue
  127. if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
  128. continue
  129. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
  130. continue
  131. if self.appear_then_click(self.I_MSKIP, interval=1.5):
  132. continue
  133. if self.appear_then_click(self.I_MSTART, interval=3):
  134. continue
  135. if self.appear_then_click(self.I_MSTART_CONFIRM, interval=3):
  136. continue
  137. if self.appear_then_click(self.I_MSTART_CONFIRM2, interval=3):
  138. continue
  139. if self.appear_then_click(self.I_MCONINUE, interval=3):
  140. continue
  141. # Hook: select one shikigami and confirm before starting
  142. if self.appear(self.I_SELECT_SHIKIGAMI_AND_CONFIRM):
  143. self.select_shikigami_and_confirm()
  144. logger.info("Start Roguelike")
  145. while 1:
  146. self.screenshot()
  147. if self.appear(self.I_M_STORE):
  148. break
  149. if self.appear_then_click(self.I_MFIRST_SKILL, interval=1):
  150. continue
  151. # 选中第一个柔风
  152. logger.info("Select first skill")
  153. def island_name(self) -> MoonSeaType:
  154. while 1:
  155. self.screenshot()
  156. text = self.O_ISLAND_NAME.ocr(self.device.image)
  157. if '星' in text:
  158. return MoonSeaType.island105
  159. if '战' in text:
  160. return MoonSeaType.island104
  161. if '混' in text:
  162. return MoonSeaType.island103
  163. if '神秘' in text:
  164. return MoonSeaType.island102
  165. if '宁息' in text:
  166. return MoonSeaType.island101
  167. def boss_team_lock(self):
  168. while 1:
  169. self.screenshot()
  170. if self.appear(self.I_BOSS_TEAM_LOCK):
  171. break
  172. if self.appear_then_click(self.I_BOSS_TEAM_UNLOCK, interval=2):
  173. logger.info('Click lock Boss Team')
  174. continue
  175. def boss_battle(self) -> bool:
  176. logger.hr('Boss Battle')
  177. self.ui_click_until_disappear(self.I_BOSS_FIRE, interval=1)
  178. self.device.stuck_record_clear()
  179. self.device.stuck_record_add('BATTLE_STATUS_S')
  180. while 1:
  181. self.screenshot()
  182. if self.appear(self.I_BOSS_SHARE):
  183. break
  184. if self.appear(self.I_BOSS_BATTLE_GIVEUP):
  185. # 打boss失败了
  186. logger.warning('Boss battle give up')
  187. self.ui_click_until_disappear(self.I_BOSS_BATTLE_GIVEUP, interval=1)
  188. continue
  189. if self.appear(self.I_BOSS_USE_DOUBLE, interval=1):
  190. # 双倍奖励
  191. logger.info('Double reward')
  192. self.ui_get_reward(self.I_BOSS_USE_DOUBLE)
  193. if self.ui_reward_appear_click():
  194. continue
  195. if self.appear_then_click(self.I_BOSS_GET_EXP, interval=1):
  196. logger.info('Get EXP')
  197. continue
  198. if self.appear_then_click(self.I_UI_CANCEL, interval=1):
  199. # 取消购买 万相赐福
  200. continue
  201. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
  202. continue
  203. if self.appear_then_click(self.I_BOSS_SKIP, interval=1):
  204. # 第二个boss
  205. self.device.stuck_record_clear()
  206. self.device.stuck_record_add('BATTLE_STATUS_S')
  207. continue
  208. logger.info('Boss battle end')
  209. if self.wait_until_appear(self.I_BOSS_SHUTU, wait_time=20):
  210. self.ui_click(self.I_BOSS_SHUTU, stop=self.I_MSTART)
  211. return True
  212. def select_shikigami_and_confirm(self):
  213. """Select shikigami and confirm to start battle."""
  214. while True:
  215. self.screenshot()
  216. if not self.appear(self.I_SELECT_SHIKIGAMI_AND_CONFIRM):
  217. break
  218. self.swipe(self.S_TEAM_SWIPE_UP)
  219. self.appear_then_click(self.I_MSTART_CONFIRM, interval=2)
  220. self.appear_then_click(self.I_COIN2, interval=2)
  221. if __name__ == '__main__':
  222. from module.config.config import Config
  223. from module.device.device import Device
  224. c = Config('oas1')
  225. d = Device(c)
  226. t = MoonSea(c, d)
  227. t.screenshot()
  228. t.one()