Party System

The party module provides party management for handling multiple player characters.

Party Classes

Party system for managing groups of entities.

This module provides a persistent party system that works with combat and can be extended for custom features like shared resources.

class barebones_rpg.party.party.Party(**data)[source]

Bases: BaseModel

A persistent party of entities.

Parties are collections of entities that persist outside of combat. They provide a simple interface for managing group membership and can be extended for custom features like shared resources or party-wide buffs.

Example

>>> from barebones_rpg.entities import Character
>>> from barebones_rpg.party import Party
>>>
>>> hero = Character(name="Hero", stats=Stats(hp=100, atk=15))
>>> mage = Character(name="Mage", stats=Stats(hp=80, atk=10))
>>>
>>> party = Party(name="Adventurers")
>>> party.add_member(hero)
>>> party.add_member(mage)
>>> print(party.size())
2
>>> print(party.get_leader().name)
Hero
Extensibility:

The Party class can be extended for custom behavior:

>>> class PartyWithGold(Party):
...     shared_gold: int = 0
...
...     def add_gold(self, amount: int):
...         self.shared_gold += amount

Or use the metadata dict for runtime customization:

>>> party.metadata["gold"] = 100
>>> party.metadata["formation"] = "defensive"
name: str
members: List[Any]
metadata: Dict[str, Any]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

add_member(member)[source]

Add a member to the party.

Parameters:

member (Any) – Entity to add to the party

Return type:

bool

Returns:

True if member was added successfully, False if already in party

remove_member(member)[source]

Remove a member from the party.

Parameters:

member (Any) – Entity to remove from the party

Return type:

bool

Returns:

True if member was found and removed, False if not in party

get_alive_members()[source]

Get all living members.

Return type:

List[Any]

Returns:

List of alive members

is_defeated()[source]

Check if entire party is defeated.

Return type:

bool

Returns:

True if all members are dead, False otherwise

get_leader()[source]

Get the party leader.

By default, the leader is the first member in the party. This can be overridden in subclasses for custom leader logic.

Return type:

Optional[Any]

Returns:

The party leader or None if party is empty

size()[source]

Get the number of members in the party.

Return type:

int

Returns:

Number of party members

has_member(member)[source]

Check if an entity is in the party.

Parameters:

member (Any) – Entity to check

Return type:

bool

Returns:

True if member is in the party

clear()[source]

Remove all members from the party.

Return type:

None

to_dict()[source]

Convert party to dictionary for saving.

Note: This only serializes basic party structure. Entity serialization must be handled separately.

Return type:

Dict[str, Any]

Returns:

Dictionary representation of party

classmethod from_dict(data, entity_lookup)[source]

Create party from dictionary.

Parameters:
  • data (Dict[str, Any]) – Dictionary representation

  • entity_lookup (Dict[str, Any]) – Dictionary mapping entity IDs to entity objects

Return type:

Party

Returns:

Party instance