Skip to content

character_classes

character_classes

Defines character classes for player characters.

CharacterClass

CharacterClass(character_class_type: CharacterClassType, level: int = 1, constitution_modifier: int = 0)

Defines a character class for a player character.

Attributes:

  • class_type (CharacterClassType) –

    The type of the character class.

  • saving_throws (List[int]) –

    The saving throw values.

  • levels (List[ClassLevel]) –

    The class levels.

  • current_level (ClassLevel) –

    The current level of the character.

  • hit_die (str) –

    The hit die for the character class.

  • hp (int) –

    The current hit points.

  • xp (int) –

    The current experience points.

xp_needed_for_next_level property

xp_needed_for_next_level: int

Return the XP needed to reach the next level.

level_up

level_up(hp_modifier: int = 0) -> bool

Level up the character if possible.

If the character's current XP meets the next level's requirement, the character's current_level is populated with the next level available for the class. Hit points are rolled using the hit die appropriate for the character's class and are applied to the character's CharacterClass instance.

Example:

    >>> pc = PlayerCharacter(name="Sckricko", character_class=CharacterClassType.WARRIOR)
    >>> pc.character_class.xp = 2000  # Manually setting XP to meet level-up criteria
    >>> hp_modifier = pc.abilities[AbilityTypes.CONSTITUTION].modifiers[ModifierTypes.HP]
    >>> new_level = pc.character_class.level_up(hp_modifier)
    >>> new_level.level_num
    2

Parameters:

  • hp_modifier (int, default: 0 ) –

    Hit point bonus or penalty to apply to the HP roll when leveling.

Returns:

  • bool ( bool ) –

    True if the character leveled up, otherwise False.

Raises:

  • ValueError

    Raised if leveling up is not possible due to insufficient XP or maximum level reached.

roll_hp

roll_hp(hp_modifier: int = 0) -> DiceRoll

Roll hit points for the character.

Parameters:

  • hp_modifier (int, default: 0 ) –

    Bonus or penalty to apply to the hit point roll.

Returns:

  • DiceRoll ( DiceRoll ) –

    The dice roll result.

ClassLevel

ClassLevel(level_num: int, title: str, xp_required_for_level: int, hit_dice: str, thac0: int, spell_slots: Union[None, str, List[Tuple[int, int]]] = None)

Represents a single level in a character class.

Attributes:

  • level_num (int) –

    The level number.

  • title (str) –

    The title for the level.

  • required_xp (int) –

    The XP required to reach this level.

  • hit_dice (str) –

    The hit dice for this level.

  • spell_slots (Union[None, str, List[Tuple[int, int]]]) –

    Spell slots available at this level.

get_to_hit_target_ac

get_to_hit_target_ac(target_ac: int)

Get the to-hit roll required for a character of this class and level to hit a target that has the given AC.

all_character_classes module-attribute

all_character_classes = [CharacterClass(CLERIC), CharacterClass(THIEF), CharacterClass(DWARF), CharacterClass(ELF), CharacterClass(FIGHTER), CharacterClass(HALFLING), CharacterClass(MAGIC_USER), CharacterClass(COMMONER)]

class_levels module-attribute

class_levels = {CLERIC: cleric_levels, DWARF: dwarf_levels, ELF: elf_levels, FIGHTER: fighter_levels, HALFLING: halfling_levels, MAGIC_USER: magic_user_levels, THIEF: thief_levels, COMMONER: commoner_levels}