Fix logo found on save and exit screen (#91)
This commit is contained in:
1
game.ini
1
game.ini
@@ -111,6 +111,7 @@ repair_btn=477,709,135,120
|
||||
inventory=1290,515,591,247
|
||||
vendor_stash=44,126,600,600
|
||||
skill_right=996,1010,62,62
|
||||
hero_selection_logo=0,0,550,830
|
||||
|
||||
[path]
|
||||
pindle_save_dist=1382,53, 1685,105, 1440,132
|
||||
|
||||
29
src/bot.py
29
src/bot.py
@@ -12,6 +12,7 @@ from char.i_char import IChar
|
||||
from config import Config
|
||||
from health_manager import HealthManager
|
||||
from death_manager import DeathManager
|
||||
from game_recovery import GameRecovery
|
||||
from npc_manager import NpcManager, Npc
|
||||
from pickit import PickIt
|
||||
from game_stats import GameStats
|
||||
@@ -27,6 +28,7 @@ class Bot:
|
||||
def __init__(self):
|
||||
self._config = Config()
|
||||
self._game_stats = GameStats()
|
||||
self._game_recovery = GameRecovery()
|
||||
self._screen = Screen(self._config.general["monitor"])
|
||||
self._template_finder = TemplateFinder(self._screen)
|
||||
self._item_finder = ItemFinder()
|
||||
@@ -120,7 +122,7 @@ class Bot:
|
||||
|
||||
def on_create_game(self):
|
||||
self._game_stats.log_start_game()
|
||||
self._template_finder.search_and_wait("D2_LOGO_HS")
|
||||
self._template_finder.search_and_wait("D2_LOGO_HS", roi=self._config.ui_roi["hero_selection_logo"])
|
||||
self._ui_manager.start_game()
|
||||
self._template_finder.search_and_wait(["A5_TOWN_1", "A5_TOWN_0"])
|
||||
self._tp_is_up = False
|
||||
@@ -333,30 +335,9 @@ class Bot:
|
||||
def on_end_game(self):
|
||||
self._pre_buffed = 0
|
||||
if self._health_manager.did_chicken() or self._death_manager.died():
|
||||
Logger.info("End game while chicken or death happened. Checking where we are at.")
|
||||
# This is a tricky state as we send different actions in different threads.
|
||||
# Chicken could have been succesfull which means we are at hero selection screen
|
||||
# Chicken could have been unsuccesfull, which means we are naked in a5_town
|
||||
# Chicken could have been unsuccesfull, but it already stopped main thread and death manager did not have time to check death -> death screen
|
||||
Logger.info("End game while chicken or death happened. Running game recovery to get back to hero selection.")
|
||||
time.sleep(1.5)
|
||||
is_loading = True
|
||||
while is_loading:
|
||||
is_loading = self._template_finder.search("LOADING", self._screen.grab())[0]
|
||||
time.sleep(0.5)
|
||||
time.sleep(1.5)
|
||||
# Okay we are sure we are not in loading screen, let's check if we are in hero selection or in a5 town
|
||||
img = self._screen.grab()
|
||||
if self._template_finder.search("A5_TOWN_1", img)[0]:
|
||||
Logger.info("We are at town, save and exit game.")
|
||||
self._ui_manager.save_and_exit()
|
||||
elif self._template_finder.search("D2_LOGO_HS", img)[0]:
|
||||
Logger.info("We are at hero selection.")
|
||||
elif self._death_manager.handle_death_screen():
|
||||
Logger.info("For some reason we were still at death screen, but Death Manager should have sent us back to town. save and exit game.")
|
||||
self._ui_manager.save_and_exit()
|
||||
else:
|
||||
Logger.error("Could not determine location after chicken / death. Can not continue...")
|
||||
os._exit(1)
|
||||
self._game_recovery.go_to_hero_selection()
|
||||
else:
|
||||
self._ui_manager.save_and_exit()
|
||||
|
||||
|
||||
@@ -53,12 +53,10 @@ class DeathManager:
|
||||
wait(0.1, 0.2)
|
||||
keyboard.release(self._config.char["show_items"])
|
||||
time.sleep(6)
|
||||
if self._template_finder.search("D2_LOGO_HS", self._screen.grab())[0]:
|
||||
if self._template_finder.search("D2_LOGO_HS", self._screen.grab(), roi=self._config.ui_roi["hero_selection_logo"])[0]:
|
||||
# in this case chicken executed and left the game, but we were still dead.
|
||||
return True
|
||||
keyboard.send("esc")
|
||||
self._template_finder.search_and_wait("A5_TOWN_1")
|
||||
time.sleep(2)
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -69,6 +67,7 @@ class DeathManager:
|
||||
if self.handle_death_screen(run_thread):
|
||||
self._do_monitor = False
|
||||
return
|
||||
Logger.debug("Stop death monitoring")
|
||||
|
||||
|
||||
# Testing:
|
||||
|
||||
@@ -17,8 +17,13 @@ class GameRecovery:
|
||||
self._ui_manager = UiManager(self._screen, self._template_finder)
|
||||
|
||||
def go_to_hero_selection(self):
|
||||
# make sure we are not on loading screen
|
||||
is_loading = True
|
||||
while is_loading:
|
||||
is_loading = self._template_finder.search("LOADING", self._screen.grab())[0]
|
||||
time.sleep(0.5)
|
||||
# first lets just see if you might already be at hero selection
|
||||
found, _ = self._template_finder.search_and_wait("D2_LOGO_HS", time_out=1, take_ss=False)
|
||||
found, _ = self._template_finder.search_and_wait("D2_LOGO_HS", time_out=1, take_ss=False, roi=self._config.ui_roi["hero_selection_logo"])
|
||||
if found:
|
||||
return True
|
||||
# would have been too easy, maybe we have died?
|
||||
@@ -36,3 +41,8 @@ class GameRecovery:
|
||||
time.sleep(1)
|
||||
return self._ui_manager.save_and_exit()
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
game_recovery = GameRecovery()
|
||||
game_recovery.go_to_hero_selection()
|
||||
|
||||
Reference in New Issue
Block a user