moon_sea.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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_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. logger.info("Start Roguelike")
  139. while 1:
  140. self.screenshot()
  141. if self.appear(self.I_M_STORE):
  142. break
  143. if self.appear_then_click(self.I_MFIRST_SKILL, interval=1):
  144. continue
  145. # 选中第一个柔风
  146. logger.info("Select first skill")
  147. def island_name(self) -> MoonSeaType:
  148. while 1:
  149. self.screenshot()
  150. text = self.O_ISLAND_NAME.ocr(self.device.image)
  151. if '星' in text:
  152. return MoonSeaType.island105
  153. if '战' in text:
  154. return MoonSeaType.island104
  155. if '混' in text:
  156. return MoonSeaType.island103
  157. if '神秘' in text:
  158. return MoonSeaType.island102
  159. if '宁息' in text:
  160. return MoonSeaType.island101
  161. def boss_team_lock(self):
  162. while 1:
  163. self.screenshot()
  164. if self.appear(self.I_BOSS_TEAM_LOCK):
  165. break
  166. if self.appear_then_click(self.I_BOSS_TEAM_UNLOCK, interval=2):
  167. logger.info('Click lock Boss Team')
  168. continue
  169. def boss_battle(self) -> bool:
  170. logger.hr('Boss Battle')
  171. self.ui_click_until_disappear(self.I_BOSS_FIRE, interval=1)
  172. self.device.stuck_record_clear()
  173. self.device.stuck_record_add('BATTLE_STATUS_S')
  174. while 1:
  175. self.screenshot()
  176. if self.appear(self.I_BOSS_SHARE):
  177. break
  178. if self.appear(self.I_BOSS_BATTLE_GIVEUP):
  179. # 打boss失败了
  180. logger.warning('Boss battle give up')
  181. self.ui_click_until_disappear(self.I_BOSS_BATTLE_GIVEUP, interval=1)
  182. continue
  183. if self.appear(self.I_BOSS_USE_DOUBLE, interval=1):
  184. # 双倍奖励
  185. logger.info('Double reward')
  186. self.ui_get_reward(self.I_BOSS_USE_DOUBLE)
  187. if self.ui_reward_appear_click():
  188. continue
  189. if self.appear_then_click(self.I_BOSS_GET_EXP, interval=1):
  190. logger.info('Get EXP')
  191. continue
  192. if self.appear_then_click(self.I_UI_CANCEL, interval=1):
  193. # 取消购买 万相赐福
  194. continue
  195. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
  196. continue
  197. if self.appear_then_click(self.I_BOSS_SKIP, interval=1):
  198. # 第二个boss
  199. self.device.stuck_record_clear()
  200. self.device.stuck_record_add('BATTLE_STATUS_S')
  201. continue
  202. logger.info('Boss battle end')
  203. if self.wait_until_appear(self.I_BOSS_SHUTU, wait_time=20):
  204. self.ui_click(self.I_BOSS_SHUTU, stop=self.I_MSTART)
  205. return True
  206. if __name__ == '__main__':
  207. from module.config.config import Config
  208. from module.device.device import Device
  209. c = Config('oas1')
  210. d = Device(c)
  211. t = MoonSea(c, d)
  212. t.screenshot()
  213. t.one()