Mercurial > fife-parpg
changeset 551:3b933753cba8
QuestManager now loads all quests.
Added some more comments.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 15 Jun 2010 21:13:01 +0000 |
parents | d0282579668c |
children | 718e154a43c8 |
files | demos/rpg/maps/quests.xml demos/rpg/scripts/actors/player.py demos/rpg/scripts/actors/questgiver.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/quests/questmanager.py demos/rpg/scripts/scene.py |
diffstat | 6 files changed, 59 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <?xml version='1.0' encoding='UTF-8'?> <Settings> + <Module name="QuestGivers"> + <Setting name="list" type="list"> Quiller </Setting> + </Module> <Module name="Quiller"> <Setting name="questlist" type="list"> test_quest1 ; test_quest2 </Setting> <Setting name="test_quest1" type="dict"> type : RETURN_ITEM ; name : Test quest ; desc : This is the first quest you will get </Setting>
--- 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
--- 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):
--- 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()
--- 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]:
--- 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): """