Add merc_chicken param and add highlighted variation of save&exit button (#11)

* typo fix

* add merc chicken param, add highlighted save/exit button

* update readme

* remove files from other branch

* remove debug images, adjust gitignore

* fixed requested changes, revert 1 old logger change
This commit is contained in:
Mitchell Gleed
2021-11-11 23:51:52 +01:00
committed by GitHub
parent 5fd3aabf72
commit fa9f7b2f3e
11 changed files with 36 additions and 19 deletions
+1
View File
@@ -13,3 +13,4 @@ run.onefile-build/
generated/
botty_v*/
custom.ini
*info_*.png
+2 -1
View File
@@ -92,7 +92,8 @@ num_loot_columns | Number of columns in inventory used for loot (from left!). Re
take_health_potion | Health percentage when healing potion will be used
take_mana_potion | Mana percentage when mana potion will be used. Currently belt managment is not very clever and it is safest to only pick up health pots and make sure mana reg is enough for pindle to not need mana pots.
heal_merc | Merc health percentage when giving healing potion to merc
chicken | Health percentage when chicken (leaving game)
chicken | Will chicken (leave game) when player health percentage drops below set value, range 0 to 1. Set to 0 to not chicken.
merc_chicken | Will chicken (leave game) when merc health percentage drops below set value, range 0 to 1. Set to 0 to not chicken.
show_items | Hotkey for "show items"
inventory_screen | Hotkey to open up inventory
stand_still | Hotkey for "stand still". Note this can not be the default shift key as it would interfere with the merc healing routine.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

+1
View File
@@ -29,6 +29,7 @@ take_health_potion=0.8
take_mana_potion=0.6
heal_merc=0.5
chicken=0.2
merc_chicken=0
show_items=alt
inventory_screen=i
; note: stand_still can not be the default "shift" as it would interfere with merc healing
+1
View File
@@ -48,6 +48,7 @@ class Config:
"take_mana_potion": float(self._select_val("char", "take_mana_potion")),
"heal_merc": float(self._select_val("char", "heal_merc")),
"chicken": float(self._select_val("char", "chicken")),
"merc_chicken": float(self._select_val("char", "merc_chicken")),
"tp": self._select_val("char", "tp"),
"show_belt": self._select_val("char", "show_belt"),
"potion1": self._select_val("char", "potion1"),
+18 -11
View File
@@ -77,6 +77,17 @@ class HealthManager:
merc_health_percentage = (float(np.sum(health_tresh)) / health_tresh.size) * (1/255.0)
return merc_health_percentage
def _do_chicken(self, img, run_thread):
cv2.imwrite("info_debug_chicken.png", img)
# clean up key presses that might be pressed in the run_thread
keyboard.release(self._config.char["stand_still"])
keyboard.release(self._config.char["show_items"])
time.sleep(0.01)
self._ui_manager.save_and_exit()
self._did_chicken = True
kill_thread(run_thread)
self._do_monitor = False
def start_monitor(self, run_thread: Thread):
Logger.debug("Start health monitoring")
self._do_monitor = True
@@ -95,16 +106,8 @@ class HealthManager:
self._last_health = time.time()
# give the chicken a 4 sec delay to give time for a healing pot and avoid endless loop of chicken
elif health_percentage < self._config.char["chicken"] and (time.time() - start) > 4:
Logger.warning("Trying to chicken!")
cv2.imwrite("info_debug_chicken.png", img)
# clean up key presses that might be pressed in the run_thread
keyboard.release(self._config.char["stand_still"])
keyboard.release(self._config.char["show_items"])
time.sleep(0.01)
self._ui_manager.save_and_exit()
self._did_chicken = True
kill_thread(run_thread)
self._do_monitor = False
Logger.warning(f"Trying to chicken, player HP {(health_percentage*100):.1f}%!")
self._do_chicken(img, run_thread)
break
# check mana
mana_percentage = self.get_mana(img)
@@ -117,7 +120,11 @@ class HealthManager:
if merc_alive:
merc_health_percentage = self.get_merc_health(img)
last_drink = time.time() - self._last_merc_healh
if merc_health_percentage < self._config.char["heal_merc"] and last_drink > 5.0:
if merc_health_percentage < self._config.char["merc_chicken"]:
Logger.warning(f"Trying to chicken, merc HP {(merc_health_percentage*100):.1f}%!")
self._do_chicken(img, run_thread)
break
elif merc_health_percentage < self._config.char["heal_merc"] and last_drink > 5.0:
self._drink_poition(img, "health", merc=True)
self._last_merc_healh = time.time()
Logger.debug("Stop health monitoring")
+1 -3
View File
@@ -50,9 +50,7 @@ class PickIt:
# no need to stash potions, scrolls, or gold
if (("potion" not in closest_item.name) and ("tp_scroll" != closest_item.name) and ("misc_gold" not in closest_item.name)):
found_items = True
Logger.info(f"** Looted {closest_item.name}")
else:
Logger.info(f"Picking up {closest_item.name}")
Logger.info(f"Picking up {closest_item.name}")
mouse.move(x_m, y_m)
time.sleep(0.1)
mouse.click(button="left")
+10 -3
View File
@@ -80,7 +80,8 @@ class TemplateFinder:
"PLAY_BTN": [load_template("assets/templates/play_btn.png", 1.0), 1.0],
"PLAY_BTN_GRAY": [load_template("assets/templates/play_btn_gray.png", 1.0), 1.0],
"HELL_BTN": [load_template("assets/templates/hell_btn.png", 1.0), 1.0],
"SAVE_AND_EXIT": [load_template("assets/templates/save_and_exit.png", 1.0), 1.0],
"SAVE_AND_EXIT_NO_HIGHLIGHT": [load_template("assets/templates/save_and_exit_no_highlight.png", 1.0), 1.0],
"SAVE_AND_EXIT_HIGHLIGHT": [load_template("assets/templates/save_and_exit_highlight.png", 1.0), 1.0],
"SERVER_ISSUES": [load_template("assets/templates/server_issues.png", 1.0), 1.0],
"WAYPOINT_MENU": [load_template("assets/templates/waypoint_menu.png", 1.0), 1.0],
"MERC": [load_template("assets/templates/merc.png", 1.0), 1.0],
@@ -161,7 +162,7 @@ class TemplateFinder:
return True, ref_point
return False, None
def search_and_wait(self, ref: str, roi: List[float] = None, time_out: float = None, threshold: float = 0.7) -> Tuple[bool, Tuple[float, float]]:
def search_and_wait(self, ref: Union[str, List[str]], roi: List[float] = None, time_out: float = None, threshold: float = 0.7) -> Tuple[bool, Tuple[float, float]]:
"""
Helper function that will loop and keep searching for a template
:param ref: Key of template which has been loaded beforehand
@@ -173,7 +174,13 @@ class TemplateFinder:
while 1:
img = self._screen.grab()
is_loading_black_roi = np.average(img[:, 0:self._config.ui_roi["loading_left_black"][2]]) < 1.0
success, pos = self.search(ref, img, roi=roi, threshold=threshold)
if type(ref) is str:
ref = [ref]
for x in ref:
success, pos = self.search(x, img, roi=roi, threshold=threshold)
if success:
break
if not is_loading_black_roi and success:
return True, pos
if time_out is not None and (time.time() - start) > time_out:
+2 -1
View File
@@ -136,13 +136,14 @@ class UiManager():
keyboard.send("esc")
wait(0.1)
exit_btn_pos = (self._config.ui_pos["save_and_exit_x"], self._config.ui_pos["save_and_exit_y"])
found, _ = self._template_finder.search_and_wait("SAVE_AND_EXIT", roi=self._config.ui_roi["save_and_exit"], time_out=7)
found, _ = self._template_finder.search_and_wait(["SAVE_AND_EXIT_NO_HIGHLIGHT","SAVE_AND_EXIT_HIGHLIGHT"], roi=self._config.ui_roi["save_and_exit"], time_out=7)
if found:
x_m, y_m = self._screen.convert_screen_to_monitor(exit_btn_pos)
mouse.move(x_m, y_m, randomize=12)
wait(0.1)
mouse.click(button="left")
return True
return False
def start_hell_game(self) -> bool: