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
–Manages the
Dungeon
andQuest
collections in a game scenario and the progress of the player'sParty
through the scenario. -
DungeonNotFoundError
–Raised for missing dungeons.
-
DungeonAlreadyExistsError
–Raised for duplicate dungeon additions.
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:
-
DungeonAlreadyExistsError
–If the dungeon already exists in the adventure.
load_adventure
staticmethod
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:
-
FileNotFoundError
–If the specified file does not exist.
-
PermissionError
–If there are issues with file access permissions.
-
JSONDecodeError
–If the file content is not valid JSON.
-
Exception
–For any other issues that may occur.
save_adventure
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:
-
DungeonNotFoundError
–If the dungeon isn't in the adventure.
set_active_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 the adventure.
Call this method only after you've added a party to the adventure and set the active dungeon.
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.