evennia.contrib.tutorials.evadventure.quests

A simple quest system for EvAdventure.

A quest is represented by a quest-handler sitting as .quests on a Character. Individual Quests are child classes of EvAdventureQuest with methods for each step of the quest. The quest handler can add, remove, and track the progress by calling the progress method on the quest. Persistent changes are stored on the quester using the add_data and get_data methods with an Attribute as storage backend.

A quest ending can mean a reward or the start of another quest.

class evennia.contrib.tutorials.evadventure.quests.EvAdventureQuest(quester)[source]

Bases: object

This represents a single questing unit of quest.

Properties:

name (str): Main identifier for the quest. category (str, optional): This + name must be globally unique.

it ends - it then pauses after the last completed step.

Each step of the quest is represented by a .step_<stepname> method. This should check the status of the quest-step and update the .current_step or call .complete(). There are also .help_<stepname> which is either a class-level help string or a method returning a help text. All properties should be stored on the quester.

Example: py class MyQuest(EvAdventureQuest):

‘’’A quest with two steps that ar’’’

start_step = “A”

help_A = “You need a ‘A_flag’ attribute on yourself to finish this step!” help_B = “Finally, you need more than 4 items in your inventory!”

def step_A(self, *args, **kwargs):
if self.get_data(“A_flag”) == True:

self.quester.msg(“Completed the first step of the quest.”) self.current_step = “end” self.progress()

def step_B(self, *args, **kwargs):

def step_end(self, *args, **kwargs):
if len(self.quester.contents) > 4:

self.quester.msg(“Quest complete!”) self.complete()

key = 'base quest'
desc = 'This is the base quest class'
start_step = 'start'
help_start = 'You need to start first'
help_end = 'You need to end the quest'
__init__(quester)[source]

Initialize self. See help(type(self)) for accurate signature.

add_data(key, value)[source]

Add data to the quest. This saves it permanently.

Parameters
  • key (str) – The key to store the data under.

  • value (any) – The data to store.

get_data(key, default=None)[source]

Get data from the quest.

Parameters
  • key (str) – The key to get data for.

  • default (any, optional) – The default value to return if key is not found.

Returns

any – The data stored under the key.

remove_data(key)[source]

Remove data from the quest permanently.

Parameters

key (str) – The key to remove.

property questhandler
property current_step
property status
property is_completed
property is_abandoned
property is_failed
complete()[source]

Complete the quest.

abandon()[source]

Abandon the quest.

fail()[source]

Fail the quest.

progress(*args, **kwargs)[source]

This is called whenever the environment expects a quest may need stepping. This will determine which quest-step we are on and run step_<stepname>, which in turn will figure out if the step is complete or not.

Parameters
  • *args – Will be passed into the step method.

  • **kwargs

    Will be passed into the step method.

Notes

self.quester is available as the character following the quest.

help(*args, **kwargs)[source]

This is used to get help (or a reminder) of what needs to be done to complete the current quest-step. It will look for a help_<stepname> method or string attribute on the quest.

Parameters
  • *args – Will be passed into any help_* method.

  • **kwargs

    Will be passed into any help_* method.

Returns

str – The help text for the current step.

step_start(*args, **kwargs)[source]

Example step that completes immediately.

cleanup()[source]

This is called both when completing the quest, or when it is abandoned prematurely.

This is for cleaning up any extra state that were set during the quest (stuff in self.data is automatically cleaned up)

class evennia.contrib.tutorials.evadventure.quests.EvAdventureQuestHandler(obj)[source]

Bases: object

This sits on the Character, as .quests.

It’s initiated using a lazy property on the Character:

@lazy_property def quests(self):

return EvAdventureQuestHandler(self)

quest_storage_attribute_key = '_quests'
quest_storage_attribute_category = 'evadventure'
quest_data_attribute_template = '_quest_data_{quest_key}'
quest_data_attribute_category = 'evadventure'
__init__(obj)[source]

Initialize self. See help(type(self)) for accurate signature.

has(quest_key)[source]

Check if a given quest is registered with the Character.

Parameters
  • quest_key (str) – The name of the quest to check for.

  • quest_category (str, optional) – Quest category, if any.

Returns

bool – If the character is following this quest or not.

get(quest_key)[source]

Get the quest stored on character, if any.

Parameters

quest_key (str) – The name of the quest to check for.

Returns

EvAdventureQuest or None

The quest stored, or None if

Character is not on this quest.

all()[source]

Get all quests stored on character.

Returns

list – All quests stored on character.

add(quest_class)[source]

Add a new quest

Parameters

quest_class (EvAdventureQuest) – The quest class to start.

remove(quest_key)[source]

Remove a quest. If not complete, it will be abandoned.

Parameters

quest_key (str) – The quest to remove.

save_quest_data(quest_key)[source]

Save data for a quest. We store this on the quester as well as updating the quest itself.

Parameters

quest_key (str) – The quest to save data for. The data is assumed to be stored on the quest as .data (a dict).

load_quest_data(quest_key)[source]

Load data for a quest.

Parameters

quest_key (str) – The quest to load data for.

Returns

dict – The data stored for the quest.

class evennia.contrib.tutorials.evadventure.quests.CmdQuests(**kwargs)[source]

Bases: evennia.commands.command.Command

List all quests and their statuses as well as get info about the status of a specific quest.

Usage:

quests quest <questname>

key = 'quests'
aliases = ['quest']
help_category = 'general'
lock_storage = 'cmd:all();'
search_index_entry = {'aliases': 'quest', 'category': 'general', 'key': 'quests', 'no_prefix': ' quest', 'tags': '', 'text': '\n List all quests and their statuses as well as get info about the status of\n a specific quest.\n\n Usage:\n quests\n quest <questname>\n\n '}
parse()[source]

Once the cmdhandler has identified this as the command we want, this function is run. If many of your commands have a similar syntax (for example ‘cmd arg1 = arg2’) you should simply define this once and just let other commands of the same form inherit from this. See the docstring of this module for which object properties are available to use (notably self.args).

func()[source]

This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse())