Skip to content

adventure

adventure

The adventure module provides the Adventure class, which represents a scenario to be played through by the adventuring Party.

The Adventure class is intended to encapsulate a set of thematically related dungeons and quests the player's Party can explore and complete. It's the thing a game game designer would typically present as a cohesive story or portion of a story for the player to experience.

Classes:

Adventure

Adventure(name: str, description: str = '', introduction: str = '', dungeons: list = [], quests: list = [])

An Adventure has a collection of dungeons that can be played through and quests that can be completed by a party of characters.

To start an adventure, add a Party to the adventure with set_active_party and then call start_adventure. Once you've started an adventure, you can't add or remove the party or its characters until you call end_adventure or all the characters in the party have been killed.

Only one party can play through (be added to) an adventure at a time.

Attributes:

  • name (str) –

    The name of the adventure.

  • short_description (str) –

    A short description of the adventure.

  • introduction (str) –

    A longer introduction in the form typically found in the beginning of a module.

  • dungeons (list) –

    A list of the dungeons in the adventure.

  • quests (list) –

    A list of the quests in the adventure.

  • party (Party) –

    The party playing through the adventure.

add_dungeon

add_dungeon(dungeon: Dungeon)

Add a dungeon to the adventure.

Parameters:

  • dungeon (Dungeon) –

    The dungeon to add to the adventure.

Raises:

end_adventure

end_adventure()

End the adventure.

Call this method when the adventure is over.

load_adventure staticmethod

load_adventure(file_path: str = None) -> Adventure

Loads the adventure from a JSON file.

Parameters:

  • file_path (str, default: None ) –

    The path of the file to load the adventure from.

Returns:

  • Adventure ( Adventure ) –

    An instance of the Adventure class loaded from the file.

Raises:

save_adventure

save_adventure(file_path: str = None) -> str

Saves the adventure to a JSON file.

Parameters:

  • file_path (str, default: None ) –

    The path where the file will be saved. If None, saves in the default data directory.

Returns:

  • str ( str ) –

    The path where the file was saved.

Raises:

  • OSError

    If the file cannot be written.

set_active_dungeon

set_active_dungeon(dungeon: Dungeon)

Set the active dungeon for the adventure.

The active dungeon is the dungeon that the party is currently exploring.

Parameters:

  • dungeon (Dungeon) –

    The dungeon to set as active.

Raises:

set_active_party

set_active_party(party)

Set the party of player characters that will play through the adventure.

Parameters:

  • party (Party) –

    The adventuring party for the adventure.

start_adventure

start_adventure()

Start the adventure.

Call this method only after you've added a party to the adventure and set the active dungeon.

to_dict

to_dict() -> dict

Convert the adventure to a dict.

Returns:

  • dict ( dict ) –

    A dict representation of the adventure.

DungeonAlreadyExistsError

Bases: Exception

Exception raised when a given dungeon already exists in the adventure's list of dungeons.

DungeonNotFoundError

Bases: Exception

Exception raised when a given dungeon isn't in the adventure's list of dungeons.