moon_sea.py 9.5 KB

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