maid-stdlib¶
The maid-stdlib package provides the standard library of reusable components, systems, events, commands, and utilities for MAID games.
Installation¶
Module Overview¶
Components (maid_stdlib.components)¶
Reusable ECS components for common game mechanics:
- HealthComponent - Hit points and health management
- ManaComponent - Magic points for spellcasting
- StaminaComponent - Stamina for physical actions
- InventoryComponent - Item storage and capacity
- PositionComponent - Location tracking
- StatsComponent - Character attributes (STR, DEX, etc.)
- CombatComponent - Combat state and cooldowns
- EquipmentComponent - Equipped items
- ItemComponent - Item properties
- NPCComponent - NPC behavior and state
- PlayerComponent - Player-specific data
- DescriptionComponent - Entity descriptions
- MovementComponent - Movement tracking
Systems (maid_stdlib.systems)¶
Base systems implementing common game mechanics:
- HealthRegenerationSystem - Regenerate health over time
- ManaRegenerationSystem - Regenerate mana over time
- StaminaRegenerationSystem - Regenerate stamina over time
- MovementRegenerationSystem - Regenerate movement points
- PositionSyncSystem - Sync entity positions
- HealthCheckSystem - Check for entity death
Events (maid_stdlib.events)¶
Standard events for common game actions:
RoomEnterEvent- Entity enters a roomRoomLeaveEvent- Entity leaves a roomCombatStartEvent- Combat beginsCombatEndEvent- Combat endsDamageDealtEvent- Damage dealt to entityEntityDeathEvent- Entity diesItemPickedUpEvent- Item picked upItemDroppedEvent- Item droppedMessageEvent- Message to display
Commands (maid_stdlib.commands)¶
Standard commands available to all games:
| Command | Description |
|---|---|
look |
Look at room or object |
move / directions |
Move between rooms |
get / take |
Pick up items |
drop |
Drop items |
inventory / i |
View inventory |
help |
Get command help |
language |
Set language preference |
Utilities (maid_stdlib.utils)¶
Helper functions and utilities:
- dice - Dice rolling functions
- formatting - Text formatting and colors
- editor - In-game text editor
- menu - Interactive menu system
- table - ASCII table formatting
Components¶
HealthComponent¶
Component for tracking entity health.
ManaComponent¶
Component for tracking magical energy.
ManaComponent
¶
StaminaComponent¶
Component for tracking physical energy.
StaminaComponent
¶
InventoryComponent¶
Component for item storage.
InventoryComponent
¶
Bases: Component
Tracks entity inventory.
can_add_item
¶
Check if an item can be added (slot and weight check).
add_item
¶
Add an item to inventory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
UUID
|
ID of item to add |
required |
weight
|
float
|
Weight of the item (default 0.0) |
0.0
|
Returns:
| Type | Description |
|---|---|
bool
|
False if inventory full or weight limit exceeded |
remove_item
¶
Remove an item from inventory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
UUID
|
ID of item to remove |
required |
weight
|
float
|
Weight of the item (default 0.0) |
0.0
|
Returns:
| Type | Description |
|---|---|
bool
|
False if item not found |
PositionComponent¶
Component for location tracking.
StatsComponent¶
Component for character attributes.
StatsComponent
¶
Bases: Component
Core RPG statistics for characters.
These are the base attributes that influence all other derived stats. Content packs may use these to calculate combat, skill, and other values.
get_modifier
¶
Get the modifier for a stat (D&D-style: (stat - 10) // 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stat
|
str
|
Stat name (strength, dexterity, etc.) |
required |
Returns:
| Type | Description |
|---|---|
int
|
Modifier value (-5 to +10 typically) |
add_experience
¶
Add experience and return number of levels gained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
int
|
Experience to add |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of levels gained (0 if none) |
Systems¶
HealthRegenerationSystem¶
System that regenerates entity health over time.
HealthRegenerationSystem
¶
HealthRegenerationSystem(world: World)
Bases: System
Regenerates health for entities not in combat.
Uses HealthComponent.regeneration_rate to determine regen speed. Skips entities that are in combat (have CombatComponent with in_combat=True).
ManaRegenerationSystem¶
System that regenerates entity mana over time.
ManaRegenerationSystem
¶
ManaRegenerationSystem(world: World)
Bases: System
Regenerates mana for entities.
Uses ManaComponent.regeneration_rate to determine regen speed. Regenerates even in combat (but content packs can override).
StaminaRegenerationSystem¶
System that regenerates entity stamina over time.
StaminaRegenerationSystem
¶
StaminaRegenerationSystem(world: World)
Bases: System
Regenerates stamina for entities.
Uses different rates for in-combat vs out-of-combat: - StaminaComponent.regeneration_rate: out of combat - StaminaComponent.combat_regen_rate: in combat
Utilities¶
Dice Utilities¶
Functions for rolling dice with standard notation.
from maid_stdlib.utils import roll_dice, roll, parse_dice_notation
# Roll 2d6+3
result = roll_dice("2d6+3")
print(f"Rolled {result.total} (rolls: {result.rolls})")
# Quick roll
total = roll(2, 6, 3) # 2d6+3
# Parse notation
parsed = parse_dice_notation("3d8-2")
print(f"Dice: {parsed.num_dice}d{parsed.sides}{parsed.modifier:+d}")
roll_dice
¶
roll_dice(
num_dice: int = 1, sides: int = 6, modifier: int = 0
) -> DiceResult
Roll dice and return detailed results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_dice
|
int
|
Number of dice to roll |
1
|
sides
|
int
|
Number of sides on each die |
6
|
modifier
|
int
|
Bonus/penalty to add to total |
0
|
Returns:
| Type | Description |
|---|---|
DiceResult
|
DiceResult with total, individual rolls, and notation |
roll
¶
Roll dice and return the total.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_dice
|
int
|
Number of dice to roll |
1
|
sides
|
int
|
Number of sides on each die |
6
|
modifier
|
int
|
Bonus/penalty to add to total |
0
|
Returns:
| Type | Description |
|---|---|
int
|
Total of all dice plus modifier |
Text Formatting¶
Functions for formatting text with colors and styles.
from maid_stdlib.utils import colorize, strip_colors, wrap_text, center_text
# Apply colors
text = colorize("Hello, World!", "bright_green")
# Parse color tags
text = parse_color_tags("{red}Warning:{/red} {yellow}Caution!{/yellow}")
# Wrap long text
wrapped = wrap_text(long_text, width=80)
# Center text
centered = center_text("Title", width=40, fill_char="=")
colorize
¶
Apply ANSI color to text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to colorize |
required |
color
|
str
|
Color name (see COLORS dict) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Text with ANSI color codes |
strip_colors
¶
Remove all ANSI color codes from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text with ANSI codes |
required |
Returns:
| Type | Description |
|---|---|
str
|
Plain text without color codes |
Table Formatting¶
Create ASCII tables for displaying data.
from maid_stdlib.utils import format_table
# Simple table
headers = ["Name", "Level", "Class"]
rows = [
["Gandalf", "20", "Wizard"],
["Aragorn", "15", "Ranger"],
]
table = format_table(headers, rows)
print(table)
format_table
¶
format_table(
rows: list[list[str]],
headers: list[str] | None = None,
column_sep: str = " | ",
) -> str
Format data as a simple text table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[list[str]]
|
List of rows, each row is a list of cell values |
required |
headers
|
list[str] | None
|
Optional header row |
None
|
column_sep
|
str
|
Separator between columns |
' | '
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted table as string |
Content Pack¶
The stdlib provides a content pack that registers all components, systems, and commands:
from maid_engine import GameEngine
from maid_stdlib import StdlibContentPack
engine = GameEngine(settings)
engine.load_content_pack(StdlibContentPack())
StdlibContentPack
¶
Standard library content pack.
Provides common components, base systems, events, and commands that most MUD games will need.
register_commands
¶
Register commands provided by this pack.
register_document_schemas
¶
register_document_schemas(store: DocumentStore) -> None
Register document schemas used by this pack.
Package API¶
Full package API documentation:
maid_stdlib
¶
MAID Standard Library - Common components, systems, and utilities.
This package provides reusable building blocks for MUD games:
- Common components (Health, Inventory, Position, Stats)
- Base abstract systems (combat, inventory, movement)
- Standard events (movement, combat, item interactions)
- Basic commands (look, move, get, drop, inventory)
- Utility functions (dice rolling, text formatting)
CombatEndEvent
dataclass
¶
CombatStartEvent
dataclass
¶
DamageDealtEvent
dataclass
¶
DescriptionComponent
¶
Bases: Component
Entity description and display information.
The name, short_desc, and long_desc fields support TranslatableText for internationalization. You can set per-locale translations using the @set command with locale suffixes:
@set entity/DescriptionComponent.name.es = "Spanish name"
@set entity/DescriptionComponent.short_desc.de = "German description"
When fields are plain strings, they work normally. When a locale-specific translation is set via @set, the field is automatically converted to TranslatableText to store the translations.
matches_keyword
¶
Check if entity matches a keyword search.
Source code in packages/maid-stdlib/src/maid_stdlib/components/core.py
DiceResult
dataclass
¶
Result of a dice roll.
EntityDeathEvent
dataclass
¶
EquipmentComponent
¶
HealthCheckSystem
¶
HealthCheckSystem(world: World)
Bases: System
Monitors health and emits EntityDeathEvent when health reaches 0.
This system runs after damage-dealing systems to detect deaths. It tracks which entities have already had death events emitted to avoid duplicate events.
The "dead" tag is added to entities when they die and should be removed when they are resurrected/respawned.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/health.py
shutdown
async
¶
update
async
¶
Check for dead entities and emit death events.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/health.py
HealthComponent
¶
HealthRegenerationSystem
¶
HealthRegenerationSystem(world: World)
Bases: System
Regenerates health for entities not in combat.
Uses HealthComponent.regeneration_rate to determine regen speed. Skips entities that are in combat (have CombatComponent with in_combat=True).
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
shutdown
async
¶
update
async
¶
Regenerate health for all eligible entities.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
InventoryComponent
¶
Bases: Component
Tracks entity inventory.
add_item
¶
Add an item to inventory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
UUID
|
ID of item to add |
required |
weight
|
float
|
Weight of the item (default 0.0) |
0.0
|
Returns:
| Type | Description |
|---|---|
bool
|
False if inventory full or weight limit exceeded |
Source code in packages/maid-stdlib/src/maid_stdlib/components/core.py
can_add_item
¶
Check if an item can be added (slot and weight check).
Source code in packages/maid-stdlib/src/maid_stdlib/components/core.py
remove_item
¶
Remove an item from inventory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
UUID
|
ID of item to remove |
required |
weight
|
float
|
Weight of the item (default 0.0) |
0.0
|
Returns:
| Type | Description |
|---|---|
bool
|
False if item not found |
Source code in packages/maid-stdlib/src/maid_stdlib/components/core.py
ItemComponent
¶
Bases: Component
Marks an entity as an item.
This component identifies item entities and holds item-specific metadata like template, quality, and ownership.
ItemDroppedEvent
dataclass
¶
ItemPickedUpEvent
dataclass
¶
ManaComponent
¶
ManaRegenerationSystem
¶
ManaRegenerationSystem(world: World)
Bases: System
Regenerates mana for entities.
Uses ManaComponent.regeneration_rate to determine regen speed. Regenerates even in combat (but content packs can override).
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
shutdown
async
¶
update
async
¶
Regenerate mana for all eligible entities.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
MessageEvent
dataclass
¶
MovementRegenerationSystem
¶
MovementRegenerationSystem(world: World)
Bases: System
Regenerates movement points for entities.
Uses MovementComponent.regeneration_rate to determine regen speed.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
shutdown
async
¶
update
async
¶
Regenerate movement for all eligible entities.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
NPCComponent
¶
Bases: Component
Marks an entity as a non-player character.
This component identifies NPC entities and holds NPC-specific metadata like AI behavior, dialogue, and spawn information.
PlayerComponent
¶
Bases: Component
Marks an entity as a player character.
This component identifies player-controlled entities and holds player-specific metadata like account linkage and session info.
PositionSyncSystem
¶
PositionSyncSystem(world: World)
Bases: System
Synchronizes PositionComponent with World room index.
This system runs early (low priority number) to ensure the room index is up-to-date before other systems query room occupants.
It handles: - Initial placement of entities in rooms - Detecting position changes and updating the room index - Tracking last known position to detect changes
Source code in packages/maid-stdlib/src/maid_stdlib/systems/position.py
shutdown
async
¶
update
async
¶
Sync position components with world room index.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/position.py
RoomEnterEvent
dataclass
¶
RoomLeaveEvent
dataclass
¶
StaminaComponent
¶
StaminaRegenerationSystem
¶
StaminaRegenerationSystem(world: World)
Bases: System
Regenerates stamina for entities.
Uses different rates for in-combat vs out-of-combat: - StaminaComponent.regeneration_rate: out of combat - StaminaComponent.combat_regen_rate: in combat
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
shutdown
async
¶
update
async
¶
Regenerate stamina for all eligible entities.
Source code in packages/maid-stdlib/src/maid_stdlib/systems/regeneration.py
StatsComponent
¶
Bases: Component
Core RPG statistics for characters.
These are the base attributes that influence all other derived stats. Content packs may use these to calculate combat, skill, and other values.
add_experience
¶
Add experience and return number of levels gained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
int
|
Experience to add |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of levels gained (0 if none) |
Source code in packages/maid-stdlib/src/maid_stdlib/components/core.py
get_modifier
¶
Get the modifier for a stat (D&D-style: (stat - 10) // 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stat
|
str
|
Stat name (strength, dexterity, etc.) |
required |
Returns:
| Type | Description |
|---|---|
int
|
Modifier value (-5 to +10 typically) |
Source code in packages/maid-stdlib/src/maid_stdlib/components/core.py
StdlibContentPack
¶
Standard library content pack.
Provides common components, base systems, events, and commands that most MUD games will need.
get_dependencies
¶
get_systems
¶
on_load
async
¶
on_load(engine: GameEngine) -> None
on_unload
async
¶
on_unload(engine: GameEngine) -> None
register_commands
¶
Register commands provided by this pack.
Source code in packages/maid-stdlib/src/maid_stdlib/pack.py
register_document_schemas
¶
register_document_schemas(store: DocumentStore) -> None
center_text
¶
Center text within a given width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to center |
required |
width
|
int
|
Total width |
80
|
fill_char
|
str
|
Character to use for padding |
' '
|
Returns:
| Type | Description |
|---|---|
str
|
Centered text |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/text.py
colorize
¶
Apply ANSI color to text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to colorize |
required |
color
|
str
|
Color name (see COLORS dict) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Text with ANSI color codes |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/text.py
format_table
¶
format_table(
rows: list[list[str]],
headers: list[str] | None = None,
column_sep: str = " | ",
) -> str
Format data as a simple text table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[list[str]]
|
List of rows, each row is a list of cell values |
required |
headers
|
list[str] | None
|
Optional header row |
None
|
column_sep
|
str
|
Separator between columns |
' | '
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted table as string |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/text.py
get_stdlib_systems
¶
Get all systems provided by stdlib.
Returns systems in priority order for registration. Content packs can disable or extend these systems as needed.
System priorities: - PositionSyncSystem (5): Sync positions with room index - HealthRegenerationSystem (10): Regen health out of combat - ManaRegenerationSystem (15): Regen mana - StaminaRegenerationSystem (20): Regen stamina (combat-aware) - MovementRegenerationSystem (25): Regen movement points - HealthCheckSystem (60): Emit death events when health reaches 0
Source code in packages/maid-stdlib/src/maid_stdlib/systems/__init__.py
parse_color_tags
¶
Convert MXP-style color tags to ANSI codes.
Converts tags like
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text with color tags |
required |
Returns:
| Type | Description |
|---|---|
str
|
Text with ANSI color codes |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/text.py
parse_dice_notation
¶
parse_dice_notation(notation: str) -> DiceResult
Parse dice notation (e.g., "2d6+3") and roll.
Supported formats: - "d6" or "1d6" - single die - "2d6" - multiple dice - "2d6+3" - with positive modifier - "2d6-2" - with negative modifier
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notation
|
str
|
Dice notation string |
required |
Returns:
| Type | Description |
|---|---|
DiceResult
|
DiceResult from rolling the specified dice |
Raises:
| Type | Description |
|---|---|
ValueError
|
If notation is invalid |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/dice.py
roll
¶
Roll dice and return the total.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_dice
|
int
|
Number of dice to roll |
1
|
sides
|
int
|
Number of sides on each die |
6
|
modifier
|
int
|
Bonus/penalty to add to total |
0
|
Returns:
| Type | Description |
|---|---|
int
|
Total of all dice plus modifier |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/dice.py
roll_dice
¶
roll_dice(
num_dice: int = 1, sides: int = 6, modifier: int = 0
) -> DiceResult
Roll dice and return detailed results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_dice
|
int
|
Number of dice to roll |
1
|
sides
|
int
|
Number of sides on each die |
6
|
modifier
|
int
|
Bonus/penalty to add to total |
0
|
Returns:
| Type | Description |
|---|---|
DiceResult
|
DiceResult with total, individual rolls, and notation |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/dice.py
strip_colors
¶
Remove all ANSI color codes from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text with ANSI codes |
required |
Returns:
| Type | Description |
|---|---|
str
|
Plain text without color codes |
Source code in packages/maid-stdlib/src/maid_stdlib/utils/text.py
wrap_text
¶
Wrap text to specified width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to wrap |
required |
width
|
int
|
Maximum line width |
80
|
indent
|
str
|
Indent for first line |
''
|
subsequent_indent
|
str
|
Indent for subsequent lines |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Wrapped text |