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:
BaseModelA 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"
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- is_defeated()[source]¶
Check if entire party is defeated.
- Return type:
- 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.
- size()[source]¶
Get the number of members in the party.
- Return type:
- Returns:
Number of party members