From bf80b9ccd7941dc22350558f287c7d9d27c0da6a Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 14 Oct 2020 11:35:07 +0200 Subject: [PATCH 01/14] clean finished quests in quest mode --- mapadroid/ocr/matching_trash.py | 2 +- mapadroid/ocr/pogoWindows.py | 66 +++++++++++++++++++ mapadroid/worker/MITMBase.py | 108 ++++++++++++++++++++++---------- mapadroid/worker/WorkerBase.py | 12 ++++ 4 files changed, 154 insertions(+), 34 deletions(-) diff --git a/mapadroid/ocr/matching_trash.py b/mapadroid/ocr/matching_trash.py index 472e2cdfd..57e3e0b6a 100644 --- a/mapadroid/ocr/matching_trash.py +++ b/mapadroid/ocr/matching_trash.py @@ -64,7 +64,7 @@ def trash_image_matching(origin, screen_img, full_screen): last_y_coord = 0 res = cv2.matchTemplate(screen, resized, cv2.TM_CCOEFF_NORMED) - threshold = 0.5 + threshold = 0.65 loc = np.where(res >= threshold) boxcount = 0 for pt in zip(*loc[::-1]): diff --git a/mapadroid/ocr/pogoWindows.py b/mapadroid/ocr/pogoWindows.py index a736fc047..5d09ffa3f 100644 --- a/mapadroid/ocr/pogoWindows.py +++ b/mapadroid/ocr/pogoWindows.py @@ -610,3 +610,69 @@ def __screendetection_get_type_internal(self, image, return None return returntype, globaldict, width, height, diff + + def check_finished_quest(self, image, identifier): + return self.__thread_pool.apply_async(self.__check_finished_quest_internal, (image, identifier)).get() + + def __check_finished_quest_internal(self, image, identifier): + origin_logger = get_origin_logger(logger, origin=identifier) + results = dict.fromkeys(["breakthrough", "finished", "blocked"], []) + globaldict: Optional[dict] = {} + diff: int = 1 + origin_logger.debug("__check_finished_quest_interal") + + try: + with Image.open(image) as frame_org: + width, height = frame_org.size + origin_logger.debug("Screensize: W:{} x H:{}", width, height) + + if width < 1080: + origin_logger.info('Resize screen ...') + frame_org = frame_org.resize([int(2 * s) for s in frame_org.size], Image.ANTIALIAS) + diff: int = 2 + + try: + globaldict = pytesseract.image_to_data(frame_org, output_type=Output.DICT, timeout=40, + config='--dpi 70') + except Exception as e: + origin_logger.error("Tesseract Error: {}. Exception: {}", globaldict, e) + globaldict = None + + origin_logger.debug("Screentext: {}", globaldict) + if globaldict is None or 'text' not in globaldict: + return results + + n_boxes = len(globaldict['text']) + for index in range(n_boxes): + if globaldict['text'][index] in ["REWARD!", "ABHOLEN!"]: + # original screen coordinates + left = globaldict["left"][index] / diff + top = globaldict["top"][index] / diff + + # get rgb values of a close "orange pixel" - the color differs between: + # the quest stack, normal finished quests, and quests blocked bc of the breakthrough + r, g, b = frame_org.getpixel((globaldict["left"][index], globaldict["top"][index] - 20 / diff)) + origin_logger.debug("rgb of this quest: {}/{}/{}", r, g, b) + + # breakthrough reward is in the upper half of the screen + if top < height / 2: + origin_logger.debug("Found breakthrough reward at coords {},{}", left, top) + results["breakthrough"].append({'x': left, 'y': top}) + # finished quest - can be retrieved + elif 250 > r > 228 and b < 90: + origin_logger.debug("Found finished quest at coords {},{}", left, top) + results["finished"].append({'x': left, 'y': top}) + # quest stack - to be ignored + elif r > 228 and b < 90: + origin_logger.debug("Found stacked quest at coords {},{}", left, top) + else: + origin_logger.debug("Found blocked quest at coords {},{}", left, top) + results["blocked"].append({'x': left, 'y': top}) + except (FileNotFoundError, ValueError) as e: + origin_logger.error("Failed opening image {} with exception {}", image, e) + return results + + # reverse sort by y so that clicking will start from the bottom - starting from the top causes entries to move + if results["finished"]: + results["finished"] = sorted(results["finished"], key=lambda k: k['y'], reverse=True) + return results diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index 9913e740a..b596c4bd3 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -269,7 +269,7 @@ def _wait_data_worker(self, latest, proto_to_wait_for, timestamp): """ pass - def _clear_quests(self, delayadd, openmenu=True): + def _clear_quests(self, delayadd, openmenu=True, looped=False): self.logger.debug('{_clear_quests} called') if openmenu: x, y = self._resocalc.get_coords_quest_menu(self) @@ -287,41 +287,83 @@ def _clear_quests(self, delayadd, openmenu=True): self.logger.debug("_clear_quests Open field: {}, {}", int(x), int(y)) time.sleep(4 + int(delayadd)) - trashcancheck = self._get_trash_positions(full_screen=True) - self.logger.debug("_clear_quests Found trash: {}", trashcancheck) - if trashcancheck is None: - self.logger.error('Could not find any trashcan - abort') - return - if len(trashcancheck) == 0: - self._clear_quests_failcount += 1 - if self._clear_quests_failcount < 3: - self.logger.warning("Could not find any trashcan on a valid screenshot {} time(s) in a row!", - self._clear_quests_failcount) + # looping is required for breakthrough cleanup - there should be no trashcans left, thus skip this when looped + if not looped: + trashcancheck = self._get_trash_positions(full_screen=True) + self.logger.debug("_clear_quests Found trash: {}", trashcancheck) + if trashcancheck is None: + self.logger.error('Could not find any trashcan - abort') + return + if len(trashcancheck) == 0: + self._clear_quests_failcount += 1 + if self._clear_quests_failcount < 3: + self.logger.warning("Could not find any trashcan on a valid screenshot {} time(s) in a row!", + self._clear_quests_failcount) + else: + self._clear_quests_failcount = 0 + self.logger.error("Unable to clear quests 3 times in a row. Restart pogo ...") + if not self._restart_pogo(mitm_mapper=self._mitm_mapper): + # TODO: put in loop, count up for a reboot ;) + raise InternalStopWorkerException + return else: + self.logger.info("Found {} trashcan(s) on screen", len(trashcancheck)) + # get confirm box coords + x, y = self._resocalc.get_confirm_delete_quest_coords(self) + + for trash in range(len(trashcancheck)): self._clear_quests_failcount = 0 - self.logger.error("Unable to clear quests 3 times in a row. Restart pogo ...") - if not self._restart_pogo(mitm_mapper=self._mitm_mapper): - # TODO: put in loop, count up for a reboot ;) - raise InternalStopWorkerException - return - else: - self.logger.info("Found {} trashcan(s) on screen", len(trashcancheck)) - # get confirm box coords - x, y = self._resocalc.get_confirm_delete_quest_coords(self) - - for trash in range(len(trashcancheck)): - self._clear_quests_failcount = 0 - self.set_devicesettings_value('last_questclear_time', time.time()) - self.logger.info("Delete old quest {}", int(trash) + 1) - for i in range(3): - self.logger.debug("repeated trash click #{}", i + 1) + self.set_devicesettings_value('last_questclear_time', time.time()) + self.logger.info("Delete old quest {}", int(trash) + 1) self._communicator.click(int(trashcancheck[0].x), int(trashcancheck[0].y)) - time.sleep(0.3 + int(delayadd)) - self.logger.debug("final trash click ...") - self._communicator.click(int(trashcancheck[0].x), int(trashcancheck[0].y)) - time.sleep(2.5 + int(delayadd)) - self._communicator.click(int(x), int(y)) - time.sleep(1 + int(delayadd)) + time.sleep(4.5 + int(delayadd)) + self._communicator.click(int(x), int(y)) + time.sleep(1 + int(delayadd)) + + # check for finished quests if there was not the expected amount of trashcans + expected_trashcans = 1 if self._always_cleanup else 3 + if looped or len(trashcancheck) < expected_trashcans: + cleaned_count: int = 0 + if looped: + self.logger.info("Retry clearing finished quests after retrieving breakthrough reward") + else: + self.logger.info("Less than {} trashcans were found - check for finished quests", expected_trashcans) + + questcheck = self._check_finished_quest(full_screen=True) + if questcheck["blocked"]: + if not looped: + self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") + self._communicator.click(questcheck["breakthrough"][0]['x'], questcheck["breakthrough"][0]['y']) + time.sleep(20) + self._communicator.back_button() + time.sleep(5) + self._clear_quests(delayadd, openmenu=False, looped=True) + return + else: + self.logger.error("Unable to clean breakthrough - the reward pokemon needs to be caught!") + elif questcheck["breakthrough"]: + self.logger.warning("Breakthrough reward found - consider catching it soon!") + + if not questcheck["finished"]: + self.logger.info("Unable to find any finished quests.") + for quest in questcheck["finished"]: + cleaned_count += 1 + self.logger.info("Retrieving finished quest #{}", cleaned_count) + self._communicator.click(quest['x'], quest['y']) + time.sleep(15) + self._communicator.back_button() + time.sleep(5) + + # back button throws us to the map, return to the quest menu if more quests to be cleared + # otherwise just return without trying to click the close button + if len(questcheck["finished"]) > cleaned_count: + x, y = self._resocalc.get_coords_quest_menu(self) + self._communicator.click(int(x), int(y)) + self.logger.debug("_clear_quests Open menu again: {}, {}", int(x), int(y)) + time.sleep(6 + int(delayadd)) + else: + self.logger.success("Done clearing finished quests!") + return x, y = self._resocalc.get_close_main_button_coords(self) self._communicator.click(int(x), int(y)) diff --git a/mapadroid/worker/WorkerBase.py b/mapadroid/worker/WorkerBase.py index dd49e19e5..4b8851b19 100644 --- a/mapadroid/worker/WorkerBase.py +++ b/mapadroid/worker/WorkerBase.py @@ -784,6 +784,18 @@ def _get_trash_positions(self, full_screen=False): return trashes + def _check_finished_quest(self, full_screen=False): + self.logger.warning("_check_finished_quest: Check finished quest.") + if not self._take_screenshot(delay_before=self.get_devicesettings_value("post_screenshot_delay", 1)): + self.logger.debug("_check_finished_quest: Failed getting screenshot") + return None + + if os.path.isdir(self.get_screenshot_path()): + self.logger.error("_check_finished_quest: screenshot.png is not a file/corrupted") + return None + + return self._pogoWindowManager.check_finished_quest(self.get_screenshot_path(), self._origin) + def _take_screenshot(self, delay_after=0.0, delay_before=0.0, errorscreen: bool = False): self.logger.debug2("Taking screenshot...") time.sleep(delay_before) From c96a037f58dc32b9c27cb89dde8aa0c65e232516 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 14 Oct 2020 12:47:28 +0200 Subject: [PATCH 02/14] finished quests: fix results dict, logging cleanup --- mapadroid/ocr/pogoWindows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mapadroid/ocr/pogoWindows.py b/mapadroid/ocr/pogoWindows.py index 5d09ffa3f..1db831574 100644 --- a/mapadroid/ocr/pogoWindows.py +++ b/mapadroid/ocr/pogoWindows.py @@ -616,7 +616,7 @@ def check_finished_quest(self, image, identifier): def __check_finished_quest_internal(self, image, identifier): origin_logger = get_origin_logger(logger, origin=identifier) - results = dict.fromkeys(["breakthrough", "finished", "blocked"], []) + results = {"breakthrough": [], "finished": [], "blocked": []} globaldict: Optional[dict] = {} diff: int = 1 origin_logger.debug("__check_finished_quest_interal") @@ -652,11 +652,11 @@ def __check_finished_quest_internal(self, image, identifier): # get rgb values of a close "orange pixel" - the color differs between: # the quest stack, normal finished quests, and quests blocked bc of the breakthrough r, g, b = frame_org.getpixel((globaldict["left"][index], globaldict["top"][index] - 20 / diff)) - origin_logger.debug("rgb of this quest: {}/{}/{}", r, g, b) + origin_logger.debug("Quest at {},{} has RGB: {}/{}/{}", left, top, r, g, b) # breakthrough reward is in the upper half of the screen if top < height / 2: - origin_logger.debug("Found breakthrough reward at coords {},{}", left, top) + origin_logger.debug("Found breakthrough reward at coords {},{}", left, top) results["breakthrough"].append({'x': left, 'y': top}) # finished quest - can be retrieved elif 250 > r > 228 and b < 90: From 123625017d76275ddf5dcdfb2f08927928296f85 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 14 Oct 2020 12:51:58 +0200 Subject: [PATCH 03/14] finished quests: fix wrong loglevel --- mapadroid/worker/WorkerBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapadroid/worker/WorkerBase.py b/mapadroid/worker/WorkerBase.py index 4b8851b19..b42f75523 100644 --- a/mapadroid/worker/WorkerBase.py +++ b/mapadroid/worker/WorkerBase.py @@ -785,7 +785,7 @@ def _get_trash_positions(self, full_screen=False): return trashes def _check_finished_quest(self, full_screen=False): - self.logger.warning("_check_finished_quest: Check finished quest.") + self.logger.debug("_check_finished_quest: Check finished quest.") if not self._take_screenshot(delay_before=self.get_devicesettings_value("post_screenshot_delay", 1)): self.logger.debug("_check_finished_quest: Failed getting screenshot") return None From e790ac953b8e0a6f02503ba285c088c991fd382c Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 23 Nov 2020 10:29:23 +0100 Subject: [PATCH 04/14] undo obsolete trash matching threshold change --- mapadroid/ocr/matching_trash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapadroid/ocr/matching_trash.py b/mapadroid/ocr/matching_trash.py index 57e3e0b6a..472e2cdfd 100644 --- a/mapadroid/ocr/matching_trash.py +++ b/mapadroid/ocr/matching_trash.py @@ -64,7 +64,7 @@ def trash_image_matching(origin, screen_img, full_screen): last_y_coord = 0 res = cv2.matchTemplate(screen, resized, cv2.TM_CCOEFF_NORMED) - threshold = 0.65 + threshold = 0.5 loc = np.where(res >= threshold) boxcount = 0 for pt in zip(*loc[::-1]): From 3e6dc64d807c77710b6d5efe4f3e2d4b2d0fcca6 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 23 Nov 2020 10:35:53 +0100 Subject: [PATCH 05/14] check_finished based on kwarg --- mapadroid/worker/MITMBase.py | 81 ++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index 73ecd8263..1a2aa2cc4 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -269,7 +269,7 @@ def _wait_data_worker(self, latest, proto_to_wait_for, timestamp): """ pass - def _clear_quests(self, delayadd, openmenu=True, looped=False): + def _clear_quests(self, delayadd, openmenu=True, check_finished=False, looped=False): self.logger.debug('{_clear_quests} called') if openmenu: x, y = self._resocalc.get_coords_quest_menu(self) @@ -277,47 +277,48 @@ def _clear_quests(self, delayadd, openmenu=True, looped=False): self.logger.debug("_clear_quests Open menu: {}, {}", int(x), int(y)) time.sleep(6 + int(delayadd)) - cleaned_count: int = 0 - if looped: - self.logger.info("Retry clearing finished quests after retrieving breakthrough reward") - else: - self.logger.info("Check for finished quests") - - questcheck = self._check_finished_quest(full_screen=True) - if questcheck["blocked"]: - if not looped: - self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") - self._communicator.click(questcheck["breakthrough"][0]['x'], questcheck["breakthrough"][0]['y']) - time.sleep(20) + if check_finished: + cleaned_count: int = 0 + if looped: + self.logger.info("Retry clearing finished quests after retrieving breakthrough reward") + else: + self.logger.info("Check for finished quests") + + questcheck = self._check_finished_quest(full_screen=True) + if questcheck["blocked"]: + if not looped: + self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") + self._communicator.click(questcheck["breakthrough"][0]['x'], questcheck["breakthrough"][0]['y']) + time.sleep(20) + self._communicator.back_button() + time.sleep(5) + self._clear_quests(delayadd, openmenu=False, check_finished=True, looped=True) + return + else: + self.logger.error("Unable to clean breakthrough - the reward pokemon needs to be caught!") + elif questcheck["breakthrough"]: + self.logger.warning("Breakthrough reward found - consider catching it soon!") + + if not questcheck["finished"]: + self.logger.info("Unable to find any finished quests.") + for quest in questcheck["finished"]: + cleaned_count += 1 + self.logger.info("Retrieving finished quest #{}", cleaned_count) + self._communicator.click(quest['x'], quest['y']) + time.sleep(15) self._communicator.back_button() time.sleep(5) - self._clear_quests(delayadd, openmenu=False, looped=True) - return - else: - self.logger.error("Unable to clean breakthrough - the reward pokemon needs to be caught!") - elif questcheck["breakthrough"]: - self.logger.warning("Breakthrough reward found - consider catching it soon!") - - if not questcheck["finished"]: - self.logger.info("Unable to find any finished quests.") - for quest in questcheck["finished"]: - cleaned_count += 1 - self.logger.info("Retrieving finished quest #{}", cleaned_count) - self._communicator.click(quest['x'], quest['y']) - time.sleep(15) - self._communicator.back_button() - time.sleep(5) - - # back button throws us to the map, return to the quest menu if more quests to be cleared - # otherwise just return without trying to click the close button - if len(questcheck["finished"]) > cleaned_count: - x, y = self._resocalc.get_coords_quest_menu(self) - self._communicator.click(int(x), int(y)) - self.logger.debug("_clear_quests Open menu again: {}, {}", int(x), int(y)) - time.sleep(6 + int(delayadd)) - else: - self.logger.success("Done clearing finished quests!") - return + + # back button throws us to the map, return to the quest menu if more quests to be cleared + # otherwise just return without trying to click the close button + if len(questcheck["finished"]) > cleaned_count: + x, y = self._resocalc.get_coords_quest_menu(self) + self._communicator.click(int(x), int(y)) + self.logger.debug("_clear_quests Open menu again: {}, {}", int(x), int(y)) + time.sleep(6 + int(delayadd)) + else: + self.logger.success("Done clearing finished quests!") + return x, y = self._resocalc.get_close_main_button_coords(self) self._communicator.click(int(x), int(y)) From 1aaade62c26ea50fbb7bd9115f8fde663dbd518e Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 23 Nov 2020 10:37:44 +0100 Subject: [PATCH 06/14] click the daily tab --- mapadroid/worker/MITMBase.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index 1a2aa2cc4..2fd3a4b2a 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -278,6 +278,11 @@ def _clear_quests(self, delayadd, openmenu=True, check_finished=False, looped=Fa time.sleep(6 + int(delayadd)) if check_finished: + x, y = self._resocalc.get_quest_listview(self) + self._communicator.click(int(x), int(y)) + self.logger.debug("_clear_quests Open field: {}, {}", int(x), int(y)) + time.sleep(4 + int(delayadd)) + cleaned_count: int = 0 if looped: self.logger.info("Retry clearing finished quests after retrieving breakthrough reward") From c2e79ef91398aef57f572c5a13a64bbdf224f31b Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 23 Nov 2020 11:08:42 +0100 Subject: [PATCH 07/14] check finished when starting and when log is full unexpectedly --- mapadroid/worker/WorkerQuests.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mapadroid/worker/WorkerQuests.py b/mapadroid/worker/WorkerQuests.py index 97f4134d2..d5322af94 100644 --- a/mapadroid/worker/WorkerQuests.py +++ b/mapadroid/worker/WorkerQuests.py @@ -45,6 +45,7 @@ class ClearThreadTasks(Enum): IDLE = 0 BOX = 1 QUEST = 2 + QUEST_WITH_FINISHED = 3 class WorkerQuests(MITMBase): @@ -121,7 +122,7 @@ def _pre_work_loop(self): else: # initial cleanup old quests if not self._init: - self.clear_thread_task = ClearThreadTasks.QUEST + self.clear_thread_task = ClearThreadTasks.QUEST_WITH_FINISHED def _health_check(self): """ @@ -425,6 +426,10 @@ def _clear_thread(self): self.logger.info("Clearing quest") self._clear_quests(self._delay_add) self.clear_thread_task = ClearThreadTasks.IDLE + elif self.clear_thread_task == ClearThreadTasks.QUEST_WITH_FINISHED and not self._level_mode: + self.logger.info("Clearing quests and checking for finished quests") + self._clear_quests(self._delay_add, check_finished=True) + self.clear_thread_task = ClearThreadTasks.IDLE time.sleep(1) except (InternalStopWorkerException, WebsocketWorkerRemovedException, WebsocketWorkerTimeoutException, WebsocketWorkerConnectionClosedException): @@ -792,7 +797,7 @@ def _handle_stop(self, timestamp: float): if not self._restart_pogo(mitm_mapper=self._mitm_mapper): # TODO: put in loop, count up for a reboot ;) raise InternalStopWorkerException - self.clear_thread_task = ClearThreadTasks.QUEST + self.clear_thread_task = ClearThreadTasks.QUEST_WITH_FINISHED self._clear_quest_counter = 0 break else: From ccd1d92938b8b6f22444bd0fdf5a915411819496 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 23 Nov 2020 11:11:38 +0100 Subject: [PATCH 08/14] also take note of AR quests during checks --- mapadroid/ocr/pogoWindows.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mapadroid/ocr/pogoWindows.py b/mapadroid/ocr/pogoWindows.py index 76db4bc7d..111b20373 100644 --- a/mapadroid/ocr/pogoWindows.py +++ b/mapadroid/ocr/pogoWindows.py @@ -623,7 +623,7 @@ def check_finished_quest(self, image, identifier): def __check_finished_quest_internal(self, image, identifier): origin_logger = get_origin_logger(logger, origin=identifier) - results = {"breakthrough": [], "finished": [], "blocked": []} + results = {"breakthrough": [], "finished": [], "blocked": [], "ar": []} globaldict: Optional[dict] = {} diff: int = 1 origin_logger.debug("__check_finished_quest_interal") @@ -675,6 +675,11 @@ def __check_finished_quest_internal(self, image, identifier): else: origin_logger.debug("Found blocked quest at coords {},{}", left, top) results["blocked"].append({'x': left, 'y': top}) + + if globaldict['text'][index] in ["Scan", "scannen"]: + origin_logger.debug("Found AR quest at coords {},{}", left, top) + results["ar"].append({'x': left, 'y': top}) + except (FileNotFoundError, ValueError) as e: origin_logger.error("Failed opening image {} with exception {}", image, e) return results From ac411a4e151f8275b1c9ec8924060002bc9b42d8 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 23 Nov 2020 11:26:13 +0100 Subject: [PATCH 09/14] get original screen coordinates for every index --- mapadroid/ocr/pogoWindows.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mapadroid/ocr/pogoWindows.py b/mapadroid/ocr/pogoWindows.py index 111b20373..df35d4d0f 100644 --- a/mapadroid/ocr/pogoWindows.py +++ b/mapadroid/ocr/pogoWindows.py @@ -651,11 +651,11 @@ def __check_finished_quest_internal(self, image, identifier): n_boxes = len(globaldict['text']) for index in range(n_boxes): - if globaldict['text'][index] in ["REWARD!", "ABHOLEN!"]: - # original screen coordinates - left = globaldict["left"][index] / diff - top = globaldict["top"][index] / diff + # original screen coordinates + left = globaldict["left"][index] / diff + top = globaldict["top"][index] / diff + if globaldict['text'][index] in ["REWARD!", "ABHOLEN!"]: # get rgb values of a close "orange pixel" - the color differs between: # the quest stack, normal finished quests, and quests blocked bc of the breakthrough r, g, b = frame_org.getpixel((globaldict["left"][index], globaldict["top"][index] - 20 / diff)) From 10480dd653062082396c542385a26311d926a124 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 25 Nov 2020 09:21:14 +0100 Subject: [PATCH 10/14] handle inconsistent OCR result - blocked but no breakthrough available --- mapadroid/worker/MITMBase.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index 2fd3a4b2a..7ee0b3cbf 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -291,7 +291,10 @@ def _clear_quests(self, delayadd, openmenu=True, check_finished=False, looped=Fa questcheck = self._check_finished_quest(full_screen=True) if questcheck["blocked"]: - if not looped: + if not questcheck["breakthrough"] and not looped: + self.logger.warning("Found blocked quest but no breakthrough reward - likely flawed OCR result. " + "This can be ignored if not happening repeatedly.") + elif not looped: self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") self._communicator.click(questcheck["breakthrough"][0]['x'], questcheck["breakthrough"][0]['y']) time.sleep(20) From 736774225acdac249d8d55bc7bb3c2a895e4670c Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 25 Nov 2020 11:52:27 +0100 Subject: [PATCH 11/14] go to main screen before opening quest menu --- mapadroid/worker/MITMBase.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index 7ee0b3cbf..ddb83cc8f 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -271,6 +271,13 @@ def _wait_data_worker(self, latest, proto_to_wait_for, timestamp): def _clear_quests(self, delayadd, openmenu=True, check_finished=False, looped=False): self.logger.debug('{_clear_quests} called') + + reached_main_menu = self._check_pogo_main_screen(10, True) + if not reached_main_menu: + if not self._restart_pogo(mitm_mapper=self._mitm_mapper): + # TODO: put in loop, count up for a reboot ;) + raise InternalStopWorkerException + if openmenu: x, y = self._resocalc.get_coords_quest_menu(self) self._communicator.click(int(x), int(y)) From 6ba8d322f67cc41b3a21aa2404241d5462975c58 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 25 Nov 2020 12:54:13 +0100 Subject: [PATCH 12/14] identify blocked quest explicitly --- mapadroid/ocr/pogoWindows.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mapadroid/ocr/pogoWindows.py b/mapadroid/ocr/pogoWindows.py index df35d4d0f..ffd002b7a 100644 --- a/mapadroid/ocr/pogoWindows.py +++ b/mapadroid/ocr/pogoWindows.py @@ -665,16 +665,17 @@ def __check_finished_quest_internal(self, image, identifier): if top < height / 2: origin_logger.debug("Found breakthrough reward at coords {},{}", left, top) results["breakthrough"].append({'x': left, 'y': top}) + # blocked quest - breakthrough needs to be retrieved + elif 250 > r > 228 and g < 165 and b < 72: + origin_logger.debug("Found blocked quest at coords {},{}", left, top) + results["blocked"].append({'x': left, 'y': top}) # finished quest - can be retrieved elif 250 > r > 228 and b < 90: origin_logger.debug("Found finished quest at coords {},{}", left, top) results["finished"].append({'x': left, 'y': top}) # quest stack - to be ignored - elif r > 228 and b < 90: + elif r > 249 and b < 90: origin_logger.debug("Found stacked quest at coords {},{}", left, top) - else: - origin_logger.debug("Found blocked quest at coords {},{}", left, top) - results["blocked"].append({'x': left, 'y': top}) if globaldict['text'][index] in ["Scan", "scannen"]: origin_logger.debug("Found AR quest at coords {},{}", left, top) From db3593b785286aa384942ae9998023d162a95724 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Wed, 25 Nov 2020 12:57:43 +0100 Subject: [PATCH 13/14] ok travis --- mapadroid/worker/MITMBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index ddb83cc8f..647f1298e 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -300,7 +300,7 @@ def _clear_quests(self, delayadd, openmenu=True, check_finished=False, looped=Fa if questcheck["blocked"]: if not questcheck["breakthrough"] and not looped: self.logger.warning("Found blocked quest but no breakthrough reward - likely flawed OCR result. " - "This can be ignored if not happening repeatedly.") + "This can be ignored if not happening repeatedly.") elif not looped: self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") self._communicator.click(questcheck["breakthrough"][0]['x'], questcheck["breakthrough"][0]['y']) From ca2b767607ccdd1245ec6164a35db76f66a2be4e Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Sun, 1 Aug 2021 15:55:04 +0200 Subject: [PATCH 14/14] handle questcheck ocr failure There would be an exception thrown if the OCR part of quest checking failed. This commit fixes the problem. --- mapadroid/worker/MITMBase.py | 74 +++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/mapadroid/worker/MITMBase.py b/mapadroid/worker/MITMBase.py index ab4686569..6588a94a0 100644 --- a/mapadroid/worker/MITMBase.py +++ b/mapadroid/worker/MITMBase.py @@ -377,43 +377,47 @@ def _clear_quests(self, delayadd, openmenu=True, check_finished=False, looped=Fa self.logger.info("Check for finished quests") questcheck = self._check_finished_quest(full_screen=True) - if questcheck["blocked"]: - if not questcheck["breakthrough"] and not looped: - self.logger.warning("Found blocked quest but no breakthrough reward - likely flawed OCR result. " - "This can be ignored if not happening repeatedly.") - elif not looped: - self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") - self._communicator.click(questcheck["breakthrough"][0]['x'], questcheck["breakthrough"][0]['y']) - time.sleep(20) + if not questcheck: + self.logger.warning("Quest check OCR failed. Move on.") + else: + if questcheck["blocked"]: + if not questcheck["breakthrough"] and not looped: + self.logger.warning("Found blocked quest but no breakthrough reward - likely flawed OCR" + "result. This can be ignored if not happening repeatedly.") + elif not looped: + self.logger.warning("Found a blocked quest - need to try to cleanup breakthrough!") + self._communicator.click(questcheck["breakthrough"][0]['x'], + questcheck["breakthrough"][0]['y']) + time.sleep(20) + self._communicator.back_button() + time.sleep(5) + self._clear_quests(delayadd, openmenu=False, check_finished=True, looped=True) + return + else: + self.logger.error("Unable to clean breakthrough - the reward pokemon needs to be caught!") + elif questcheck["breakthrough"]: + self.logger.warning("Breakthrough reward found - consider catching it soon!") + + if not questcheck["finished"]: + self.logger.info("Unable to find any finished quests.") + for quest in questcheck["finished"]: + cleaned_count += 1 + self.logger.info("Retrieving finished quest #{}", cleaned_count) + self._communicator.click(quest['x'], quest['y']) + time.sleep(15) self._communicator.back_button() time.sleep(5) - self._clear_quests(delayadd, openmenu=False, check_finished=True, looped=True) - return - else: - self.logger.error("Unable to clean breakthrough - the reward pokemon needs to be caught!") - elif questcheck["breakthrough"]: - self.logger.warning("Breakthrough reward found - consider catching it soon!") - - if not questcheck["finished"]: - self.logger.info("Unable to find any finished quests.") - for quest in questcheck["finished"]: - cleaned_count += 1 - self.logger.info("Retrieving finished quest #{}", cleaned_count) - self._communicator.click(quest['x'], quest['y']) - time.sleep(15) - self._communicator.back_button() - time.sleep(5) - - # back button throws us to the map, return to the quest menu if more quests to be cleared - # otherwise just return without trying to click the close button - if len(questcheck["finished"]) > cleaned_count: - x, y = self._resocalc.get_coords_quest_menu(self) - self._communicator.click(int(x), int(y)) - self.logger.debug("_clear_quests Open menu again: {}, {}", int(x), int(y)) - time.sleep(6 + int(delayadd)) - else: - self.logger.success("Done clearing finished quests!") - return + + # back button throws us to the map, return to the quest menu if more quests to be cleared + # otherwise just return without trying to click the close button + if len(questcheck["finished"]) > cleaned_count: + x, y = self._resocalc.get_coords_quest_menu(self) + self._communicator.click(int(x), int(y)) + self.logger.debug("_clear_quests Open menu again: {}, {}", int(x), int(y)) + time.sleep(6 + int(delayadd)) + else: + self.logger.success("Done clearing finished quests!") + return x, y = self._resocalc.get_close_main_button_coords(self) self._communicator.click(int(x), int(y))