weight config

This commit is contained in:
w 2025-06-03 22:55:39 -03:00
parent 4c2b3f589f
commit 9f9c034461
2 changed files with 18 additions and 0 deletions

View file

@ -21,6 +21,15 @@ def get_config_file() -> str:
raise ConfigError(f'Could not find {config_path}') raise ConfigError(f'Could not find {config_path}')
return 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 = configparser.ConfigParser()
config.read(get_config_file()) config.read(get_config_file())
@ -43,3 +52,5 @@ NOTIFICATION_POLL_INTERVAL = int(config['notification']['PollInterval'])
NOTIFICATION_BATCH_SIZE = int(config['notification']['BatchSize']) NOTIFICATION_BATCH_SIZE = int(config['notification']['BatchSize'])
GACHA_ROLL_INTERVAL = int(config['gacha']['RollInterval']) GACHA_ROLL_INTERVAL = int(config['gacha']['RollInterval'])
RARITY_TO_WEIGHT = get_rarity_to_weight(config['gacha'])

View file

@ -9,6 +9,13 @@ DatabaseLocation = ./gacha_game.db
[gacha] [gacha]
; Number of seconds players have to wait between rolls ; Number of seconds players have to wait between rolls
RollInterval = 72000 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] [notification]
; Number of seconds to sleep while awaiting new notifications ; Number of seconds to sleep while awaiting new notifications