diff --git a/src/bot.py b/src/bot.py index 23e444f..65bf6e2 100644 --- a/src/bot.py +++ b/src/bot.py @@ -42,6 +42,7 @@ from run import Pindle, ShenkEld, Trav, Nihlathak, Arcane, Diablo, Vizier from town import TownManager, A1, A2, A3, A4, A5, town_manager from messages import Messenger +from threading import Lock class Bot: @@ -50,6 +51,7 @@ class Bot: self._messenger = Messenger() self._pather = Pather() self._pickit = PickIt() + self._stash_mutex = Lock() # Create Character match Config().char["type"]: @@ -379,12 +381,16 @@ class Bot: # Stash stuff if keep_items or stash_gold: + Logger.info("Stashing items") self._curr_loc, result_items = self._town_manager.stash(self._curr_loc, items=items) sell_items = any([item.sell for item in result_items]) if result_items else None + #Acquire mutex to prevent controller from killing thread during transmutes + self._stash_mutex.acquire() Logger.info("Running transmutes") self._transmute.run_transmutes(force=False) common.close() + self._stash_mutex.release() if not self._curr_loc: return self.trigger_or_stop("end_game", failed=True) self._picked_up_items = False diff --git a/src/game_controller.py b/src/game_controller.py index 802a12a..f02f514 100644 --- a/src/game_controller.py +++ b/src/game_controller.py @@ -55,8 +55,10 @@ class GameController: self.game_stats.log_death(self.death_manager._last_death_screenshot) elif did_chicken: self.game_stats.log_chicken(self.health_manager._last_chicken_screenshot) + self.bot._stash_mutex.acquire() #Grab mutex to ensure stashing is not occuring self.bot.stop() kill_thread(self.bot_thread) + self.bot._stash_mutex.release() # Try to recover from whatever situation we are and go back to hero selection if max_consecutive_fails_reached: msg = f"Consecutive fails {self.game_stats.get_consecutive_runs_failed()} >= Max {Config().general['max_consecutive_fails']}. Quitting botty." diff --git a/src/ui/view.py b/src/ui/view.py index f31f3b2..ff5a537 100644 --- a/src/ui/view.py +++ b/src/ui/view.py @@ -8,7 +8,7 @@ from utils.misc import wait from ui_manager import wait_until_hidden, wait_until_visible, detect_screen_object, select_screen_object_match, ScreenObjects, list_visible_objects, is_visible from inventory import common from screen import convert_screen_to_monitor -from threading import Thread, Lock +from threading import Lock exit_mutex = Lock()