feat(bot): Go shopping!

This commit is contained in:
aeon0
2021-11-08 23:43:58 +01:00
parent efabf671d0
commit 2cdab92ba9
7 changed files with 76 additions and 3 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+15
View File
@@ -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:
+2 -2
View File
@@ -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")
+2
View File
@@ -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
+52 -1
View File
@@ -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)
+5
View File
@@ -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