Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Barbarus/skill_check.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87 lines (71 sloc)
3.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from character import Character | |
def print_skill_info(character: Character): | |
"""Print all skill bonuses for the character""" | |
print("\nSkill Bonuses:") | |
# Group skills by ability | |
ability_groups = { | |
"Strength": ["athletics"], | |
"Dexterity": ["acrobatics", "sleight_of_hand", "stealth"], | |
"Intelligence": ["arcana", "history", "investigation", "nature", "religion"], | |
"Wisdom": ["animal_handling", "insight", "medicine", "perception", "survival"], | |
"Charisma": ["deception", "intimidation", "performance", "persuasion"] | |
} | |
for ability, skills in ability_groups.items(): | |
print(f"\n{ability} Skills:") | |
for skill in skills: | |
bonus = character.get_skill_bonus(skill) | |
prof = "✓" if character.skill_proficiencies[skill] else " " | |
print(f"{skill.replace('_', ' ').capitalize():15} {prof} : {bonus:+2d}") | |
def roll_skill_check(character: Character, skill: str, advantage_status: str = 'n') -> None: | |
"""Roll a skill check with advantage/disadvantage""" | |
# Get ability for this skill | |
ability = character.skill_abilities[skill] | |
# Get rolls | |
total, base_roll, is_proficient = character.roll_skill_check(skill, advantage_status) | |
# Show roll details | |
if advantage_status == 'a': | |
roll2 = character.roll_skill_check(skill)[1] # Get another base roll | |
print(f"Rolling with advantage: {base_roll} and {roll2}, using {max(base_roll, roll2)}") | |
elif advantage_status == 'd': | |
roll2 = character.roll_skill_check(skill)[1] | |
print(f"Rolling with disadvantage: {base_roll} and {roll2}, using {min(base_roll, roll2)}") | |
else: | |
print(f"Rolling: {base_roll}") | |
# Show modifier breakdown | |
ability_mod = getattr(character, f"{ability}_mod") | |
prof_bonus = character.proficiency_bonus if is_proficient else 0 | |
print(f"Adding: {ability_mod:+d} {ability} modifier {prof_bonus:+d} proficiency bonus") | |
print(f"Final {skill.replace('_', ' ').capitalize()} check: {total}") | |
def main(): | |
character = Character("Your Character") | |
while True: | |
print("\nAvailable commands:") | |
print("1. Show skill bonuses") | |
print("2. Roll a skill check") | |
print("3. Exit") | |
choice = input("\nEnter choice (1-3): ") | |
if choice == "1": | |
print_skill_info(character) | |
elif choice == "2": | |
print("\nChoose skill:") | |
skills = list(character.skill_abilities.keys()) | |
for i, skill in enumerate(skills, 1): | |
print(f"{i}. {skill.replace('_', ' ').capitalize()}") | |
skill_choice = input(f"\nChoose skill (1-{len(skills)}): ") | |
try: | |
skill_idx = int(skill_choice) - 1 | |
if 0 <= skill_idx < len(skills): | |
skill = skills[skill_idx] | |
advantage = input("Roll with (a)dvantage, (d)isadvantage, or (n)ormal?: ").lower() | |
print() # blank line for readability | |
roll_skill_check(character, skill, advantage) | |
else: | |
print("Invalid skill choice") | |
except ValueError: | |
print("Invalid input") | |
elif choice == "3": | |
break | |
else: | |
print("Invalid choice") | |
if __name__ == "__main__": | |
main() |