DnD_5e.utility_methods_dnd package
Module contents
A module containing useful functions for other modules in this DnD 5e combat project
- DnD_5e.utility_methods_dnd.ability_to_mod(score: int) int[source]
Convert an ability score to a modifier
- Parameters:
score (integer between 1 and 30 (inclusive)) – the ability score to convert
- Returns:
the ability modifier
- Return type:
- Raise:
ValueError if score is invalid
- DnD_5e.utility_methods_dnd.validate_dice(dice) Tuple[int, int][source]
Determine whether a given dice representation is valid. If it is, return the dice in tuple form
- Parameters:
dice (a tuple of dice number and dice type (e.g., (1, 6)) or a string of format dicenum + "d" + dicetype (e.g., "1d6")) – the dice to validate
- Returns:
the dice representation
- Return type:
TYPE_DICE_TUPLE- Raise:
ValueError if dice is invalid
- DnD_5e.utility_methods_dnd.roll_dice(dice_type: int, num: int = 1, modifier: int = 0, adv: int = 0, critable: bool = False) Tuple[int, int][source]
Roll dice (applying advantage as specified), add the modifier (but don’t go below 0), and return a result that includes the total number and an integer that indicates whether or not the roll was a crit
- Parameters:
dice_type (positive integer) – the type of dice to roll (e.g., a d20)
num (positive integer) – the number of dice to roll
modifier (int) – the modifier to add after all dice have been rolled
adv (one of these integers: -1, 0, 1) – indicates whether this roll has advantage
critable (bool) – whether critical success and critical fail are possible
- Returns:
a tuple that contains the total roll value as well as an indicator of whether the roll was a crit or not
- Return type:
TYPE_ROLL_RESULT
- DnD_5e.utility_methods_dnd.cr_to_xp(cr: float | int) int[source]
Convert a challenge rating to an xp value
- DnD_5e.utility_methods_dnd.calc_advantage(advs: List[int] | Tuple[int]) int[source]
Calculate advantage or disadvantage based on a list of advantage values
- Parameters:
advs (a list or tuple of integers) – a list or tuple of advantage values
- Returns:
a value to indicate advantage
- Return type:
one of these integers: -1, 0, 1
- DnD_5e.utility_methods_dnd.time_to_rounds(time_var) int[source]
Convert a given time to a number of rounds
- Parameters:
time_var (string, or tuple containing a positive integer and a string) – a variable that contains some kind of time
- Returns:
the number of rounds that corresponds to time_var
- Return type:
non-negative integer
- Raise:
ValueError if time_var is invalid
- DnD_5e.utility_methods_dnd.proficiency_bonus_per_level(level: int) int[source]
Calculate proficiency bonus based on level
- Parameters:
level (integer between 1 and 20 (inclusive)) – a Character level
- Returns:
the proficiency bonus that corresponds to level
- Return type:
positive integer
- DnD_5e.utility_methods_dnd.proficency_bonus_by_cr(cr: int) int[source]
Calculate proficiency bonus based on challenge rating
- Parameters:
cr (non-negative number) – challenge rating
- Returns:
the proficiency bonus that corresponds to cr
- Return type:
positive integer
- DnD_5e.utility_methods_dnd.ability_from_abbreviation(name: str) str[source]
Get the full ability score name given an abbreviation
- Parameters:
name (one of these strings: "str", "dex", "con", "int", "wis", "cha") – the abbreviated ability score name
- Returns:
the full ability score name that corresponds to name
- Return type:
one of these strings: “strength”, “dexterity”, “constitution”, “intelligence”, “wisdom”, “charisma”
- Raise:
ValueError if name is invalid