diff --git a/alune/config.py b/alune/config.py index 97e83c5..0a48c00 100644 --- a/alune/config.py +++ b/alune/config.py @@ -2,6 +2,7 @@ Module to handle the configuration for the bot. """ +from collections import defaultdict import os.path from random import Random import shutil @@ -71,6 +72,7 @@ def _sanitize(self): self._sanitize_game_mode() self._sanitize_traits() self._sanitize_adb_port() + self._sanitize_chances() def _sanitize_adb_port(self): adb_port = self._config.get("adb_port", 5555) @@ -81,6 +83,17 @@ def _sanitize_adb_port(self): adb_port = 5555 self._config["adb_port"] = adb_port + def _sanitize_chances(self): + chance_config = self._config.get("chances", defaultdict()) + buy_xp_chance = chance_config.get("buy_xp", 33) + try: + buy_xp_chance = int(buy_xp_chance) + except ValueError: + logger.warning(f"The configured buy_xp chance '{buy_xp_chance}' is not a number. Using 33 instead.") + buy_xp_chance = 33 + chance_config["buy_xp"] = buy_xp_chance + self._config["chances"] = chance_config + def _sanitize_log_level(self): """ Sanitize the user configured log level by checking against valid values. @@ -181,3 +194,12 @@ def get_game_mode(self) -> str: The game mode name. """ return self._config["game_mode"] + + def get_chance_to_buy_xp(self) -> int: + """ + Get the chance in percent the bot should buy xp at per check. + + Returns: + The chance in percent from 0 to 100. + """ + return self._config["chances"]["buy_xp"] diff --git a/alune/resources/config.yaml b/alune/resources/config.yaml index 1829ae1..c4913d4 100644 --- a/alune/resources/config.yaml +++ b/alune/resources/config.yaml @@ -27,6 +27,13 @@ surrender_early: false # Default value : 0 (disabled = surrender as fast as possible) surrender_random_delay: 0 +# Configuration for chance events in the bot, in percent. +chances: + # The chance % to buy experience per check - configuring 50 means it's a 50% chance. + # Alune will never try to buy XP when it can't. + buy_xp: 50 + + # Override the default ADB port Alune tries to connect to. # If there is no device listening on this port, a scan will happen to find your device. adb_port: 5555 diff --git a/main.py b/main.py index 8e6edf3..292be76 100644 --- a/main.py +++ b/main.py @@ -265,7 +265,7 @@ async def take_game_decision(adb_instance: ADB, config: AluneConfig): return can_buy_xp = screen.get_button_on_screen(screenshot, Button.buy_xp) - if can_buy_xp and _random.randint(1, 3) == 3: + if can_buy_xp and _random.randint(1, 100) <= config.get_chance_to_buy_xp(): logger.debug("Buying XP") await adb_instance.click_button(Button.buy_xp) await asyncio.sleep(1)