Quests¶
-
class
pyzork.base.
QuestManager
(**kwargs)[source]¶ -
add
(**kwargs)[source]¶ Decorator method for adding quests to the QuestManager instance. This adds the quest to the list of possible quests but does not start it. This leaves the quest sublcass itself untouched but adds it to the list.
Parameters: - id (str) – The unique identifier for the quest, used whenever you want to manipulate a specific quest
- name (Optional[str]) – The user name of the quest, the library will fall back to the class doc and then the class name if none are provided
- description (Optional[str]) – The user friendly description of the quest. If none are provided the library will fallback to the doc of the reward function of that quest
- repeatable (Optional[int]) – How many times the quest can be done, defaults to 1
-
clear
()[source]¶ Remove all registered, active and finished quests. Also removes all pending rewards
-
finish_quest
(quest_id: str)[source]¶ Forcefully complete a quest,sending the reward to be processed, incrementing the amount of times a quest has been completed and removing it from the list of active quests
Parameters: quest_id (str) – The quest to finish
-
get_finished
(quest_id: str) → int[source]¶ Returns the number of time a quest was finished.
Parameters: quest_id (str) – The unique identifier for the quest Returns: The number of time the quest was completed. Return type: int
-
get_finished
(quest_id: str) → int[source] Returns the number of time a quest was finished.
Parameters: quest_id (str) – The unique identifier for the quest Returns: The number of time the quest was completed. Return type: int
-
pause_quest
(quest_id)[source]¶ Pause a quest, the quest’s current progress remains stored and a new instance of the quest cannot be started but the player’s actions will no longer contribute to the quest’s progression.
Parameters: quest_id (str) – The unique identifier for the quest you wish to pause
-
process_rewards
(player: Player, world: World)[source]¶ This processes all the current rewards that have not yet been claimed. This is called by default in the world loop, you can call this manually to force requests to be processed if the player is out of the world loop for a particularly long time.
Parameters:
-
progress_quests
(event, *args, **kwargs)[source]¶ This is the heart of the quest system, this is the method that needs to be called in order to propogate events to all the quests that can handle it. If are only relying on built-in events in their default states you do not need to call this funtion, you’ll only needto call this functin if you create your own events.
Parameters: - event (str) – The event that has happened, this is merely the name of the function but should follow the on_XXX name convention such as on_death, on_pickup, etc…
- *args (List) – List of args that will be passed to the quests that have this event
- **kwargs (Dict) – Dictionnary of kwargs that will be passed to the quests that have this event
-
-
class
pyzork.base.
Quest
(**kwargs)[source]¶ Quests are missions within the world you create for the player, they are there to guide the player, give a directive. They can also be used to allow the player to gain additional power through side missions, which don’t necessarily affect the main story.
Quests come by default with a certain numbers of event that are triggered by the library when certain things happen. However, these events are by no means hardcoded, you can freely create your own events which can be propageted using pyzork.qm.progress_quests and will then be applied to any quests which has that event.
-
name
¶ The name of the quest, if none is given during init then the library falls back first to the docstring of the class and then to the class name.
Type: str
-
description
¶ The description of the quest, if none is given the library falls back to the docstring of the reward method
Type: str
-
id
¶ The unique identifier for the quests which are used for things like qm.start_quest and qm.stop_quest
Type: str
-
on_death
(entity: Entity)[source]¶ This even is triggered everytime an entity’s health reaches 0. The event makes the instance of that entity available to you.
Parameters: entity (Entity) – The entity that has died Returns: Whether or not the quest is done, if True the quest is considered completed, if it is False or None the quest is considered still in progress. Return type: bool
-
on_discover
(location: Location)[source]¶ Happens everytime a location is discovered for the first time. This makes the location itself available to you.
Parameters: location (Location) – The location that was discovered Returns: Whether or not the quest is done, if True the quest is considered completed, if it is False or None the quest is considered still in progress. Return type: bool
-
on_interact
(entity: Entity, world: World)[source]¶ Happens everytime an Entity is talked to.
Parameters: - entity (Entity) – The entity that is being interacted with.
- world (World) – The world instance where the interaction is happening.
Returns: Whether or not the quest is done, if True the quest is considered completed, if it is False or None the quest is considered still in progress.
Return type:
-
on_level
(levels: ExperienceLevels)[source]¶ Happens everytime an entity levels up
Parameters: levels (ExperienceLevels) – The instance which just leveled up. Returns: Whether or not the quest is done, if True the quest is considered completed, if it is False or None the quest is considered still in progress. Return type: bool
-
on_pickup
(item: Item)[source]¶ Happens everytime an item is picked up.
Returns: Whether or not the quest is done, if True the quest is considered completed, if it is False or None the quest is considered still in progress. Return type: bool
-
reward
(player: Player)[source]¶ Function that grants the player a certain reward, this make the player instance available to you. Quest rewards are only processed in the world loop by default, if you want or need to forcibly check if any new rewards have been made available you can use pyzork.qm.process_rewards
Parameters: player (Player) – The player instance of the adventure
-
Example¶
Creating quests and managing quests use two different classes and can be created with a great amount of granularity.
Quests¶
Quests are composed of two parts the first part is one or more event based functions which serve the purpose of progressing the quest and a reward which is the entire goal for completing the quest in the first place. For example, a simple quest which only requires you kill a goblin:
from pyzork import QM, Quest, post_output
from my_adventure import Goblin
QM.add(id="KillGob", name="Kill a Goblin")
class KillGolbin(Quest):
def on_death(self, entity):
if isinstance(entity, Goblin):
return True
def reward(self, player):
post_ouptut("You did it! Well done you killed a goblin!")
Managing Quest¶
Quests have to be started manually using the QuestManager made available to you by the library, this ensures that you maintain complete control over the quests and their uses. The quest manager is instantiated for you, you only have to import the QuestManager instance which has the name QM. When handling quests you’ll be using strictly their id. To start a quest you only need to:
from pyzork import QM
QM.start_quest("KillGob")
You can also pause, stop, unpause quests using the many methods documented for QuestManager. If you create any custom events within quests you will have to propogate them yourself using progress_quests.