moon_sea.py 8.9 KB

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