From 127f1cc02485babab97898ec16d0e483a13d46d7 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Sun, 1 Aug 2021 20:49:26 +0200 Subject: [PATCH 1/2] Enable encounters in quest mode Due to PD being able to hide Pokemon on the game map, it is no longer a problem that Pokemon might be clicked instead of the Pokestop during quest scan. Thus, checking for these clicks based on received encounter data is no longer necessary and encounters can be received without disturbing the quest scan flow. --- .../data_manager/modules/area_pokestops.py | 27 +++++++++++++++ mapadroid/patcher/__init__.py | 3 +- mapadroid/patcher/pokestop_encounters.py | 34 +++++++++++++++++++ mapadroid/worker/WorkerQuests.py | 17 ++++++++-- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 mapadroid/patcher/pokestop_encounters.py diff --git a/mapadroid/data_manager/modules/area_pokestops.py b/mapadroid/data_manager/modules/area_pokestops.py index 7709e7a48..345fb0fbe 100644 --- a/mapadroid/data_manager/modules/area_pokestops.py +++ b/mapadroid/data_manager/modules/area_pokestops.py @@ -113,6 +113,33 @@ class AreaPokestops(Area): "description": "Cleanup quest inventory after every stop (Default: False)", "expected": bool } + }, + "mon_ids_iv": { + "settings": { + "type": "lookup", + "display": { + "name": "monlist", + "section": "monivlist" + }, + "require": False, + "description": "IV List Resource", + "expected": int, + "uri": True, + "data_source": "monivlist", + "uri_source": "api_monivlist" + } + }, + "all_mons": { + "settings": { + "type": "option", + "require": False, + "values": [False, True], + "description": + "Dynamically generate the areas IV list to ensure all mons are included. If a mon is not part " + "of the IV list it will be appended to the end of the list. Mons will be added in ascending " + "order based on their ID.", + "expected": bool + } } } } diff --git a/mapadroid/patcher/__init__.py b/mapadroid/patcher/__init__.py index e3ae4113b..d86ec1078 100644 --- a/mapadroid/patcher/__init__.py +++ b/mapadroid/patcher/__init__.py @@ -50,7 +50,8 @@ (41, 'dynamic_iv_list'), (42, 'add_encounter_all'), (43, 'remove_tap_duration'), - (44, 'more_ways_to_scan_mons') + (44, 'more_ways_to_scan_mons'), + (45, 'pokestop_encounters') ]) diff --git a/mapadroid/patcher/pokestop_encounters.py b/mapadroid/patcher/pokestop_encounters.py new file mode 100644 index 000000000..f1e39f7a3 --- /dev/null +++ b/mapadroid/patcher/pokestop_encounters.py @@ -0,0 +1,34 @@ +from ._patch_base import PatchBase + + +class Patch(PatchBase): + name = "Pokestop Encounters" + descr = ( + 'Add settings to enable encounters in pokestop mode' + ) + + def _execute(self): + if not self._schema_updater.check_column_exists("settings_area_pokestops", "all_mons"): + alter = """ + ALTER TABLE `settings_area_pokestops` + ADD COLUMN `all_mons` tinyint(1) NOT NULL DEFAULT '0' + """ + try: + self._db.execute(alter, commit=True, raise_exc=True) + except Exception as e: + self._logger.exception("Unexpected error: {}", e) + self.issues = True + + if not self._schema_updater.check_column_exists("settings_area_pokestops", "monlist_id"): + alter = """ + ALTER TABLE `settings_area_pokestops` + ADD COLUMN `monlist_id` int(10) unsigned DEFAULT NULL, + ADD KEY `fk_ap_monid` (`monlist_id`), + ADD CONSTRAINT `fk_ap_monid` FOREIGN KEY (`monlist_id`) + REFERENCES `settings_monivlist` (`monlist_id`); + """ + try: + self._db.execute(alter, commit=True, raise_exc=True) + except Exception as e: + self._logger.exception("Unexpected error: {}", e) + self.issues = True diff --git a/mapadroid/worker/WorkerQuests.py b/mapadroid/worker/WorkerQuests.py index 5a34faf34..58b94bbb4 100644 --- a/mapadroid/worker/WorkerQuests.py +++ b/mapadroid/worker/WorkerQuests.py @@ -449,6 +449,9 @@ def _update_injection_settings(self): scanmode = "quests" injected_settings["scanmode"] = scanmode ids_iv: List[int] = [] + routemanager_settings = self._mapping_manager.routemanager_get_settings(self._routemanager_name) + if routemanager_settings is not None: + ids_iv = self._mapping_manager.get_monlist(self._routemanager_name) self._encounter_ids = {} self._mitm_mapper.update_latest(origin=self._origin, key="ids_encountered", values_dict=self._encounter_ids) self._mitm_mapper.update_latest(origin=self._origin, key="ids_iv", values_dict=ids_iv) @@ -490,6 +493,12 @@ def _directly_surrounding_gmo_cells_containing_stops_around_current_position(sel def _current_position_has_spinnable_stop(self, timestamp: float) -> PositionStopType: type_received, data_received = self._wait_for_data(timestamp=timestamp, proto_to_wait_for=ProtoIdentifier.GMO) + while type_received == LatestReceivedType.MON: + self.logger.info("Received MON looking for spinnable stop - ignore / try again") + time.sleep(1) + type_received, data_received = self._wait_for_data(timestamp=time.time(), + proto_to_wait_for=ProtoIdentifier.GMO) + if type_received != LatestReceivedType.GMO or data_received is None: self._spinnable_data_failure() return PositionStopType.GMO_NOT_AVAILABLE @@ -570,12 +579,14 @@ def _try_to_open_pokestop(self, timestamp: float) -> LatestReceivedType: while stop_type in (PositionStopType.GMO_NOT_AVAILABLE, PositionStopType.GMO_EMPTY, PositionStopType.NO_FORT) and not recheck_count > 2: recheck_count += 1 - self.logger.info("Wait for new data to check the stop again ... (attempt {})", recheck_count + 1) - type_received, proto_entry = self._wait_for_data(timestamp=time.time(), + self.logger.info("Wait for new data to check the stop again ... ({}, attempt {})", stop_type, + recheck_count + 1) + repeat_timestamp = time.time() + type_received, proto_entry = self._wait_for_data(timestamp=repeat_timestamp, proto_to_wait_for=ProtoIdentifier.GMO, timeout=35) if type_received != LatestReceivedType.UNDEFINED: - stop_type = self._current_position_has_spinnable_stop(timestamp) + stop_type = self._current_position_has_spinnable_stop(repeat_timestamp) if not PositionStopType.type_contains_stop_at_all(stop_type): self.logger.info("Location {}, {} considered to be ignored in the next round due to failed " From 7bdd8019ed426f3c1bdede17122bbc0600293f50 Mon Sep 17 00:00:00 2001 From: Christian Betz Date: Mon, 6 Sep 2021 12:45:05 +0200 Subject: [PATCH 2/2] fully ignore LatestReceivedType.MON in quest mode Completely remove LatestReceivedType.MON from _check_for_data_content in WorkerQuests - we do not need to act on Encounter data while quest scanning anymore, it can be ignored. --- mapadroid/worker/WorkerQuests.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/mapadroid/worker/WorkerQuests.py b/mapadroid/worker/WorkerQuests.py index 58b94bbb4..1016747a5 100644 --- a/mapadroid/worker/WorkerQuests.py +++ b/mapadroid/worker/WorkerQuests.py @@ -493,12 +493,6 @@ def _directly_surrounding_gmo_cells_containing_stops_around_current_position(sel def _current_position_has_spinnable_stop(self, timestamp: float) -> PositionStopType: type_received, data_received = self._wait_for_data(timestamp=timestamp, proto_to_wait_for=ProtoIdentifier.GMO) - while type_received == LatestReceivedType.MON: - self.logger.info("Received MON looking for spinnable stop - ignore / try again") - time.sleep(1) - type_received, data_received = self._wait_for_data(timestamp=time.time(), - proto_to_wait_for=ProtoIdentifier.GMO) - if type_received != LatestReceivedType.GMO or data_received is None: self._spinnable_data_failure() return PositionStopType.GMO_NOT_AVAILABLE @@ -767,10 +761,6 @@ def _check_for_data_content(self, latest, proto_to_wait_for: ProtoIdentifier, ti and latest[ProtoIdentifier.GYM_INFO.value].get('timestamp', 0) >= timestamp: type_of_data_found = LatestReceivedType.GYM return type_of_data_found, data_found - elif ProtoIdentifier.ENCOUNTER.value in latest \ - and latest[ProtoIdentifier.ENCOUNTER.value].get('timestamp', 0) >= timestamp: - type_of_data_found = LatestReceivedType.MON - return type_of_data_found, data_found elif proto_to_wait_for.value not in latest: self.logger.debug("No data linked to the requested proto since MAD started.") return type_of_data_found, data_found