map.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.appear_then_click(self.I_UI_CANCEL, interval=1):
  82. continue
  83. if self.click(self.C_ISLAND_ENTER_1, interval=2):
  84. continue
  85. if self.click(self.C_ISLAND_ENTER_2, interval=2):
  86. continue
  87. if self.click(self.C_ISLAND_ENTER_3, interval=2):
  88. continue
  89. if self.click(self.C_ISLAND_ENTER_4, interval=2):
  90. continue
  91. if self.click(self.C_ISLAND_ENTER_5, interval=2):
  92. continue
  93. if self.click(self.C_ISLAND_ENTER_6, interval=2):
  94. continue
  95. logger.info('Entering island randomly')
  96. return
  97. isl_roi = [isl_roi[0]-40, isl_roi[1] + 70, isl_roi[2] + 40, isl_roi[3]+40]
  98. self.C_ISLAND_ENTER.roi_front = isl_roi
  99. while 1:
  100. self.screenshot()
  101. if not self.in_main() and self.appear(self.I_BACK_EXIT):
  102. break
  103. if self.click(self.C_ISLAND_ENTER, interval=2.5):
  104. continue
  105. logger.info('Entering island')
  106. return
  107. def activate_store(self) -> bool:
  108. """
  109. 最后打boss前面激活一次商店买东西
  110. @return: 有钱够就是True
  111. """
  112. logger.info('Activating store')
  113. self.screenshot()
  114. if self.appear(self.I_M_STORE) and not self.appear(self.I_M_STORE_ACTIVITY):
  115. logger.warning('Now you have not money to buy items')
  116. logger.warning('Store is not active')
  117. return False
  118. cnt_act = 0
  119. while 1:
  120. self.screenshot()
  121. if self.appear(self.I_UI_CONFIRM):
  122. self.ui_click_until_disappear(self.I_UI_CONFIRM, interval=2)
  123. break
  124. if cnt_act >= 3:
  125. logger.warning('Store is not active')
  126. return False
  127. if self.appear_then_click(self.I_M_STORE_ACTIVITY, interval=1.5):
  128. cnt_act += 1
  129. continue
  130. def entry_island_random(self, area: list = None):
  131. """
  132. :param area: 搁置
  133. :return:
  134. """
  135. # if not isinstance(area, list):
  136. # area = list(area)
  137. logger.info('Entry island randomly')
  138. while 1:
  139. self.screenshot()
  140. if not self.in_main() and self.appear(self.I_BACK_EXIT):
  141. break
  142. if self.click(self.C_ISLAND_ENTER_4, interval=2):
  143. continue
  144. if self.click(self.C_ISLAND_ENTER_5, interval=2):
  145. continue
  146. if self.click(self.C_ISLAND_ENTER_6, interval=2):
  147. continue
  148. return
  149. if __name__ == '__main__':
  150. from module.config.config import Config
  151. from module.device.device import Device
  152. from module.base.utils import load_image
  153. c = Config('oas1')
  154. d = Device(c)
  155. t = MoonSeaMap(c, d)
  156. t.device.image = load_image(r'C:\Users\Ryland\Desktop\Desktop\34.png')
  157. match = re.search(r'\d{1,2}', '<17回合后迎战月读')
  158. if match:
  159. isl_num = int(match.group())
  160. print(isl_num)