Fix/robustify a4 start (#232)
This commit is contained in:
@@ -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 |
|
||||
| --------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
@@ -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]
|
||||
;==================================================================;
|
||||
|
||||
+9
-2
@@ -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)
|
||||
|
||||
+1
-2
@@ -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 = {}
|
||||
|
||||
@@ -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:
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user