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 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.
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)]