Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Fix health manager pause (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 committed Dec 7, 2021
1 parent d5d1116 commit 3f496af
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
25 changes: 18 additions & 7 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import time
import os
import random
from typing import Union


class Bot:
Expand Down Expand Up @@ -72,7 +73,7 @@ def __init__(self, screen: Screen, game_stats: GameStats, pick_corpse: bool = Fa
# Create member variables
self._pick_corpse = pick_corpse
self._picked_up_items = False
self._curr_loc: Location = None
self._curr_loc: Union[bool, Location] = None
self._tps_left = 20
self._pre_buffed = 0
self._stopping = False
Expand Down Expand Up @@ -220,36 +221,46 @@ def on_maintenance(self):
self.trigger_or_stop("end_game")

def on_run_pindle(self):
res = False
self._do_runs["run_pindle"] = False
res = self._pindle.run(self._curr_loc, not self._pre_buffed)
self._curr_loc = self._pindle.approach(self._curr_loc)
if self._curr_loc:
res = self._pindle.battle(not self._pre_buffed)
if self.is_last_run() or not res:
self.trigger_or_stop("end_game")
else:
self.trigger_or_stop("end_run")
self._curr_loc = res[0]
self._picked_up_items = res[1]
self.trigger_or_stop("end_run")

def on_run_shenk(self):
res = False
self._do_runs["run_shenk"] = False
res = self._shenk.run(self._curr_loc, self._route_config["run_shenk"], not self._pre_buffed)
self._curr_loc = self._shenk.approach(self._curr_loc)
if self._curr_loc:
res = self._shenk.battle(self._route_config["run_shenk"], not self._pre_buffed)
if self.is_last_run() or not res:
self.trigger_or_stop("end_game")
else:
self.trigger_or_stop("end_run")
self._curr_loc = res[0]
self._picked_up_items = res[1]
self.trigger_or_stop("end_run")

def on_run_trav(self):
res = False
self._do_runs["run_trav"] = False
res = self._trav.run(self._curr_loc, not self._pre_buffed)
self._curr_loc = self._trav.approach(self._curr_loc)
if self._curr_loc:
res = self._trav.battle(not self._pre_buffed)
if self.is_last_run() or not res:
self.trigger_or_stop("end_game")
else:
self.trigger_or_stop("end_run")
self._curr_loc = res[0]
self._picked_up_items = res[1]
self.trigger_or_stop("end_run")

def on_end_game(self):
self._curr_loc = False
self._pre_buffed = False
self._ui_manager.save_and_exit()
self._game_stats.log_end_game()
Expand Down
4 changes: 4 additions & 0 deletions src/health_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def reset_chicken_flag(self):
def update_location(self, loc: Location):
if loc is not None and type(loc) == str:
bosses = ["shenk", "eldritch", "pindle", "trav"]
prev_value = self._pausing
self._pausing = not any(substring in loc for substring in bosses)
if self._pausing != prev_value:
debug_str = "pausing" if self._pausing else "active"
Logger.info(f"Health Manager is now {debug_str}")

@staticmethod
def get_health(config: Config, img: np.ndarray) -> float:
Expand Down
8 changes: 5 additions & 3 deletions src/run/pindle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
self._char = char
self._pickit = pickit

def run(self, start_loc: Location, do_pre_buff: bool) -> Union[bool, tuple[Location, bool]]:
def approach(self, start_loc: Location) -> Union[bool, Location]:
# Go through Red Portal in A5
Logger.info("Run Pindle")
loc = self._town_manager.go_to_act(5, start_loc)
Expand All @@ -38,10 +38,12 @@ def run(self, start_loc: Location, do_pre_buff: bool) -> Union[bool, tuple[Locat
return False
wait(0.4)
found_loading_screen_func = lambda: self._ui_manager.wait_for_loading_screen(2.0)

# Kill Pindle
if not self._char.select_by_template(["A5_RED_PORTAL", "A5_RED_PORTAL_TEXT"], found_loading_screen_func):
return False
return Location.A5_PINDLE_START

def battle(self, do_pre_buff: bool) -> Union[bool, tuple[Location, bool]]:
# Kill Pindle
if not self._template_finder.search_and_wait(["PINDLE_0", "PINDLE_1"], threshold=0.65, time_out=20).valid:
return False
if do_pre_buff:
Expand Down
4 changes: 3 additions & 1 deletion src/run/shenk_eld.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ def __init__(
self._char = char
self._pickit = pickit

def run(self, start_loc: Location, do_shenk: bool, do_pre_buff: bool) -> Union[bool, tuple[Location, bool]]:
def approach(self, start_loc: Location) -> Union[bool, Location, bool]:
Logger.info("Run Eldritch")
# Go to Frigid Highlands
if not self._town_manager.open_wp(start_loc):
return False
wait(0.4)
self._ui_manager.use_wp(5, 1)
return Location.A5_ELDRITCH_START

def battle(self, do_shenk: bool, do_pre_buff: bool) -> Union[bool, tuple[Location, bool]]:
# Eldritch
if not self._template_finder.search_and_wait(["ELDRITCH_0", "ELDRITCH_START"], threshold=0.65, time_out=20).valid:
return False
Expand Down
8 changes: 5 additions & 3 deletions src/run/trav.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ def __init__(
self._char = char
self._pickit = pickit

def run(self, start_loc: Location, do_pre_buff: bool) -> Union[bool, tuple[Location, bool]]:
def approach(self, start_loc: Location) -> Union[bool, Location]:
# Go to Travincal via waypoint
Logger.info("Run Trav")
if not self._char.can_teleport():
Logger.error("Trav is currently only supported for teleporting builds. Skipping trav")
return True
Logger.error("Trav is currently only supported for teleporting builds")
return False
if not self._town_manager.open_wp(start_loc):
return False
wait(0.4)
self._ui_manager.use_wp(3, 7)
return Location.A3_TRAV_START

def battle(self, do_pre_buff: bool) -> Union[bool, tuple[Location, bool]]:
# Kill Council
if not self._template_finder.search_and_wait(["TRAV_0", "TRAV_1"], threshold=0.65, time_out=20).valid:
return False
Expand Down

0 comments on commit 3f496af

Please sign in to comment.