Merge pull request #503 from aeon0/max-consecutive-fails

New Param for fails, if max is reached, kill botty. Defaults off.
This commit is contained in:
egut125
2022-02-04 10:15:16 -05:00
committed by GitHub
5 changed files with 20 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ run_shenk=0
| custom_message_hook | Add your own message hook here to get messages about drops and botty status updates, discord webhook is default |
| logger_lvl | Can be any of [info, debug] and determines how much output you see on the command line |
| max_game_length_s | Botty will attempt to stop whatever its doing and try to restart a new game. Note if this fails, botty will attempt to shut down D2R and Bnet |
| max_consecutive_fails | Botty will stop making games if the number of consecutive fails reaches this max value |
| randomize_runs | 0: the order will be as seen in the params.ini. 1: the order will be random |
| difficulty | Set to `normal` `nightmare` or `hell` for game difficulty |
| message_api_type | Which api to use to send botty messages. Supports "generic_api" (basic discord), or "discord" (discord embeds with images).

View File

@@ -4,6 +4,7 @@ name=Botty
message_api_type=generic_api
custom_message_hook=
max_game_length_s=380
max_consecutive_fails=0
randomize_runs=0
difficulty=hell
info_screenshots=1

View File

@@ -165,6 +165,7 @@ class Config:
"saved_games_folder": Config._select_val("general", "saved_games_folder"),
"name": Config._select_val("general", "name"),
"max_game_length_s": float(Config._select_val("general", "max_game_length_s")),
"max_consecutive_fails": int(Config._select_val("general", "max_consecutive_fails")),
"randomize_runs": bool(int(Config._select_val("general", "randomize_runs"))),
"difficulty": Config._select_val("general", "difficulty"),
"message_api_type": Config._select_val("general", "message_api_type"),

View File

@@ -59,7 +59,8 @@ class GameController:
while 1:
self.health_manager.update_location(self.bot.get_curr_location())
max_game_length_reached = self.game_stats.get_current_game_length() > self._config.general["max_game_length_s"]
if max_game_length_reached or self.death_manager.died() or self.health_manager.did_chicken():
max_consecutive_fails_reached = False if not self._config.general["max_consecutive_fails"] else self.game_stats.get_consecutive_runs_failed() >= self._config.general["max_consecutive_fails"]
if max_game_length_reached or max_consecutive_fails_reached or self.death_manager.died() or self.health_manager.did_chicken():
# Some debug and logging
if max_game_length_reached:
Logger.info(f"Max game length reached. Attempting to restart {self._config.general['name']}!")
@@ -72,7 +73,14 @@ class GameController:
self.bot.stop()
kill_thread(self.bot_thread)
# Try to recover from whatever situation we are and go back to hero selection
do_restart = self.game_recovery.go_to_hero_selection()
if max_consecutive_fails_reached:
msg = f"Consecutive fails {self.game_stats.get_consecutive_runs_failed()} >= Max {self._config.general['max_consecutive_fails']}. Quitting botty."
Logger.error(msg)
if self._config.general["custom_message_hook"]:
messenger.send_message(msg)
os._exit(1)
else:
do_restart = self.game_recovery.go_to_hero_selection()
break
time.sleep(0.5)
self.bot_thread.join()

View File

@@ -24,6 +24,7 @@ class GameStats:
self._death_counter = 0
self._merc_death_counter = 0
self._runs_failed = 0
self._consecutive_runs_failed = 0
self._failed_game_time = 0
self._location = None
self._location_stats = {}
@@ -88,12 +89,14 @@ class GameStats:
self._timer = None
if failed:
self._runs_failed += 1
self._consecutive_runs_failed += 1
if self._location is not None:
self._location_stats[self._location]["failed_runs"] += 1
self._location_stats["totals"]["failed_runs"] += 1
self._failed_game_time += elapsed_time
Logger.warning(f"End failed game: Elpased time: {elapsed_time:.2f}s")
Logger.warning(f"End failed game: Elpased time: {elapsed_time:.2f}s Fails: {self._consecutive_runs_failed}")
else:
self._consecutive_runs_failed = 0
Logger.info(f"End game. Elapsed time: {elapsed_time:.2f}s")
def pause_timer(self):
@@ -116,6 +119,9 @@ class GameStats:
return self._timepaused - self._timer
else:
return time.time() - self._timer
def get_consecutive_runs_failed(self):
return self._consecutive_runs_failed
def _create_msg(self):
elapsed_time = time.time() - self._start_time