diff --git a/module/base/base.py b/module/base/base.py index 2ece6a4ce..e2443e00f 100644 --- a/module/base/base.py +++ b/module/base/base.py @@ -273,7 +273,7 @@ class ModuleBase: Returns: Button: Or None if nothing matched. """ - image = color_similarity_2d(self.image_crop(area), color=color) + image = color_similarity_2d(self.image_crop(area, copy=False), color=color) points = np.array(np.where(image > color_threshold)).T[:, ::-1] if points.shape[0] < encourage ** 2: # Not having enough pixels to match diff --git a/module/device/connection.py b/module/device/connection.py index 1fd5eb911..2e19fd286 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -385,15 +385,21 @@ class Connection(ConnectionAttr): Returns: list[str]: ['nc'] or ['busybox', 'nc'] """ - sdk = self.sdk_ver - logger.info(f'sdk_ver: {sdk}') - if sdk >= 28: - # Android 9 emulators does not have `nc`, try `busybox nc` - # BlueStacks Pie (Android 9) has `nc` but cannot send data, try `busybox nc` first - trial = [ - ['busybox', 'nc'], - ['nc'], - ] + if self.is_emulator: + sdk = self.sdk_ver + logger.info(f'sdk_ver: {sdk}') + if sdk >= 28: + # LD Player 9 does not have `nc`, try `busybox nc` + # BlueStacks Pie (Android 9) has `nc` but cannot send data, try `busybox nc` first + trial = [ + ['busybox', 'nc'], + ['nc'], + ] + else: + trial = [ + ['nc'], + ['busybox', 'nc'], + ] else: trial = [ ['nc'], @@ -401,8 +407,9 @@ class Connection(ConnectionAttr): ] for command in trial: # About 3ms - result = self.adb_shell(command) # Result should be command help if success + # nc: bad argument count (see "nc --help") + result = self.adb_shell(command) # `/system/bin/sh: nc: not found` if 'not found' in result: continue diff --git a/module/device/connection_attr.py b/module/device/connection_attr.py index 97c914dbe..a90f6ed01 100644 --- a/module/device/connection_attr.py +++ b/module/device/connection_attr.py @@ -68,6 +68,10 @@ class ConnectionAttr: res = re.search(r'(127\.\d+\.\d+\.\d+:\d+)', serial) if res: serial = res.group(1) + # 12127.0.0.1:16384 + serial = serial.replace('12127.0.0.1', '127.0.0.1') + # auto127.0.0.1:16384 + serial = serial.replace('auto127.0.0.1', '127.0.0.1').replace('autoemulator', 'emulator') return str(serial) def serial_check(self): diff --git a/tasks/assignment/ui.py b/tasks/assignment/ui.py index d187207c4..5eeba0732 100644 --- a/tasks/assignment/ui.py +++ b/tasks/assignment/ui.py @@ -228,7 +228,7 @@ class AssignmentUI(UI): logger.info('Event completed') break if self.appear(ASSIGNMENT_CHECK) and \ - self.image_color_count(ENTRY_LOADED, (35, 35, 35), count=800): + self.image_color_count(ENTRY_LOADED, (35, 35, 35), count=400): logger.info('Entry loaded') break diff --git a/tasks/character/switch.py b/tasks/character/switch.py index a30e25796..bf5e750af 100644 --- a/tasks/character/switch.py +++ b/tasks/character/switch.py @@ -122,7 +122,7 @@ class CharacterSwitch(UI): expected_peaks = np.array([201, 279, 357, 435]) expected_peaks_in_area = expected_peaks - area[1] # Use Luminance to fit H264 video stream - image = rgb2luma(crop(self.device.image, area)) + image = rgb2luma(crop(self.device.image, area, copy=False)) # Remove character names kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) image = cv2.erode(image, kernel) diff --git a/tasks/combat/combat.py b/tasks/combat/combat.py index 827e29f57..d7355e97e 100644 --- a/tasks/combat/combat.py +++ b/tasks/combat/combat.py @@ -2,6 +2,7 @@ from module.base.decorator import run_once from module.exception import RequestHumanTakeover from module.logger import logger from tasks.combat.assets.assets_combat_finish import COMBAT_AGAIN, COMBAT_EXIT +from tasks.combat.assets.assets_combat_interact import DUNGEON_COMBAT_INTERACT from tasks.combat.assets.assets_combat_prepare import COMBAT_PREPARE from tasks.combat.assets.assets_combat_team import COMBAT_TEAM_PREPARE, COMBAT_TEAM_SUPPORT from tasks.combat.interact import CombatInteract @@ -126,7 +127,7 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo self.interval_reset(COMBAT_PREPARE) self.map_A_timer.reset() if self.appear(COMBAT_PREPARE, interval=2): - if self.obtained_is_full(self.dungeon, wave_done=self.combat_wave_done): + if self.is_doing_planner and self.obtained_is_full(self.dungeon, wave_done=self.combat_wave_done): # Update stamina so task can be delayed if both obtained_is_full and stamina exhausted self.combat_get_trailblaze_power() return False @@ -136,11 +137,13 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo self.interval_reset(COMBAT_PREPARE) trial += 1 continue - if self.handle_combat_interact(): - self.map_A_timer.reset() - continue - if self.handle_ascension_dungeon_prepare(): - continue + if self.appear(DUNGEON_COMBAT_INTERACT): + if self.handle_combat_interact(): + self.map_A_timer.reset() + continue + else: + if self.handle_ascension_dungeon_prepare(): + continue if self.handle_popup_confirm(): continue @@ -303,7 +306,8 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo if self.appear(COMBAT_AGAIN, interval=5): add_wave_done() # Update obtain_frequent_check - self.obtained_is_full(dungeon=self.dungeon, wave_done=self.combat_wave_done, obtain_get=False) + if self.is_doing_planner: + self.obtained_is_full(dungeon=self.dungeon, wave_done=self.combat_wave_done, obtain_get=False) # Cache the result of _combat_can_again() as no expected stamina reduce during retry if combat_can_again is None: combat_can_again = self._combat_can_again() diff --git a/tasks/combat/skill.py b/tasks/combat/skill.py index 081c9b44d..fb3bdcda2 100644 --- a/tasks/combat/skill.py +++ b/tasks/combat/skill.py @@ -47,7 +47,7 @@ class CombatSkill(UI): break # New skill icon if prev_image is not None: - if not match_template(self.image_crop(button), prev_image): + if not match_template(self.image_crop(button, copy=False), prev_image): logger.info(f'Skill used: {button} (icon changed)') break diff --git a/tasks/combat/state.py b/tasks/combat/state.py index cac86c67c..e9e32a7f5 100644 --- a/tasks/combat/state.py +++ b/tasks/combat/state.py @@ -22,7 +22,7 @@ class CombatState(UI): return False def _is_combat_button_active(self, button): - image = rgb2luma(self.image_crop(button)) + image = rgb2luma(self.image_crop(button, copy=False)) lines = cv2.reduce(image, 1, cv2.REDUCE_AVG).flatten() # [122 122 122 182 141 127 139 135 130 135 136 141 147 149 149 150 147 145 # 148 150 150 150 150 150 144 138 134 141 136 133 173 183 130 128 127 126] diff --git a/tasks/combat/support.py b/tasks/combat/support.py index de060cca1..0eabf9542 100644 --- a/tasks/combat/support.py +++ b/tasks/combat/support.py @@ -30,7 +30,7 @@ class SupportCharacter: def __init__(self, name, screenshot, similarity=0.75): self.name = name self.image = self._scale_character() - self.screenshot = crop(screenshot, SupportCharacter._crop_area) + self.screenshot = crop(screenshot, SupportCharacter._crop_area, copy=False) self.similarity = similarity self.button = self._find_character() diff --git a/tasks/daily/daily_quest.py b/tasks/daily/daily_quest.py index c186101c9..744f8ccc4 100644 --- a/tasks/daily/daily_quest.py +++ b/tasks/daily/daily_quest.py @@ -33,10 +33,10 @@ class DailyQuestOcr(Ocr): def pre_process(self, image): image = super().pre_process(image) - image = crop(image, OCR_DAILY_QUEST.area) + image = crop(image, OCR_DAILY_QUEST.area, copy=False) mask = MASK_DAILY_QUEST.matched_button.image # Remove "+200Activity" - cv2.bitwise_and(image, mask, dst=image) + image = cv2.bitwise_and(image, mask) return image def after_process(self, result): diff --git a/tasks/dungeon/state.py b/tasks/dungeon/state.py index 4db588c59..c7af7138c 100644 --- a/tasks/dungeon/state.py +++ b/tasks/dungeon/state.py @@ -39,7 +39,7 @@ class DungeonState(UI): ) ocr = OcrSimUniPoint(OCR_SIMUNI_POINT) - value, _, total = ocr.ocr_single_line(crop(image, area), direct_ocr=True) + value, _, total = ocr.ocr_single_line(crop(image, area, copy=False), direct_ocr=True) if total and value <= total: logger.attr('SimulatedUniverse', f'{value}/{total}') self.config.stored.SimulatedUniverse.set(value, total) diff --git a/tasks/dungeon/ui.py b/tasks/dungeon/ui.py index 01d0659cb..4ab40761e 100644 --- a/tasks/dungeon/ui.py +++ b/tasks/dungeon/ui.py @@ -334,7 +334,7 @@ class DungeonUI(DungeonState): # Check if having any content # List background: 254, guild border: 225 - r, g, b = cv2.split(self.image_crop(LIST_LOADED_CHECK)) + r, g, b = cv2.split(self.image_crop(LIST_LOADED_CHECK, copy=False)) minimum = cv2.min(cv2.min(r, g), b) minimum = inrange(minimum, lower=0, upper=180) if minimum.size > 100: diff --git a/tasks/forgotten_hall/team.py b/tasks/forgotten_hall/team.py index ac91a6ca1..5317c360a 100644 --- a/tasks/forgotten_hall/team.py +++ b/tasks/forgotten_hall/team.py @@ -35,7 +35,7 @@ class ForgottenHallTeam(UI): continue def is_character_chosen(self, button: ButtonWrapper) -> bool: - image = color_similarity_2d(self.image_crop(button), color=(255, 255, 255)) + image = color_similarity_2d(self.image_crop(button, copy=False), color=(255, 255, 255)) color = cv2.mean(image)[0] # print(button, color) # Chosen: diff --git a/tasks/forgotten_hall/ui.py b/tasks/forgotten_hall/ui.py index 14e9c3d59..08b1aa7a8 100644 --- a/tasks/forgotten_hall/ui.py +++ b/tasks/forgotten_hall/ui.py @@ -23,7 +23,7 @@ class ForgottenHallStageOcr(Ocr): def _find_number(self, image): raw = image.copy() area = OCR_STAGE.area - image = crop(raw, area) + image = crop(raw, area, copy=False) yellow = color_similarity_2d(image, color=(255, 200, 112)) gray = color_similarity_2d(image, color=(100, 109, 134)) image = np.maximum(yellow, gray) diff --git a/tasks/item/synthesize.py b/tasks/item/synthesize.py index 7867c0e04..fc15f9256 100644 --- a/tasks/item/synthesize.py +++ b/tasks/item/synthesize.py @@ -56,11 +56,11 @@ class Synthesize(CombatObtain): Pages: in: page_synthesize """ - image = self.image_crop(button) + image = self.image_crop(button, copy=False) image = cv2.GaussianBlur(image, (3, 3), 0) x2, y2 = image_size(image) y1 = y2 - int(y2 // 4) - image = crop(image, (0, y1, x2, y2)) + image = crop(image, (0, y1, x2, y2), copy=False) # self.device.image_show(image) # print(image.shape) diff --git a/tasks/map/minimap/minimap.py b/tasks/map/minimap/minimap.py index ce6a78c16..1b7c5bcce 100644 --- a/tasks/map/minimap/minimap.py +++ b/tasks/map/minimap/minimap.py @@ -150,7 +150,7 @@ class Minimap(MapResource): # Image.fromarray((local_maximum * 255).astype(np.uint8)).save('local_maximum.png') # Calculate the precise location using CUBIC - # precise = crop(result, area=area_offset((-4, -4, 4, 4), offset=local_loca)) + # precise = crop(result, area=area_offset((-4, -4, 4, 4), offset=local_loca), copy=False) # precise_sim, precise_loca = cubic_find_maximum(precise, precision=0.05) # precise_loca -= 5 precise_loca = np.array((0, 0)) @@ -190,7 +190,7 @@ class Minimap(MapResource): loca = state.loca local_loca = state.local_loca - precise = crop(result, area=area_offset((-4, -4, 4, 4), offset=loca)) + precise = crop(result, area=area_offset((-4, -4, 4, 4), offset=loca), copy=False) precise_sim, precise_loca = cubic_find_maximum(precise, precision=0.05) precise_loca -= 5 @@ -265,7 +265,7 @@ class Minimap(MapResource): logger.warning('No direction arrow on minimap') return - image = crop(image, area=area) + image = crop(image, area=area, copy=False) scale = self.DIRECTION_ROTATION_SCALE * self.DIRECTION_SEARCH_SCALE mapping = cv2.resize(image, None, fx=scale, fy=scale, interpolation=cv2.INTER_NEAREST) result = cv2.matchTemplate(self.ArrowRotateMap, mapping, cv2.TM_CCOEFF_NORMED) diff --git a/tasks/map/resource/generate.py b/tasks/map/resource/generate.py index cefa5f4d8..7b1032433 100644 --- a/tasks/map/resource/generate.py +++ b/tasks/map/resource/generate.py @@ -55,7 +55,7 @@ class ResourceGenerator(ResourceConst): arrows = {} for degree in range(0, 360): rotated = rotate_bound(image, degree) - rotated = crop(rotated, area=get_bbox(rotated, threshold=15)) + rotated = crop(rotated, area=get_bbox(rotated, threshold=15), copy=False) # rotated = cv2.resize(rotated, None, fx=self.ROTATE, fy=self.ROTATE, interpolation=cv2.INTER_NEAREST) rotated = color_similarity_2d(rotated, color=self.DIRECTION_ARROW_COLOR) arrows[degree] = rotated diff --git a/tasks/map/resource/resource.py b/tasks/map/resource/resource.py index 2411e00e3..b5cef51d5 100644 --- a/tasks/map/resource/resource.py +++ b/tasks/map/resource/resource.py @@ -101,7 +101,7 @@ class MapResource(ResourceConst): Crop the minimap area on image. """ area = area_offset((-radius, -radius, radius, radius), offset=self.MINIMAP_CENTER) - image = crop(image, area) + image = crop(image, area, copy=False) return image def get_circle_mask(self, image):