Bugfix: Ignore merc death if merc chicken off (#916)
* init * save as... * move timer
This commit is contained in:
+29
-18
@@ -87,9 +87,10 @@ class HealthManager:
|
||||
start = time.time()
|
||||
|
||||
while self._do_monitor:
|
||||
time.sleep(0.1)
|
||||
# Wait until the flag is reset by main.py
|
||||
if self._did_chicken or get_pause_state(): continue
|
||||
if self._did_chicken or get_pause_state():
|
||||
wait(1)
|
||||
continue
|
||||
fn_start = time.perf_counter()
|
||||
img = grab()
|
||||
if is_visible(ScreenObjects.InGame, img):
|
||||
health_percentage = meters.get_health(img)
|
||||
@@ -122,19 +123,20 @@ class HealthManager:
|
||||
belt.drink_potion("mana", stats=[health_percentage, mana_percentage])
|
||||
self._last_mana = time.time()
|
||||
# check merc
|
||||
if is_visible(ScreenObjects.MercIcon, img):
|
||||
merc_health_percentage = meters.get_merc_health(img)
|
||||
merc_hp_potion_delay = 0 if merc_health_percentage == 1 else uniform(9, 10)
|
||||
last_drink = time.time() - self._last_merc_heal
|
||||
if merc_health_percentage <= Config().char["merc_chicken"]:
|
||||
Logger.warning(f"Trying to chicken, merc HP {(merc_health_percentage*100):.1f}%!")
|
||||
self._do_chicken(img)
|
||||
if merc_health_percentage <= Config().char["heal_rejuv_merc"] and last_drink > 4.0:
|
||||
belt.drink_potion("rejuv", merc=True, stats=[merc_health_percentage])
|
||||
self._last_merc_heal = time.time()
|
||||
elif merc_health_percentage <= Config().char["heal_merc"] and last_drink > merc_hp_potion_delay:
|
||||
belt.drink_potion("health", merc=True, stats=[merc_health_percentage])
|
||||
self._last_merc_heal = time.time()
|
||||
if any([Config().char[x] for x in ["heal_rejuv_merc", "merc_chicken", "heal_merc"]]):
|
||||
if is_visible(ScreenObjects.MercIcon, img):
|
||||
merc_health_percentage = meters.get_merc_health(img)
|
||||
merc_hp_potion_delay = 0 if merc_health_percentage == 1 else uniform(9, 10)
|
||||
last_drink = time.time() - self._last_merc_heal
|
||||
if Config().char["merc_chicken"] and (merc_health_percentage <= Config().char["merc_chicken"]):
|
||||
Logger.warning(f"Trying to chicken, merc HP {(merc_health_percentage*100):.1f}%!")
|
||||
self._do_chicken(img)
|
||||
if Config().char["heal_rejuv_merc"] and (merc_health_percentage <= Config().char["heal_rejuv_merc"] and last_drink > 4.0):
|
||||
belt.drink_potion("rejuv", merc=True, stats=[merc_health_percentage])
|
||||
self._last_merc_heal = time.time()
|
||||
elif Config().char["heal_merc"] and (merc_health_percentage <= Config().char["heal_merc"] and last_drink > merc_hp_potion_delay):
|
||||
belt.drink_potion("health", merc=True, stats=[merc_health_percentage])
|
||||
self._last_merc_heal = time.time()
|
||||
if not get_panel_check_paused() and (is_visible(ScreenObjects.LeftPanel, img) or is_visible(ScreenObjects.RightPanel, img)):
|
||||
Logger.warning(f"Found an open inventory / quest / skill / stats page. Close it.")
|
||||
self._count_panel_detects += 1
|
||||
@@ -143,6 +145,10 @@ class HealthManager:
|
||||
Logger.warning(f"Found an open inventory / quest / skill / stats page again. Chicken to dismiss.")
|
||||
self._do_chicken(img)
|
||||
common.close()
|
||||
fn_end = time.perf_counter()
|
||||
wait_time = 3/25 - (fn_start - fn_end)
|
||||
if wait_time > 0:
|
||||
wait(wait_time) # wait 3 frames before rechecking
|
||||
Logger.debug("Stop health monitoring")
|
||||
|
||||
|
||||
@@ -152,9 +158,14 @@ if __name__ == "__main__":
|
||||
import keyboard
|
||||
import os
|
||||
from health_manager import set_pause_state
|
||||
keyboard.add_hotkey('f12', lambda: Logger.info('Exit Health Manager') or os._exit(1))
|
||||
from screen import start_detecting_window, stop_detecting_window, grab
|
||||
keyboard.add_hotkey('f12', lambda: Logger.info('Force Exit (f12)') or os._exit(1))
|
||||
Logger.info("Open d2r window and press f11 to start health manager")
|
||||
keyboard.wait("f11")
|
||||
start_detecting_window()
|
||||
|
||||
manager = HealthManager()
|
||||
set_pause_state(True)
|
||||
set_pause_state(False)
|
||||
Logger.info("Press f12 to exit health manager")
|
||||
health_monitor_thread = threading.Thread(target=manager.start_monitor)
|
||||
health_monitor_thread.start()
|
||||
|
||||
Reference in New Issue
Block a user