diff --git a/README.md b/README.md index 0edca74..9870568 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,6 @@ run_shenk=0 | [advanced_options] | Descriptions | | -------------------- | --------------------------------------------------------------------- | | pathing_delay_factor | A linear scaling factor, between 1 and 10, applied to pathing delays. | -| template_threshold | Threshold to find templates used during pathing. | | [items] | Descriptions | | --------- | ----------------------------------------------------------------------------------------------------------------------- | diff --git a/assets/templates/a4_wp_2.png b/assets/templates/a4_wp_2.png new file mode 100644 index 0000000..ee8054b Binary files /dev/null and b/assets/templates/a4_wp_2.png differ diff --git a/params.ini b/params.ini index 5df1a13..215e6bb 100644 --- a/params.ini +++ b/params.ini @@ -81,7 +81,6 @@ redemption= [advanced_options] ;===== don't touch unless you know what you're doing ===== pathing_delay_factor=5 -template_threshold=0.68 [items] ;==================================================================; diff --git a/src/char/i_char.py b/src/char/i_char.py index b5596df..d3c5c4e 100644 --- a/src/char/i_char.py +++ b/src/char/i_char.py @@ -41,12 +41,19 @@ class IChar: wait(0.45,0.5) return prev_cast_start - def select_by_template(self, template_type: Union[str, List[str]], success_func: Callable = None, time_out: float = 8) -> bool: + def select_by_template( + self, + template_type: Union[str, List[str]], + success_func: Callable = None, + time_out: float = 8, + threshold: float = 0.68 + ) -> bool: """ Finds any template from the template finder and interacts with it :param template_type: Strings or list of strings of the templates that should be searched for :param success_func: Function that will return True if the interaction is successful e.g. return True when loading screen is reached, defaults to None :param time_out: Timeout for the whole template selection, defaults to None + :param threshold: Threshold which determines if a template is found or not. None will use default form .ini files :return: True if success. False otherwise """ if type(template_type) == list and "A5_STASH" in template_type: @@ -55,7 +62,7 @@ class IChar: keyboard.send("esc") start = time.time() while time_out is None or (time.time() - start) < time_out: - template_match = self._template_finder.search(template_type, self._screen.grab()) + template_match = self._template_finder.search(template_type, self._screen.grab(), threshold=threshold) if template_match.valid: Logger.debug(f"Select {template_match.name} ({template_match.score*100:.1f}% confidence)") x_m, y_m = self._screen.convert_screen_to_monitor(template_match.position) diff --git a/src/config.py b/src/config.py index 73bb431..d86244f 100644 --- a/src/config.py +++ b/src/config.py @@ -99,8 +99,7 @@ class Config: self.char["static_path_eldritch"] = False self.advanced_options = { - "pathing_delay_factor": min(max(int(self._select_val("advanced_options", "pathing_delay_factor")),1),10), - "template_threshold": float(self._select_val("advanced_options", "template_threshold")), + "pathing_delay_factor": min(max(int(self._select_val("advanced_options", "pathing_delay_factor")), 1), 10), } self.items = {} diff --git a/src/template_finder.py b/src/template_finder.py index 00a3b9f..9c06c5c 100644 --- a/src/template_finder.py +++ b/src/template_finder.py @@ -51,7 +51,7 @@ class TemplateFinder: self, ref: Union[str, np.ndarray, List[str]], inp_img: np.ndarray, - threshold: float = None, + threshold: float = 0.68, roi: List[float] = None, normalize_monitor: bool = False, best_match: bool = False, @@ -68,7 +68,6 @@ class TemplateFinder: :param use_grayscale: Use grayscale template matching for speed up :return: Returns a TempalteMatch object with a valid flag """ - threshold = self._config.advanced_options["template_threshold"] if threshold is None else threshold if roi is None: # if no roi is provided roi = full inp_img roi = [0, 0, inp_img.shape[1], inp_img.shape[0]] @@ -148,7 +147,7 @@ class TemplateFinder: ref: Union[str, List[str]], roi: List[float] = None, time_out: float = None, - threshold: float = None, + threshold: float = 0.68, best_match: bool = False, take_ss: bool = True, use_grayscale: bool = False @@ -161,7 +160,6 @@ class TemplateFinder: """ if type(ref) is str: ref = [ref] - threshold = self._config.advanced_options["template_threshold"] if threshold is None else threshold Logger.debug(f"Waiting for Template {ref}") start = time.time() while 1: diff --git a/src/town/a4.py b/src/town/a4.py index 1eb0b62..d85022c 100644 --- a/src/town/a4.py +++ b/src/town/a4.py @@ -32,7 +32,8 @@ class A4(IAct): if not self._pather.traverse_nodes(curr_loc, Location.A4_WP, self._char): return False wait(0.5, 0.7) found_wp_func = lambda: self._template_finder.search("WAYPOINT_MENU", self._screen.grab()).valid - return self._char.select_by_template("A4_WP", found_wp_func) + # decreased threshold because we sometimes walk "over" it during pathing + return self._char.select_by_template(["A4_WP", "A4_WP_2"], found_wp_func, threshold=0.62) def wait_for_tp(self) -> Union[Location, bool]: success = self._template_finder.search_and_wait(["A4_TOWN_4", "A4_TOWN_5", "A4_TOWN_6"], time_out=20).valid