diff --git a/assets/templates/repair_btn.png b/assets/templates/repair_btn.png new file mode 100644 index 0000000..72fba98 Binary files /dev/null and b/assets/templates/repair_btn.png differ diff --git a/assets/templates/tp_tomb.png b/assets/templates/tp_tomb.png new file mode 100644 index 0000000..5f5bfe8 Binary files /dev/null and b/assets/templates/tp_tomb.png differ diff --git a/src/bot.py b/src/bot.py index f764727..9ea6854 100644 --- a/src/bot.py +++ b/src/bot.py @@ -54,6 +54,7 @@ class Bot: self._tp_is_up = False self._curr_location: Location = None self._timer = None + self._tps_left = 20 self._states=['hero_selection', 'a5_town', 'pindle', 'shenk'] self._transitions = [ @@ -157,8 +158,21 @@ class Bot: else: Logger.warning("Could not find stash, continue...") + if self._tps_left < 4: + Logger.info("Repairing and buying tps at Lazurk") + if not self._pather.traverse_nodes(self._curr_location, Location.LARZUK, self._char): + self.trigger("end_game") + return + self._curr_location = Location.LARZUK + self._npc_manager.open_npc_menu(Npc.LARZUK) + self._npc_manager.press_npc_btn(Npc.LARZUK, "trade_repair") + if self._ui_manager.repair_and_fill_up_tp(close_when_done=True): + self._tps_left = 20 + wait(0.8) + # Check if merc needs to be revived merc_alive, _ = self._template_finder.search("MERC", self._screen.grab(), threshold=0.9, roi=[0, 0, 200, 200]) + print(merc_alive) if not merc_alive: Logger.info("Reviveing merc") if not self._pather.traverse_nodes(self._curr_location, Location.QUAL_KEHK, self._char): @@ -309,6 +323,7 @@ class Bot: def on_end_run(self): success = self._char.tp_town() + self._tps_left -= 1 if success: success, _= self._template_finder.search_and_wait("A5_TOWN_1", time_out=10) if success: diff --git a/src/pather.py b/src/pather.py index 6162214..328d7c2 100644 --- a/src/pather.py +++ b/src/pather.py @@ -65,7 +65,7 @@ class Pather: 10: {"A5_TOWN_4": (-708, 87), "A5_TOWN_6": (-16, -48), "A5_TOWN_8": (482, 196)}, 11: {"A5_TOWN_6": (-448, -322), "A5_TOWN_8": (50, -78), "A5_TOWN_9": (11, 346)}, 12: {"A5_TOWN_8": (-209, -294), "A5_TOWN_9": (-248, 130)}, - 13: {"A5_TOWN_3": (180, 180),"A5_TOWN_10": (-800, 332)}, + 13: {"A5_TOWN_3": (180, 180),"A5_TOWN_10": (-800, 332), "A5_TOWN_4": (822, 146)}, 14: {"A5_TOWN_3": (670, 260), "A5_TOWN_10": (-300, 420)}, # Pindle 100: {"PINDLE_7": (576, -138), "PINDLE_0": (-146, -60), "PINDLE_1": (-19, 335), "PINDLE_2": (-549, 127)}, @@ -263,5 +263,5 @@ if __name__ == "__main__": ui_manager = UiManager(screen, t_finder) char = Sorceress(config.sorceress, config.char, screen, t_finder, ui_manager, pather) # pather.traverse_nodes_fixed("PINDLE", char) - pather.traverse_nodes(Location.LARZUK, Location.NIHLATHAK_PORTAL, char) + pather.traverse_nodes(Location.A5_STASH, Location.LARZUK, char) # pather._display_all_nodes_debug(filter="A5_TOWN") diff --git a/src/template_finder.py b/src/template_finder.py index 73ee5ae..8444113 100644 --- a/src/template_finder.py +++ b/src/template_finder.py @@ -87,6 +87,8 @@ class TemplateFinder: "MERC": [load_template("assets/templates/merc.png", 1.0), 1.0], "TELE_ACTIVE": [load_template("assets/templates/tele_active.png", 1.0), 1.0], "TELE_INACTIVE": [load_template("assets/templates/tele_inactive.png", 1.0), 1.0], + "REPAIR_BTN": [load_template("assets/templates/repair_btn.png", 1.0), 1.0], + "TP_TOMB": [load_template("assets/templates/tp_tomb.png", 1.0), 1.0], "SUPER_HEALING_POTION": [load_template("assets/templates/super_healing_potion.png", 1.0), 1.0], "SUPER_MANA_POTION": [load_template("assets/templates/super_mana_potion.png", 1.0), 1.0], # NPC: Qual-Kehk diff --git a/src/ui_manager.py b/src/ui_manager.py index d7901d2..f985595 100644 --- a/src/ui_manager.py +++ b/src/ui_manager.py @@ -332,6 +332,55 @@ class UiManager(): wait(0.2, 0.25) keyboard.send(self._config.char["inventory_screen"]) + def repair_and_fill_up_tp(self, close_when_done:bool = False) -> bool: + """ + Repair and fills up TP buy selling tomb and buying. Vendor inventory needs to be open! + :return: Bool if success + """ + found, pos_repair_abs = self._template_finder.search_and_wait("REPAIR_BTN", roi=self._config.ui_roi["repair_btn"], time_out=4) + if not found: + return False + x, y = self._screen.convert_screen_to_monitor(pos_repair_abs) + mouse.move(x, y, randomize=7) + wait(0.1, 0.15) + mouse.click(button="left") + wait(0.1, 0.15) + x, y = self._screen.convert_screen_to_monitor((self._config.ui_pos["vendor_misc_x"], self._config.ui_pos["vendor_misc_y"])) + mouse.move(x, y, randomize=5) + wait(0.1, 0.15) + mouse.click(button="left") + wait(0.5, 0.6) + found, pos_tp_inventory = self._template_finder.search_and_wait("TP_TOMB", roi=self._config.ui_roi["inventory"], time_out=4) + if not found: + return False + x, y = self._screen.convert_screen_to_monitor(pos_tp_inventory) + keyboard.send('ctrl', do_release=False) + mouse.move(x, y, randomize=4) + wait(0.1, 0.15) + mouse.press(button="left") + wait(0.25, 0.35) + mouse.release(button="left") + wait(0.5, 0.6) + keyboard.send('ctrl', do_press=False) + found, pos_tp_inventory = self._template_finder.search_and_wait("TP_TOMB", roi=self._config.ui_roi["vendor_stash"], time_out=4) + if not found: + return False + x, y = self._screen.convert_screen_to_monitor(pos_tp_inventory) + keyboard.send('ctrl', do_release=False) + mouse.move(x, y, randomize=4) + wait(0.1, 0.15) + mouse.click(button="right") + wait(0.1, 0.15) + keyboard.send('ctrl', do_press=False) + if close_when_done: + wait(0.1, 0.2) + keyboard.send("esc") + # just in case also bring cursor to center and click + x, y = self._screen.convert_screen_to_monitor((self._config.ui_pos["center_x"], self._config.ui_pos["center_y"])) + mouse.move(x, y, randomize=20) + mouse.click(button="left") + return True + # Testing: Move to whatever ui to test and run if __name__ == "__main__": @@ -343,7 +392,9 @@ if __name__ == "__main__": screen = Screen(config.general["monitor"]) template_finder = TemplateFinder(screen) ui_manager = UiManager(screen, template_finder) - ui_manager.start_hell_game() + ui_manager.repair_and_fill_up_tp() + wait(0.1, 0.2) + keyboard.send("esc") # ui_manager.stash_all_items(6) # ui_manager.use_wp(4, 1) # ui_manager.fill_up_belt_from_inventory(10) diff --git a/ui.ini b/ui.ini index e641f87..7ffc4f9 100644 --- a/ui.ini +++ b/ui.ini @@ -38,6 +38,8 @@ slot_height=57 stash_personal_btn_x=120 stash_personal_btn_y=115 stash_btn_width=145 +vendor_misc_x=556 +vendor_misc_y=111 ; health, mana, pots health_top=915 health_left=463 @@ -96,3 +98,6 @@ merc_icon=0,0,150,150 loading_left_black=0,0,500,1080 death=770,290,380,75 tp_search=530,180,820,600 +repair_btn=477,709,135,120 +inventory=1290,515,591,247 +vendor_stash=44,126,600,600