map.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import cv2
  2. import re
  3. import numpy as np
  4. from numpy import uint8, fromfile
  5. from module.logger import logger
  6. from tasks.base_task import BaseTask
  7. from tasks.SixRealms.moon_sea.skills import MoonSeaSkills
  8. from tasks.SixRealms.assets import SixRealmsAssets
  9. from tasks.SixRealms.common import MoonSeaType
  10. from tasks.SixRealms.oas_ocr import StoneOcr
  11. class MoonSeaMap(MoonSeaSkills):
  12. map_ocr = StoneOcr(
  13. roi=(0, 0, 1280, 720),
  14. area=(0, 0, 1280, 720),
  15. mode="Full",
  16. method="Default",
  17. keyword="",
  18. name="map_ocr")
  19. @staticmethod
  20. def contains_any_char(string, chars):
  21. return not set(string).isdisjoint(set(chars))
  22. def decide(self) -> tuple:
  23. """
  24. 这个玩意,检测不是很准
  25. @return: 岛屿的类型,剩余多少回合, (x,y, w, h)
  26. """
  27. self.screenshot()
  28. if self.appear(self.I_BOSS_FIRE):
  29. # 最后的boss
  30. return MoonSeaType.island106, 0, (0, 0, 0, 0)
  31. isl_type = MoonSeaType.island100
  32. isl_roi = (0, 0, 0, 0)
  33. isl_num = 0
  34. results = self.map_ocr.detect_and_ocr(image=self.device.image)
  35. rx1, ry1, rw, rh = self.O_OCR_MAP.roi
  36. rx2, ry2 = rx1 + rw, ry1 + rh
  37. for result in results:
  38. # box 是四个点坐标 左上, 右上, 右下, 左下
  39. x1, y1, x2, y2 = result.box[0][0], result.box[0][1], result.box[2][0], result.box[2][1]
  40. w, h = x2 - x1, y2 - y1
  41. text = result.ocr_text
  42. if self.contains_any_char(result.ocr_text, chars='回合国') and \
  43. (x1 > 1000 and y1 + h < 300):
  44. # if text[1].isdigit():
  45. # isl_num = int(text[:2])
  46. # elif text[0].isdigit():
  47. # isl_num = int(text[0])
  48. match = re.search(r'\d{1,2}', text)
  49. if match:
  50. isl_num = int(match.group())
  51. if x1 < rx1 or x2 > rx2 or y1 < ry1 or y2 > ry2:
  52. continue
  53. if isl_type == MoonSeaType.island100 and self.contains_any_char(result.ocr_text, chars='宁息'):
  54. # 如果身上没有达到300块钱就不去了
  55. if self.appear(self.I_M_STORE):
  56. continue
  57. isl_type = MoonSeaType.island101
  58. isl_roi = x1, y1, w, h
  59. elif isl_type == MoonSeaType.island100 and self.contains_any_char(result.ocr_text, chars='神秘'):
  60. isl_type = MoonSeaType.island102
  61. isl_roi = x1, y1, w, h
  62. elif isl_type == MoonSeaType.island100 and self.contains_any_char(result.ocr_text, chars='回混范'):
  63. isl_type = MoonSeaType.island103
  64. isl_roi = x1, y1, w, h
  65. elif isl_type == MoonSeaType.island100 and self.contains_any_char(result.ocr_text, chars='蜜馨屡战'):
  66. isl_type = MoonSeaType.island104
  67. isl_roi = x1, y1, w, h
  68. elif isl_type == MoonSeaType.island100 and self.contains_any_char(result.ocr_text, chars='星之'):
  69. isl_type = MoonSeaType.island105
  70. isl_roi = x1, y1, w, h
  71. logger.info('Island type: {}, Residue: {}, ROI: {}'.format(isl_type, isl_num, isl_roi))
  72. return isl_type, isl_num, isl_roi
  73. def enter_island(self, isl_type, isl_roi):
  74. if isl_type == MoonSeaType.island100:
  75. logger.warning('The island type was not recognized')
  76. logger.warning('Pick one at random, starting from the right')
  77. while 1:
  78. self.screenshot()
  79. if not self.in_main() and self.appear(self.I_BACK_EXIT):
  80. break
  81. if self.click(self.C_ISLAND_ENTER_1, interval=2):
  82. continue
  83. if self.click(self.C_ISLAND_ENTER_2, interval=2):
  84. continue
  85. if self.click(self.C_ISLAND_ENTER_3, interval=2):
  86. continue
  87. if self.click(self.C_ISLAND_ENTER_4, interval=2):
  88. continue
  89. if self.click(self.C_ISLAND_ENTER_5, interval=2):
  90. continue
  91. if self.click(self.C_ISLAND_ENTER_6, interval=2):
  92. continue
  93. logger.info('Entering island randomly')
  94. return
  95. isl_roi = [isl_roi[0]-40, isl_roi[1] + 70, isl_roi[2] + 40, isl_roi[3]+40]
  96. self.C_ISLAND_ENTER.roi_front = isl_roi
  97. while 1:
  98. self.screenshot()
  99. if not self.in_main() and self.appear(self.I_BACK_EXIT):
  100. break
  101. if self.click(self.C_ISLAND_ENTER, interval=2.5):
  102. continue
  103. logger.info('Entering island')
  104. return
  105. def activate_store(self) -> bool:
  106. """
  107. 最后打boss前面激活一次商店买东西
  108. @return: 有钱够就是True
  109. """
  110. logger.info('Activating store')
  111. self.screenshot()
  112. if self.appear(self.I_M_STORE) and not self.appear(self.I_M_STORE_ACTIVITY):
  113. logger.warning('Now you have not money to buy items')
  114. logger.warning('Store is not active')
  115. return False
  116. cnt_act = 0
  117. while 1:
  118. self.screenshot()
  119. if self.appear(self.I_UI_CONFIRM):
  120. self.ui_click_until_disappear(self.I_UI_CONFIRM, interval=2)
  121. break
  122. if cnt_act >= 3:
  123. logger.warning('Store is not active')
  124. return False
  125. if self.appear_then_click(self.I_M_STORE_ACTIVITY, interval=1.5):
  126. cnt_act += 1
  127. continue
  128. def entry_island_random(self, area: list = None):
  129. """
  130. :param area: 搁置
  131. :return:
  132. """
  133. # if not isinstance(area, list):
  134. # area = list(area)
  135. logger.info('Entry island randomly')
  136. while 1:
  137. self.screenshot()
  138. if not self.in_main() and self.appear(self.I_BACK_EXIT):
  139. break
  140. if self.click(self.C_ISLAND_ENTER_4, interval=2):
  141. continue
  142. if self.click(self.C_ISLAND_ENTER_5, interval=2):
  143. continue
  144. if self.click(self.C_ISLAND_ENTER_6, interval=2):
  145. continue
  146. return
  147. if __name__ == '__main__':
  148. from module.config.config import Config
  149. from module.device.device import Device
  150. from module.base.utils import load_image
  151. c = Config('oas1')
  152. d = Device(c)
  153. t = MoonSeaMap(c, d)
  154. t.device.image = load_image(r'C:\Users\Ryland\Desktop\Desktop\34.png')
  155. match = re.search(r'\d{1,2}', '<17回合后迎战月读')
  156. if match:
  157. isl_num = int(match.group())
  158. print(isl_num)