Quest engine

Design
There should be one class (QuestEngine) 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:

DEFINES: apples_gathered: value: 0 goal_value: 10 dead_bodys_found: value: false goal_value: true QUEST_PROPERTIES: 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 QuestEngine object can easily be made by calling quest = QuestEngine

Further actions should be applied on the QuestEngine object you just made called quest. As you can see in the example yaml file, an important thing in the QuestEngine is that you can create variables for a quest and you should be able to set them and check them. The QuestEngine 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 QuestEngine has a number of functions:
 * finishQuest(): Mark the quest with  as finished
 * hasFinishedQuest(): Returns true if a quest is already finished
 * hasQuest(): Returns true if the PC has the quest with the quest_id, either finished or still going
 * addQuest(): 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:

quest[768]

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: , 12: }

This will only contain the quests that are not yet finished. These QuestObject's will also contain a number of features:
 * setValue: will set the value of quest variable (in the yaml file example this would be apples_gathered or dead_bodys_found.
 * getValue
 * getGoalValue
 * increaseValue: Increase the variable by
 * decreaseValue


 * isGoalValue: Return true when the variable has reached it's goal level
 * isEquelOrBiggerThanGoalValue: For quests that a minimum amount of objects or more
 * CheckValue: Check if the variable ==

So if you want to increase the value of the apples_gathered by one you would call: quest[768].increaseValue("apples_gathered",1)

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

Some sample code: quest = QuestEngine quest.addQuest("apples_and_body.yaml") quest[768].increaseValue("apples_gathered",1) quest[768].setValue("dead_body_found",true) print "Check if the dead body is found:", quest[768].isGoalValue("dead_body_found") Check if the dead body is found: True
 * 1) Create the quest engine
 * 1) Add a quest to the quest log (the yaml file is defined on the top of this page)
 * 1) Increase the apples_gathered variable by one
 * 1) Set the dead_body_found variable to true
 * 1) Check if you've found the body

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

http://pastebin.com/f14056433 (quest_engine.py)

http://pastebin.com/f321c22bc (demo.py)

http://pastebin.com/f1ef7587b (apples_body.yaml)