player_character
player_character
Module containing the PlayerCharacter class. Use PlayerCharacter to represent a PC the player adds to their party.
Alignment
PlayerCharacter
PlayerCharacter(name: str, character_class_type: CharacterClassType, level: int = 1, xp_adjustment_percentage: int = 0)
Represents a player character (PC) in the game.
Attributes:
-
name
(str
) –The name of the character.
-
abilities
(dict
) –A dictionary of the character's abilities.
-
character_class
(CharacterClass
) –The character's class.
-
inventory
(Inventory
) –The character's inventory.
-
xp_adjustment_percentage
(int
) –The character's XP adjustment based on the scores of ability their prime requisite(s). This value is set when the character's class is set, or when restoring a saved character.
is_alive
property
is_alive: bool
Returns True if the character is alive.
The character is considered alive if their hit points are greater than 0.
Returns:
-
bool
(bool
) –True if the character is alive (hit points > 0), False otherwise.
xp_needed_for_next_level
property
xp_needed_for_next_level: int
Get the amount of XP needed for the character to reach the next level.
apply_damage
apply_damage(hit_points_damage: int)
Apply damage to the player character by reducing their hit points by the given amount, down to a minimum of 0.
This method has no affect if the character is already dead.
Parameters:
-
hit_points_damage
(int
) –The amount of damage done to the PC.
get_attack_roll
get_attack_roll() -> DiceRoll
Roll a 1d20 to hit, add all applicable modifiers, and return the roll.
Returns:
-
DiceRoll
(DiceRoll
) –The result of the to hit roll.
get_damage_roll
get_damage_roll() -> DiceRoll
Roll appropriate damage die, add all applicable modifiers, and return the roll.
Returns:
-
DiceRoll
(DiceRoll
) –The result of the damage roll.
get_initiative_roll
get_initiative_roll() -> int
Rolls a 1d6, adds the character's Dexterity modifier, and returns the total.
grant_xp
Grants XP to the character, taking into account their Constitution ability modifier, if any.
If the the character's new XP total is enough to level up, the character's level and associated statistics (including a new "XP neeeded for next level" value) are increased appropriately.
heal
heal(hit_points_healed: int)
Heal the player character by increasing their hit points by the given amount, up to their maximum hit points.
Parameters:
-
hit_points_healed
(int
) –The amount of hit points to heal the PC.
roll_hp
roll_hp() -> DiceRoll
Rolls the character's hit dice and applies their Constitution modifier, if any.
The total value of the roll with modifier can be negative after if the roll was low and the character has a negative Constitution modifier. You should clamp the value to 1 before applying it to the character's HP.
Returns:
-
DiceRoll
(DiceRoll
) –The result of the HP roll. Value with modifiers can be negative.
save_character
set_character_class
set_character_class(character_class_type: CharacterClassType, level: int = 1)
Sets the character class of the character.