# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1276636381 0 # Node ID 3b933753cba80fa7a1d44d981ea2d6639e83fc0c # Parent d0282579668c4e76cc951be1a95dc5555136c69c QuestManager now loads all quests. Added some more comments. diff -r d0282579668c -r 3b933753cba8 demos/rpg/maps/quests.xml --- a/demos/rpg/maps/quests.xml Tue Jun 15 17:53:20 2010 +0000 +++ b/demos/rpg/maps/quests.xml Tue Jun 15 21:13:01 2010 +0000 @@ -1,5 +1,8 @@ + + Quiller + test_quest1 ; test_quest2 type : RETURN_ITEM ; name : Test quest ; desc : This is the first quest you will get diff -r d0282579668c -r 3b933753cba8 demos/rpg/scripts/actors/player.py --- a/demos/rpg/scripts/actors/player.py Tue Jun 15 17:53:20 2010 +0000 +++ b/demos/rpg/scripts/actors/player.py Tue Jun 15 21:13:01 2010 +0000 @@ -81,10 +81,8 @@ for questid in activequests: self._gamecontroller.questmanager.activateQuestById(questid) - print "loaded active quest: " + questid completedquests = valuedict['completedquests'].split(",") for questid in completedquests: self._gamecontroller.questmanager.completeQuestById(questid) - print "loaded completed quest: " + questid diff -r d0282579668c -r 3b933753cba8 demos/rpg/scripts/actors/questgiver.py --- a/demos/rpg/scripts/actors/questgiver.py Tue Jun 15 17:53:20 2010 +0000 +++ b/demos/rpg/scripts/actors/questgiver.py Tue Jun 15 21:13:01 2010 +0000 @@ -36,20 +36,30 @@ super(QuestGiver, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) self._type = GameObjectTypes["QUESTGIVER"] - def addQuest(self, quest): - pass - def offerNextQuest(self): + """ + Brings up the quest dialog of there is a quest to be offered to the player. + """ if self._gamecontroller.questmanager.getNextQuest(self.id): self._gamecontroller.guicontroller.showQuestDialog(self) def getNextQuest(self): + """ + Returns the next quest that will be offered by this QuestGiver. + """ return self._gamecontroller.questmanager.getNextQuest(self.id) def activateQuest(self, quest): + """ + This is called after the player accepts a quest. It marks it as active or "in progress". + """ self._gamecontroller.questmanager.activateQuest(quest) def completeQuest(self): + """ + Checks to see if the active quest owned by this QuestGiver is complete and + removes the required items or gold from the players inventory. + """ for activequest in self._gamecontroller.questmanager.activequests: if activequest.ownerid == self.id: if activequest.checkQuestCompleted(self._gamecontroller.scene.player): @@ -65,6 +75,10 @@ self.say("Come back when you have all the items I requested!") def haveQuest(self): + """ + Returns True if there is either an active quest or the QuestGiver has a new quest to give + the player. Returns False otherwise. + """ return bool(self._gamecontroller.questmanager.getNextQuest(self.id)) or bool(self._getActiveQuest()) def _getActiveQuest(self): diff -r d0282579668c -r 3b933753cba8 demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Tue Jun 15 17:53:20 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Tue Jun 15 21:13:01 2010 +0000 @@ -293,6 +293,9 @@ for filename in glob.glob(os.path.join("saves" , "*.xml")): os.remove(filename) + + self._questmanager.destroy() + self._questmanager.initializeQuests() mapname = self._settings.get("RPG", "TownMapFile", "town") self.loadMap(mapname) @@ -340,6 +343,8 @@ """ if self._scene: self._scene.serialize() + + self._questmanager.destroy() self._listener.detach() self._scene.destroyScene() diff -r d0282579668c -r 3b933753cba8 demos/rpg/scripts/quests/questmanager.py --- a/demos/rpg/scripts/quests/questmanager.py Tue Jun 15 17:53:20 2010 +0000 +++ b/demos/rpg/scripts/quests/questmanager.py Tue Jun 15 21:13:01 2010 +0000 @@ -26,14 +26,46 @@ from fife import fife +from fife.extensions.fife_settings import Setting +from scripts.quests.basequest import Quest, ReturnItemQuest, QuestTypes + class QuestManager(object): def __init__(self, gamecontroller): self._gamecontroller = gamecontroller + + self._questsettings = None self._quests = {} self._activequests = [] self._completedquests = [] + def initializeQuests(self): + questfile = self._gamecontroller.settings.get("RPG", "QuestFile", "maps/quests.xml") + + self._questsettings = Setting(settings_file=questfile) + + for identifier in self._questsettings.get("QuestGivers", "list", []): + for quest in self._questsettings.get(identifier, "questlist", []): + questdict = self._questsettings.get(identifier, quest, {}) + + if questdict['type'] == "RETURN_ITEM": + questobj = ReturnItemQuest(identifier, quest, questdict['name'], questdict['desc']) + for ritem in self._questsettings.get(quest+"_items", "itemlist", []): + itemdict = self._questsettings.get(quest+"_items", ritem, {}) + if itemdict["name"] == "GOLD_COINS": + questobj.addRequiredGold(int(itemdict['value'])) + else: + questobj.addRequiredItem(ritem) + else: + questobj = Quest(identifier, quest, questdict['name'], questdict['desc']) + + self._gamecontroller.questmanager.addQuest(questobj) + + def destroy(self): + self._quests = {} + self._activequests = [] + self._completedquests = [] + def addQuest(self, quest): if self._quests.has_key(quest.ownerid): if not quest in self._quests[quest.ownerid]: diff -r d0282579668c -r 3b933753cba8 demos/rpg/scripts/scene.py --- a/demos/rpg/scripts/scene.py Tue Jun 15 17:53:20 2010 +0000 +++ b/demos/rpg/scripts/scene.py Tue Jun 15 21:13:01 2010 +0000 @@ -55,7 +55,6 @@ self._objectsettings = None self._modelsettings = None - self._questsettings = None def loadObject(self, objectname, objectid=None, valuedict=None): if objectid: @@ -75,31 +74,12 @@ newobject = Portal(self._gamecontroller, self.itemlayer, objdict["type"], objectname, modeldict["model"], identifier) elif objdict["type"] == "QUESTGIVER": newobject = QuestGiver(self._gamecontroller, self.actorlayer, objdict["type"], objectname, modeldict["model"], identifier, True) - - for quest in self._questsettings.get(identifier, "questlist", []): - questdict = self._questsettings.get(identifier, quest, {}) - - if questdict['type'] == "RETURN_ITEM": - questobj = ReturnItemQuest(newobject.id, quest, questdict['name'], questdict['desc']) - for ritem in self._questsettings.get(quest+"_items", "itemlist", []): - itemdict = self._questsettings.get(quest+"_items", ritem, {}) - if itemdict["name"] == "GOLD_COINS": - questobj.addRequiredGold(int(itemdict['value'])) - else: - questobj.addRequiredItem(ritem) - else: - questobj = Quest(newobject.id, quest, questdict['name'], questdict['desc']) - - newobject.addQuest(questobj) - - #add quest to quest manager as well - self._gamecontroller.questmanager.addQuest(questobj) - elif objdict["type"] == "NPC": newobject = Actor(self._gamecontroller, self.actorlayer, objdict["type"], objectname, modeldict["model"], identifier, True) else: return None - + + #if the valuedict is supplied it overrides the loaded default values if valuedict: newobject.deserialize(valuedict) else: @@ -163,7 +143,6 @@ self._objectsettings = Setting(settings_file=objectfile) self._modelsettings = Setting(settings_file=modelfile) - self._questsettings = Setting(settings_file=questfile) for cam in self._map.getCameras(): self._cameras[cam.getId()] = cam @@ -173,8 +152,6 @@ self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) self._itemlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ItemLayer", "item_layer")) - #self.loadItems(mapfilename) - #self.loadActors(mapfilename) self.loadObjects(mapfilename) #finally load the player @@ -208,7 +185,6 @@ self._objectsettings = None self._modelsettings = None - self._questsettings = None def getInstancesAt(self, clickpoint, layer): """