From 9f9c0344618f6bf734505292000c297e3cd9ec4b Mon Sep 17 00:00:00 2001 From: w Date: Tue, 3 Jun 2025 22:55:39 -0300 Subject: [PATCH] weight config --- bot/config.py | 11 +++++++++++ example_config.ini | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/bot/config.py b/bot/config.py index 3621103..fb34223 100644 --- a/bot/config.py +++ b/bot/config.py @@ -21,6 +21,15 @@ def get_config_file() -> str: raise ConfigError(f'Could not find {config_path}') return config_path +def get_rarity_to_weight(config_section): + """Parses Rarity_X keys from config and returns a {rarity: weight} dict.""" + rarity_weights = {} + for key, value in config_section.items(): + if key.startswith("Rarity_"): + rarity = int(key.removeprefix("Rarity_")) + rarity_weights[rarity] = float(value) + return rarity_weights + config = configparser.ConfigParser() config.read(get_config_file()) @@ -43,3 +52,5 @@ NOTIFICATION_POLL_INTERVAL = int(config['notification']['PollInterval']) NOTIFICATION_BATCH_SIZE = int(config['notification']['BatchSize']) GACHA_ROLL_INTERVAL = int(config['gacha']['RollInterval']) + +RARITY_TO_WEIGHT = get_rarity_to_weight(config['gacha']) \ No newline at end of file diff --git a/example_config.ini b/example_config.ini index d7f1c14..5f897cb 100644 --- a/example_config.ini +++ b/example_config.ini @@ -9,6 +9,13 @@ DatabaseLocation = ./gacha_game.db [gacha] ; Number of seconds players have to wait between rolls RollInterval = 72000 +; Rarity drop weights (1 to 5 stars) +; Format: rarity=weight per line +Rarity_1 = 0.7 ; common +Rarity_2 = 0.2 ; uncommon +Rarity_3 = 0.08 ; rare +Rarity_4 = 0.015 ; epic +Rarity_5 = 0.005 ; legendary [notification] ; Number of seconds to sleep while awaiting new notifications