diff --git a/.gitignore b/.gitignore index afe293f..4a8292e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ run.onefile-build/ generated/ botty_v*/ custom.ini +*info_*.png diff --git a/README.md b/README.md index 79c2784..41ad3ca 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,8 @@ num_loot_columns | Number of columns in inventory used for loot (from left!). Re take_health_potion | Health percentage when healing potion will be used take_mana_potion | Mana percentage when mana potion will be used. Currently belt managment is not very clever and it is safest to only pick up health pots and make sure mana reg is enough for pindle to not need mana pots. heal_merc | Merc health percentage when giving healing potion to merc -chicken | Health percentage when chicken (leaving game) +chicken | Will chicken (leave game) when player health percentage drops below set value, range 0 to 1. Set to 0 to not chicken. +merc_chicken | Will chicken (leave game) when merc health percentage drops below set value, range 0 to 1. Set to 0 to not chicken. show_items | Hotkey for "show items" inventory_screen | Hotkey to open up inventory stand_still | Hotkey for "stand still". Note this can not be the default shift key as it would interfere with the merc healing routine. diff --git a/assets/templates/save_and_exit.png b/assets/templates/save_and_exit.png deleted file mode 100644 index e68792c..0000000 Binary files a/assets/templates/save_and_exit.png and /dev/null differ diff --git a/assets/templates/save_and_exit_highlight.png b/assets/templates/save_and_exit_highlight.png new file mode 100644 index 0000000..b7181ee Binary files /dev/null and b/assets/templates/save_and_exit_highlight.png differ diff --git a/assets/templates/save_and_exit_no_highlight.png b/assets/templates/save_and_exit_no_highlight.png new file mode 100644 index 0000000..739bf99 Binary files /dev/null and b/assets/templates/save_and_exit_no_highlight.png differ diff --git a/params.ini b/params.ini index 50c7a91..6ccce44 100644 --- a/params.ini +++ b/params.ini @@ -29,6 +29,7 @@ take_health_potion=0.8 take_mana_potion=0.6 heal_merc=0.5 chicken=0.2 +merc_chicken=0 show_items=alt inventory_screen=i ; note: stand_still can not be the default "shift" as it would interfere with merc healing diff --git a/src/config.py b/src/config.py index 76be933..dfdb479 100644 --- a/src/config.py +++ b/src/config.py @@ -48,6 +48,7 @@ class Config: "take_mana_potion": float(self._select_val("char", "take_mana_potion")), "heal_merc": float(self._select_val("char", "heal_merc")), "chicken": float(self._select_val("char", "chicken")), + "merc_chicken": float(self._select_val("char", "merc_chicken")), "tp": self._select_val("char", "tp"), "show_belt": self._select_val("char", "show_belt"), "potion1": self._select_val("char", "potion1"), diff --git a/src/health_manager.py b/src/health_manager.py index 10d3e01..348ebfa 100644 --- a/src/health_manager.py +++ b/src/health_manager.py @@ -77,6 +77,17 @@ class HealthManager: merc_health_percentage = (float(np.sum(health_tresh)) / health_tresh.size) * (1/255.0) return merc_health_percentage + def _do_chicken(self, img, run_thread): + cv2.imwrite("info_debug_chicken.png", img) + # clean up key presses that might be pressed in the run_thread + keyboard.release(self._config.char["stand_still"]) + keyboard.release(self._config.char["show_items"]) + time.sleep(0.01) + self._ui_manager.save_and_exit() + self._did_chicken = True + kill_thread(run_thread) + self._do_monitor = False + def start_monitor(self, run_thread: Thread): Logger.debug("Start health monitoring") self._do_monitor = True @@ -95,16 +106,8 @@ class HealthManager: self._last_health = time.time() # give the chicken a 4 sec delay to give time for a healing pot and avoid endless loop of chicken elif health_percentage < self._config.char["chicken"] and (time.time() - start) > 4: - Logger.warning("Trying to chicken!") - cv2.imwrite("info_debug_chicken.png", img) - # clean up key presses that might be pressed in the run_thread - keyboard.release(self._config.char["stand_still"]) - keyboard.release(self._config.char["show_items"]) - time.sleep(0.01) - self._ui_manager.save_and_exit() - self._did_chicken = True - kill_thread(run_thread) - self._do_monitor = False + Logger.warning(f"Trying to chicken, player HP {(health_percentage*100):.1f}%!") + self._do_chicken(img, run_thread) break # check mana mana_percentage = self.get_mana(img) @@ -117,7 +120,11 @@ class HealthManager: if merc_alive: merc_health_percentage = self.get_merc_health(img) last_drink = time.time() - self._last_merc_healh - if merc_health_percentage < self._config.char["heal_merc"] and last_drink > 5.0: + if merc_health_percentage < self._config.char["merc_chicken"]: + Logger.warning(f"Trying to chicken, merc HP {(merc_health_percentage*100):.1f}%!") + self._do_chicken(img, run_thread) + break + elif merc_health_percentage < self._config.char["heal_merc"] and last_drink > 5.0: self._drink_poition(img, "health", merc=True) self._last_merc_healh = time.time() Logger.debug("Stop health monitoring") diff --git a/src/pickit.py b/src/pickit.py index 52f662f..6d12554 100644 --- a/src/pickit.py +++ b/src/pickit.py @@ -50,9 +50,7 @@ class PickIt: # no need to stash potions, scrolls, or gold if (("potion" not in closest_item.name) and ("tp_scroll" != closest_item.name) and ("misc_gold" not in closest_item.name)): found_items = True - Logger.info(f"** Looted {closest_item.name}") - else: - Logger.info(f"Picking up {closest_item.name}") + Logger.info(f"Picking up {closest_item.name}") mouse.move(x_m, y_m) time.sleep(0.1) mouse.click(button="left") diff --git a/src/template_finder.py b/src/template_finder.py index f9cf8ec..43258f0 100644 --- a/src/template_finder.py +++ b/src/template_finder.py @@ -80,7 +80,8 @@ class TemplateFinder: "PLAY_BTN": [load_template("assets/templates/play_btn.png", 1.0), 1.0], "PLAY_BTN_GRAY": [load_template("assets/templates/play_btn_gray.png", 1.0), 1.0], "HELL_BTN": [load_template("assets/templates/hell_btn.png", 1.0), 1.0], - "SAVE_AND_EXIT": [load_template("assets/templates/save_and_exit.png", 1.0), 1.0], + "SAVE_AND_EXIT_NO_HIGHLIGHT": [load_template("assets/templates/save_and_exit_no_highlight.png", 1.0), 1.0], + "SAVE_AND_EXIT_HIGHLIGHT": [load_template("assets/templates/save_and_exit_highlight.png", 1.0), 1.0], "SERVER_ISSUES": [load_template("assets/templates/server_issues.png", 1.0), 1.0], "WAYPOINT_MENU": [load_template("assets/templates/waypoint_menu.png", 1.0), 1.0], "MERC": [load_template("assets/templates/merc.png", 1.0), 1.0], @@ -161,7 +162,7 @@ class TemplateFinder: return True, ref_point return False, None - def search_and_wait(self, ref: str, roi: List[float] = None, time_out: float = None, threshold: float = 0.7) -> Tuple[bool, Tuple[float, float]]: + def search_and_wait(self, ref: Union[str, List[str]], roi: List[float] = None, time_out: float = None, threshold: float = 0.7) -> Tuple[bool, Tuple[float, float]]: """ Helper function that will loop and keep searching for a template :param ref: Key of template which has been loaded beforehand @@ -173,7 +174,13 @@ class TemplateFinder: while 1: img = self._screen.grab() is_loading_black_roi = np.average(img[:, 0:self._config.ui_roi["loading_left_black"][2]]) < 1.0 - success, pos = self.search(ref, img, roi=roi, threshold=threshold) + + if type(ref) is str: + ref = [ref] + for x in ref: + success, pos = self.search(x, img, roi=roi, threshold=threshold) + if success: + break if not is_loading_black_roi and success: return True, pos if time_out is not None and (time.time() - start) > time_out: diff --git a/src/ui_manager.py b/src/ui_manager.py index f985595..becf46f 100644 --- a/src/ui_manager.py +++ b/src/ui_manager.py @@ -136,13 +136,14 @@ class UiManager(): keyboard.send("esc") wait(0.1) exit_btn_pos = (self._config.ui_pos["save_and_exit_x"], self._config.ui_pos["save_and_exit_y"]) - found, _ = self._template_finder.search_and_wait("SAVE_AND_EXIT", roi=self._config.ui_roi["save_and_exit"], time_out=7) + found, _ = self._template_finder.search_and_wait(["SAVE_AND_EXIT_NO_HIGHLIGHT","SAVE_AND_EXIT_HIGHLIGHT"], roi=self._config.ui_roi["save_and_exit"], time_out=7) if found: x_m, y_m = self._screen.convert_screen_to_monitor(exit_btn_pos) mouse.move(x_m, y_m, randomize=12) wait(0.1) mouse.click(button="left") return True + return False def start_hell_game(self) -> bool: