Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make XP purchase chance configurable #70

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions alune/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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"]
7 changes: 7 additions & 0 deletions alune/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down