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/initiative.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (30 sloc)
1.13 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 roll_initiative(character: Character) -> None: | |
"""Roll initiative with advantage""" | |
print("\nRolling initiative with advantage (Dex mod applies)") | |
# Get two rolls due to advantage | |
roll1 = character.roll_saving_throw("dexterity")[1] # Just get the raw roll | |
roll2 = character.roll_saving_throw("dexterity")[1] | |
# Use the higher roll | |
base_roll = max(roll1, roll2) | |
print(f"Rolling with advantage: {roll1} and {roll2}, using {base_roll}") | |
# Add Dex modifier | |
dex_mod = character.dexterity_mod | |
total = base_roll + dex_mod | |
print(f"Adding: {dex_mod:+d} dexterity modifier") | |
print(f"Final Initiative: {total}") | |
def main(): | |
character = Character("Your Character") | |
while True: | |
print("\nAvailable commands:") | |
print("1. Roll Initiative") | |
print("2. Exit") | |
choice = input("\nEnter choice (1-2): ") | |
if choice == "1": | |
roll_initiative(character) | |
elif choice == "2": | |
break | |
else: | |
print("Invalid choice") | |
if __name__ == "__main__": | |
main() |