Quest engine

From Post-Apocalyptic RPG wiki

Jump to: navigation, search

Submitted code proposal.png This article features an submitted code proposal.

Submitted code proposals are currently under consideration for implementation.


There should be one class (Quest engine) that holds all the information regarding quests and should handle all the functions. The quests can be made and saved using yaml (or xml) files. These files contain all the information needed for a quest.

Quest files (files in which you define a quest) are either or yaml or xml, I personally prefer yaml but this is a point for discusion A sample of what a yaml file could look like:

       value: 0
       goal_value: 10
       value: false
       goal_value: true

   quest_id: 768
   quest_giver_id: 12
   quest_name: "10 apples and a dead body!"
   description: "Arr, I've lost 10 apples and a body! Retrieve them for me!"

A Quest engine object can easily be made by calling

quest = Quest engine()

Further actions should be applied on the Quest engine object you just made called quest. As you can see in the example yaml file, an important thing in the Quest engine is that you can create variables for a quest and you should be able to set them and check them. The Quest engine will have two lists (dicts), one for the active quests and one for finished quests. The list of active quests will contain so called QuestObject's and the finished quests list will either contain QuestObject's or only the quest_ids of the finished quests, not sure about this yet. Is knowing that a quest is finished enough or do we also want to know what variables a quest is finished with? The quest engine will handle those lists so there's no need for editing them manually (which would be ugly).

The Quest engine has a number of functions:

  • finishQuest(<quest_id>): Mark the quest with <quest_id> as finished
  • hasFinishedQuest(<quest_id>): Returns true if a quest is already finished
  • hasQuest(<quest_id>): Returns true if the PC has the quest with the quest_id, either finished or still going
  • addQuest(<file_name>): Read a yaml (or xml) file and convert it to a QuestObject and add it to the active quests lists (if it isn't on it already and if it isn't finished)
  • deleteQuest(quest_id)

You should be able threat the created object as a dict, so that individual quests can easily be accessed from within a dialog file. For example:


Returns an object that contains all the information of the quest with the quest_id 768 and you can also interact with this object. And

print quest

should print all the quests in the dict (this should only be the active quests) so it would for example print

{768: <object QuestObject>, 12: <object QuestObject>}

This will only contain the quests that are not yet finished. These QuestObject's will also contain a number of features:

  • setValue(<variable name>, <value>): will set the value of quest variable (in the yaml file example this would be apples_gathered or dead_bodys_found.
  • getValue(<variable name>)
  • getGoalValue(<variable name>)
  • increaseValue(<variable name>, <value>): Increase the variable by <value>
  • decreaseValue(<variable name>, <value>)
  • isGoalValue(<variable name>): Return true when the variable has reached it's goal level
  • isEquelOrBiggerThanGoalValue(<variable name>): For quests that a minimum amount of objects or more
  • CheckValue(<variable name>, <value>): Check if the variable <variable name> == <value>

So if you want to increase the value of the apples_gathered by one you would call:


Items like quest_id or description can be accessed by Quest[768].description

Some sample code:

#Create the quest engine
quest = Quest engine()

#Add a quest to the quest log (the yaml file is defined on the top of this page)

#Increase the apples_gathered variable by one

#Set the dead_body_found variable to true

#Check if you've found the body
print "Check if the dead body is found:", quest[768].isGoalValue("dead_body_found")
Check if the dead body is found: True

Working example (put the 3 files in one directory to test): ( ( (apples_body.yaml)

Personal tools