moon_sea.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. # 选完技能还有「获得新技能」转场,先等地图稳定,免得把转场帧的坐标当成岛屿位置。
  49. self.wait_animate_stable(self.C_MAIN_ANIMATE_KEEP, timeout=3)
  50. while 1:
  51. self.screenshot()
  52. if not self.in_main():
  53. continue
  54. isl_type, isl_num, isl_roi = self.decide()
  55. if isl_num == 1 and isl_type != MoonSeaType.island106:
  56. # 如果前一个,召唤一次宁息
  57. if self.cnt_skill101 >= 5:
  58. # 如果柔风满级就不召唤
  59. pass
  60. elif self.appear(self.I_M_STORE):
  61. # 如果没有三百块就不能召唤
  62. logger.info('There have no money to active store at the last island')
  63. pass
  64. else:
  65. self.activate_store()
  66. self.wait_animate_stable(self.C_MAIN_ANIMATE_KEEP, timeout=3)
  67. isl_type, isl_num, isl_roi = self.decide(prefer_store=True)
  68. # 如果是boss
  69. if isl_type == MoonSeaType.island106:
  70. self.boss_team_lock()
  71. if self.boss_battle():
  72. break
  73. else:
  74. continue
  75. self.enter_island(isl_type=isl_type, isl_roi=isl_roi)
  76. isl_type = self.island_name()
  77. match isl_type:
  78. case MoonSeaType.island101: self.run_l101()
  79. case MoonSeaType.island102: self.run_l102()
  80. case MoonSeaType.island103: self.run_103()
  81. case MoonSeaType.island104: self.run_l104()
  82. case MoonSeaType.island105: self.run_l105()
  83. self.wait_animate_stable(self.C_MAIN_ANIMATE_KEEP, timeout=3)
  84. continue
  85. def _continue(self):
  86. logger.warning('Moon Sea Continue')
  87. while 1:
  88. self.screenshot()
  89. if self.in_main():
  90. break
  91. if self.appear(self.I_SELECT_SHIKIGAMI_AND_CONFIRM):
  92. self.select_shikigami_and_confirm()
  93. continue
  94. if self.appear_then_click(self.I_MCONINUE, interval=1):
  95. continue
  96. def _start(self):
  97. logger.hr('Moon Sea', 1)
  98. while 1:
  99. self.screenshot()
  100. if self.appear(self.I_MSTART):
  101. break
  102. if self.appear_then_click(self.I_MENTER, interval=1):
  103. continue
  104. if self.appear(self.I_MCONINUE):
  105. # 继续上一把的
  106. self._continue()
  107. return
  108. logger.info("Ensure select ShouZu")
  109. while 1:
  110. self.screenshot()
  111. if self.appear(self.I_MSHOUZU):
  112. break
  113. if self.appear_then_click(self.I_MSHUTEN, interval=3):
  114. continue
  115. if self.appear_then_click(self.I_MSHOUZU_SELECT, interval=1):
  116. continue
  117. logger.info("Ensure selected ShouZu")
  118. while 1:
  119. self.screenshot()
  120. if self.appear(self.I_PREPARE_BATTLE):
  121. break
  122. if self.appear_then_click(self.I_MSTART_UNCHECK, interval=0.6):
  123. continue
  124. if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
  125. continue
  126. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
  127. continue
  128. if self.appear_then_click(self.I_MSKIP, interval=1.5):
  129. continue
  130. if self.appear_then_click(self.I_MSTART, interval=3):
  131. continue
  132. if self.appear_then_click(self.I_MSTART_CONFIRM, interval=3):
  133. continue
  134. if self.appear_then_click(self.I_MSTART_CONFIRM2, interval=3):
  135. continue
  136. if self.appear_then_click(self.I_MCONINUE, interval=3):
  137. continue
  138. # Hook: select one shikigami and confirm before starting
  139. if self.appear(self.I_SELECT_SHIKIGAMI_AND_CONFIRM):
  140. self.select_shikigami_and_confirm()
  141. logger.info("Start Roguelike")
  142. while 1:
  143. self.screenshot()
  144. if self.appear(self.I_M_STORE):
  145. break
  146. if self.appear_then_click(self.I_MFIRST_SKILL, interval=1):
  147. continue
  148. # 选中第一个柔风
  149. logger.info("Select first skill")
  150. def island_name(self) -> MoonSeaType:
  151. while 1:
  152. self.screenshot()
  153. text = self.O_ISLAND_NAME.ocr(self.device.image)
  154. if '星' in text:
  155. return MoonSeaType.island105
  156. if '战' in text:
  157. return MoonSeaType.island104
  158. if '混' in text:
  159. return MoonSeaType.island103
  160. if '神秘' in text:
  161. return MoonSeaType.island102
  162. if '宁息' in text:
  163. return MoonSeaType.island101
  164. def boss_team_lock(self):
  165. while 1:
  166. self.screenshot()
  167. if self.appear(self.I_BOSS_TEAM_LOCK):
  168. break
  169. if self.appear_then_click(self.I_BOSS_TEAM_UNLOCK, interval=2):
  170. logger.info('Click lock Boss Team')
  171. continue
  172. def boss_battle(self) -> bool:
  173. logger.hr('Boss Battle')
  174. self.ui_click_until_disappear(self.I_BOSS_FIRE, interval=1)
  175. self.device.stuck_record_clear()
  176. self.device.stuck_record_add('BATTLE_STATUS_S')
  177. while 1:
  178. self.screenshot()
  179. if self.appear(self.I_BOSS_SHARE):
  180. break
  181. if self.appear(self.I_BOSS_BATTLE_GIVEUP):
  182. # 打boss失败了
  183. logger.warning('Boss battle give up')
  184. self.ui_click_until_disappear(self.I_BOSS_BATTLE_GIVEUP, interval=1)
  185. continue
  186. if self.appear(self.I_BOSS_USE_DOUBLE, interval=1):
  187. # 双倍奖励
  188. logger.info('Double reward')
  189. self.ui_get_reward(self.I_BOSS_USE_DOUBLE)
  190. if self.ui_reward_appear_click():
  191. continue
  192. if self.appear_then_click(self.I_BOSS_GET_EXP, interval=1):
  193. logger.info('Get EXP')
  194. continue
  195. if self.appear_then_click(self.I_UI_CANCEL, interval=1):
  196. # 取消购买 万相赐福
  197. continue
  198. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
  199. continue
  200. if self.appear_then_click(self.I_BOSS_SKIP, interval=1):
  201. # 第二个boss
  202. self.device.stuck_record_clear()
  203. self.device.stuck_record_add('BATTLE_STATUS_S')
  204. continue
  205. logger.info('Boss battle end')
  206. if self.wait_until_appear(self.I_BOSS_SHUTU, wait_time=20):
  207. self.ui_click(self.I_BOSS_SHUTU, stop=self.I_MSTART)
  208. return True
  209. def select_shikigami_and_confirm(self):
  210. """Select shikigami and confirm to start battle."""
  211. while True:
  212. self.screenshot()
  213. if not self.appear(self.I_SELECT_SHIKIGAMI_AND_CONFIRM):
  214. break
  215. self.swipe(self.S_TEAM_SWIPE_UP)
  216. self.appear_then_click(self.I_MSTART_CONFIRM, interval=2)
  217. self.appear_then_click(self.I_COIN2, interval=2)
  218. if __name__ == '__main__':
  219. from module.config.config import Config
  220. from module.device.device import Device
  221. c = Config('oas1')
  222. d = Device(c)
  223. t = MoonSea(c, d)
  224. t.screenshot()
  225. t.one()