From b5c0e8d0dc945ab0cdc2f2d077c936eb91633525 Mon Sep 17 00:00:00 2001 From: aeon0 Date: Wed, 12 Jan 2022 20:46:14 +0100 Subject: [PATCH] Check stashing after failed runs or chicken/death (#438) * Check stashing after failed runs or chicken/death * optmize * revert some * revert --- src/bot.py | 10 ++++++++-- src/char/basic.py | 6 ++---- src/char/basic_ranged.py | 25 +++++++++---------------- src/run/nihlatak.py | 5 +++-- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/bot.py b/src/bot.py index 01121d1..726463d 100644 --- a/src/bot.py +++ b/src/bot.py @@ -254,9 +254,13 @@ class Bot: if not self._curr_loc: return self.trigger_or_stop("end_game", failed=True) - # Stash stuff, either when item was picked up or after X runs without stashing because of unwanted loot in inventory + # Check if we should force stash (e.g. when picking up items by accident or after failed runs or chicken/death) + force_stash = False self._no_stash_counter += 1 - force_stash = self._no_stash_counter > 4 and self._ui_manager.should_stash(self._config.char["num_loot_columns"]) + if not self._picked_up_items and (self._no_stash_counter > 4 or self._pick_corpse): + self._no_stash_counter = 0 + force_stash = self._ui_manager.should_stash(self._config.char["num_loot_columns"]) + # Stash stuff, either when item was picked up or after X runs without stashing because of unwanted loot in inventory if self._picked_up_items or force_stash: if self._config.char["id_items"]: Logger.info("Identifying items") @@ -337,6 +341,8 @@ class Bot: self._curr_loc, self._picked_up_items = res # in case its the last run or the run was failed, end game, otherwise move to next run if self.is_last_run() or failed_run: + if failed_run: + self._no_stash_counter = 10 # this will force a check if we should stash on next game self.trigger_or_stop("end_game", failed=failed_run) else: self.trigger_or_stop("end_run") diff --git a/src/char/basic.py b/src/char/basic.py index df14333..e41665c 100644 --- a/src/char/basic.py +++ b/src/char/basic.py @@ -29,13 +29,13 @@ class Basic(IChar): keyboard.send(self._skill_hotkeys["right_attack"]) wait(0.05, 0.1) start = time.time() - while (time.time() - start) < time_in_s: + while (time.time() - start) < time_in_s: if self._ui_manager.is_right_skill_active(): wait(0.05, 0.1) mouse.click(button="right") else: wait(0.05, 0.1) - mouse.click(button="left") + mouse.click(button="left") wait(0.01, 0.05) keyboard.send(self._char_config["stand_still"], do_press=False) @@ -55,13 +55,11 @@ class Basic(IChar): # select teleport if available super().pre_move() - def _move_and_attack(self, abs_move: tuple[int, int], atk_len: float): pos_m = self._screen.convert_abs_to_monitor(abs_move) self.pre_move() self.move(pos_m, force_move=True) self._cast_attack_pattern(atk_len) - #this is where we kill bosses diff --git a/src/char/basic_ranged.py b/src/char/basic_ranged.py index db5dccf..d236fc7 100644 --- a/src/char/basic_ranged.py +++ b/src/char/basic_ranged.py @@ -54,7 +54,7 @@ class Basic_Ranged(IChar): wait(0.5, 0.15) -#bosses +#bosses def kill_pindle(self) -> bool: pindle_pos_abs = self._screen.convert_screen_to_abs(self._config.path["pindle_end"][0]) @@ -170,23 +170,16 @@ class Basic_Ranged(IChar): def kill_nihlatak(self, end_nodes: list[int]) -> bool: # Find nilhlatak position - delay = [0.2, 0.3] atk_len = int(self._char_config["atk_len_nihlatak"]) - for i in range(atk_len): - nihlatak_pos_abs = self._pather.find_abs_node_pos(end_nodes[-1], self._screen.grab()) - if nihlatak_pos_abs is None: - return False - cast_pos_abs = np.array([nihlatak_pos_abs[0] * 0.9, nihlatak_pos_abs[1] * 0.9]) - self._left_attack(cast_pos_abs, delay, 90) - # Do some tele "dancing" after each sequence - if i < atk_len - 1: - rot_deg = random.randint(-10, 10) if i % 2 == 0 else random.randint(170, 190) - tele_pos_abs = unit_vector(rotate_vec(cast_pos_abs, rot_deg)) * 100 - pos_m = self._screen.convert_abs_to_monitor(tele_pos_abs) - self.pre_move() - self.move(pos_m) + nihlatak_pos_abs = self._pather.find_abs_node_pos(end_nodes[-1], self._screen.grab()) + if nihlatak_pos_abs is None: + return False + cast_pos_abs = np.array([nihlatak_pos_abs[0] * 0.9, nihlatak_pos_abs[1] * 0.9]) + for _ in range(atk_len): + if self._ui_manager.is_right_skill_active(): + self._right_attack(cast_pos_abs, spray=11) else: - self._right_attack(cast_pos_abs, spray=60) + self._left_attack(cast_pos_abs, spray=11) # Move to items wait(self._cast_duration, self._cast_duration + 0.2) self._pather.traverse_nodes(end_nodes, self, time_out=0.8) diff --git a/src/run/nihlatak.py b/src/run/nihlatak.py index c6e22d4..a247c68 100644 --- a/src/run/nihlatak.py +++ b/src/run/nihlatak.py @@ -105,7 +105,8 @@ class Nihlatak: end_nodes = check_arr[0].end_nodes # Attack & Pick items - self._char.kill_nihlatak(end_nodes) + if not self._char.kill_nihlatak(end_nodes): + return False wait(0.2, 0.3) picked_up_items = self._pickit.pick_up_items(self._char) - return (Location.A5_NIHLATAK_END, picked_up_items) \ No newline at end of file + return (Location.A5_NIHLATAK_END, picked_up_items)