entities package
Submodules
models.entities.character module
- class models.entities.character.Character(name: str = '', appearance: str = '', backstory: str = '', personality: str = '', languages: list[str] = <factory>, spellslots: dict[str, ~typing.Any]=<factory>, spellcasting_ability: dict[str, ~typing.Any]=<factory>, char_class: str = '', char_class_features: dict[str, ~typing.Any]=<factory>, species: str = '', species_traits: dict[str, ~typing.Any]=<factory>, subclass: str = '', feats: list[str] = <factory>, background: str = '', level: int = 1, xp: int = 0, armor_class: int = 10, death_saves: dict[str, ~typing.Any]=<factory>, hp: int = 0, stats: dict[str, ~typing.Any]=<factory>, inventory: list[str] = <factory>, training_proficiencies: dict[str, ~typing.Any]=<factory>, spells: list[dict[str, ~typing.Any]]=<factory>, proficiency_bonus: int = 2, hit_dice: dict[str, ~typing.Any]=<factory>, saving_throws: dict[str, ~typing.Any]=<factory>, skills: dict[str, ~typing.Any]=<factory>, temporary_hp: int = 0, inspiration: bool = False, passive_perception: int = 10, conditions: list[str] = <factory>, currency: dict[str, ~typing.Any]=<factory>, exhaustion_level: int = 0, armor: list[str] = <factory>, weapons: list[str] = <factory>, speed: int = 30, initiative: int = 0, resistances: list[str] = <factory>, immunities: list[str] = <factory>, vulnerabilities: list[str] = <factory>)
Bases:
GameEntityDataclass representing a player character.
Inherits base entity behavior from GameEntity and adds all D&D 5e character sheet fields.
- appearance: str = ''
- armor: list[str]
- armor_class: int = 10
- background: str = ''
- backstory: str = ''
- cast_spell(spell_name, target)
Cast a spell.
- Parameters:
spell_name (str) – Name of the spell to cast
target (Any) – Target of the spell
- char_class: str = ''
- char_class_features: dict[str, Any]
- conditions: list[str]
- currency: dict[str, Any]
- death_saves: dict[str, Any]
- exhaustion_level: int = 0
- feats: list[str]
- heal(amount)
Heal the character.
- Parameters:
amount (int) – Amount of healing to apply
- hit_dice: dict[str, Any]
- hp: int = 0
- immunities: list[str]
- initiative: int = 0
- inspiration: bool = False
- inventory: list[str]
- languages: list[str]
- level: int = 1
- name: str = ''
- passive_perception: int = 10
- personality: str = ''
- proficiency_bonus: int = 2
- resistances: list[str]
- save_to_db(db_conn)
Save the character to the database.
Uses the
characterstable schema from db_init.py: name, class, level, hp, stats, inventory, spells.- Parameters:
db_conn (sqlite3.Connection) – Database connection object
- saving_throws: dict[str, Any]
- skills: dict[str, Any]
- species: str = ''
- species_traits: dict[str, Any]
- speed: int = 30
- spellcasting_ability: dict[str, Any]
- spells: list[dict[str, Any]]
- spellslots: dict[str, Any]
- stats: dict[str, Any]
- subclass: str = ''
- take_damage(damage)
Apply damage to the character.
- Parameters:
damage (int) – Amount of damage to apply
- temporary_hp: int = 0
- training_proficiencies: dict[str, Any]
- vulnerabilities: list[str]
- weapons: list[str]
- xp: int = 0
models.entities.enemy module
- class models.entities.enemy.Enemy(name, armor_class, hp, stats, saving_throws, attacks, speed, resistances, immunities, vulnerabilities, condition_immunities, challenge_rating, xp, conditions, initiative, spells)
Bases:
GameEntityRepresents an enemy entity in the game.
- Parameters:
name (str) – Name of the enemy
armor_class (int) – Armor class value
hp (int) – Hit points
stats (dict) – Dictionary of stats (e.g., {“Strength”: 10, …})
saving_throws (dict) – Dictionary of saving throw values
attacks (list) – List of attack dictionaries
speed (int) – Movement speed
resistances (list) – List of resistances
immunities (list) – List of immunities
vulnerabilities (list) – List of vulnerabilities
condition_immunities (list) – List of condition immunities
challenge_rating (float) – Challenge rating
xp (int) – Experience points
conditions (list) – List of current conditions
initiative (int) – Initiative value
spells (list) – List of spells
- cast_spell(spell_name, target)
Cast a spell.
- Parameters:
spell_name (str) – Name of the spell to cast
target (object) – Target of the spell
- heal(amount)
Heal the enemy by a specified amount, up to its maximum hit points.
- Parameters:
amount (int) – Amount to heal
- save_to_db(db_conn)
Save the enemy to the database.
- Parameters:
db_conn (sqlite3.Connection) – Database connection object
- take_damage(damage)
Apply damage to the enemy, reducing its hit points.
- Parameters:
damage (int) – Amount of damage to apply
models.entities.entity_type module
- class models.entities.entity_type.EntityType(value)
Bases:
EnumEnumeration of possible entity types in the DnD project.
- Variables:
PLAYER – Represents a player entity.
ENEMY – Represents an enemy entity.
NPC – Represents a non-player character entity.
OBJECT – Represents an object entity.
- ENEMY = 'enemy'
- NPC = 'npc'
- OBJECT = 'object'
- PLAYER = 'player'
models.entities.game_entity module
- class models.entities.game_entity.GameEntity(name, entity_type, stats=None, inventory=None, image_path=None)
Bases:
objectRepresents a game entity with stats, inventory, and triggers.
- Parameters:
name (str) – The name of the entity.
entity_type (str) – The type/category of the entity.
stats (dict, optional) – The stats dictionary for the entity.
inventory (list, optional) – The inventory list for the entity.
- conditions: list[str]
- classmethod from_dict(data)
Create a GameEntity instance from a dictionary.
- Parameters:
data (dict) – Dictionary containing entity data.
- Returns:
A GameEntity instance.
- Return type:
- handle_event(event_type, data)
Handle a tile-based event by running any triggers matching event_type.
- Parameters:
event_type (str) – The type of event to handle.
data (Any) – Data associated with the event.
- heal(amount: int) int
Heal this entity. Returns actual healing done.
- hp: int
- property hp_percent: float
Current HP as a percentage.
- property is_alive: bool
Check if entity is alive (HP > 0).
- max_hp: int
- personality: EntityPersonality | None
- position: tuple[int, int] | None
- register_trigger(trigger)
Register a trigger for this entity if not already registered.
- Parameters:
trigger (Trigger) – The trigger to register.
- set_personality(personality: EntityPersonality) None
Set the AI personality for this entity.
- take_damage(amount: int, damage_type: str = 'untyped') int
Apply damage to this entity. Returns actual damage dealt.
- to_dict()
Serialize the entity to a dictionary.
- Returns:
Dictionary representation of the entity.
- Return type:
dict
models.entities.named_enemy module
- class models.entities.named_enemy.NamedEnemy(name, armor_class, hp, stats, saving_throws, attacks, speed, resistances, immunities, vulnerabilities, condition_immunities, challenge_rating, xp, conditions, initiative, spells, backstory, legendary_actions, lair_actions, regional_effects, spellcasting_ability, phases)
Bases:
EnemyRepresents a named enemy with additional lore, actions, and spellcasting abilities.
Inherits from
Enemyand adds properties such as backstory, legendary actions, lair actions, regional effects, spellcasting ability, and combat phases.- cast_spell(spell_name, target)
Cast a spell by name on a target.
- Parameters:
spell_name (str) – Name of the spell to cast.
target (object) – Target of the spell.
- heal(amount)
Heal the enemy, increasing its hit points up to max_hp.
- Parameters:
amount (int) – Amount of hit points to restore.
- save_to_db(db_conn)
Save the enemy’s data to the database.
- Parameters:
db_conn (sqlite3.Connection) – Database connection object.
- take_damage(damage)
Apply damage to the enemy, reducing its hit points.
- Parameters:
damage (int) – Amount of damage to apply.
models.entities.npc module
- class models.entities.npc.NPC(name, behavior)
Bases:
GameEntityRepresents a Non-Player Character (NPC) in the game.
Inherits from
GameEntity.- take_turn()
Defines the NPC’s behavior during their turn.
The action taken depends on the NPC’s behavior attribute: - “friendly”: May move around or interact with the player. - “neutral”: May idle or react passively. - “hostile”: May flee or attack.
models.entities.player
- class models.entities.player.Player(character, db_conn, player_id)
Bases:
GameEntityRepresents a player in the game.
Inherits from
GameEntityand manages player-specific data and actions.- attack(target)
Perform a simple STR-based attack against a target and log the result in the combat log.
- Parameters:
target (object) – The entity being attacked. Must have armor_class and take_damage() attributes.
- Returns:
Tuple indicating if the attack hit and the damage dealt (hit: bool, damage: int).
- Return type:
tuple
- cast_spell(spell_name, target)
Cast a spell using the associated Character’s cast_spell method.
- Parameters:
spell_name (str) – Name of the spell to cast.
target (object) – The target of the spell.
- Returns:
Result of the Character’s cast_spell method.
- interact(obj)
Interact with an object if it has an interact(player) method.
- Parameters:
obj (object) – The object to interact with.
- Returns:
The result of the object’s interact method, or None if not available.
- investigate(location)
Perform a Wisdom-based investigation check (d20 + WIS modifier).
- Parameters:
location (object) – The location or object being investigated.
- Returns:
The total roll (d20 + WIS modifier).
- Return type:
int
- move(direction: str)
Move the player north, south, east, or west by one tile and persist the new position to the database.
- Parameters:
direction (str) – Direction to move (‘north’, ‘south’, ‘east’, ‘west’).
- Returns:
The new position as a tuple (x, y).
- Return type:
tuple
- take_turn()
Stub for the per-turn loop.
You’ll want to hook this into your UI or CLI.
- Raises:
NotImplementedError – Always, as this should be implemented by the game loop or UI.
models.entities.trap module
- class models.entities.trap.Trap(name, damage, trigger_range)
Bases:
GameEntityRepresents a trap entity in the game.
Inherits from
GameEntity.- take_turn()
Traps don’t take actions, but they may be triggered during movement.