# ages.py import random # Каждый возраст: chance (%), explanation, модификатор способностей (dict с дельтами) AGES = { "Youth": { "chance": 15.0, "explanation": "equivalent to human 13 – 17", "modifiers": {"Strength": -2, "Intelligence": -2, "Wisdom": -2}, }, "Adult": { "chance": 50.0, "explanation": "equivalent to human 18 – 35", "modifiers": {}, }, "MiddleAged": { "chance": 20.0, "explanation": "equivalent to human 36 – 55", "modifiers": {"Strength": -2, "Dexterity": -2, "Constitution": -2}, }, "Old": { "chance": 10.0, "explanation": "equivalent to human 56 – 75", "modifiers": {"Strength": -4, "Dexterity": -4, "Constitution": -4, "Charisma": -2}, }, "Ancient": { "chance": 5.0, "explanation": "equivalent to human 76 – 95", "modifiers": {"Strength": -6, "Dexterity": -6, "Constitution": -6, "Charisma": -4}, }, } def get_age_and_modify_abilities( ability_scores: dict[str, int], ) -> tuple[str, str, dict[str, int]]: """Выбирает возрастную категорию и применяет модификаторы к копии ability_scores.""" total = sum(v["chance"] for v in AGES.values()) r = random.random() * total cumulative = 0.0 selected_key = None for key, data in AGES.items(): cumulative += data["chance"] if r <= cumulative: selected_key = key break if selected_key is None: selected_key = list(AGES.keys())[-1] data = AGES[selected_key] aged_scores = dict(ability_scores) for stat, delta in data["modifiers"].items(): aged_scores[stat] = aged_scores.get(stat, 0) + delta return selected_key, data["explanation"], aged_scores