Mercurial > fife-parpg
diff demos/rpg/scripts/actors/questgiver.py @ 550:d0282579668c
Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
Started adding more comments.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 15 Jun 2010 17:53:20 +0000 |
parents | 8fee2d2286e9 |
children | 3b933753cba8 |
line wrap: on
line diff
--- a/demos/rpg/scripts/actors/questgiver.py Fri Jun 11 21:29:58 2010 +0000 +++ b/demos/rpg/scripts/actors/questgiver.py Tue Jun 15 17:53:20 2010 +0000 @@ -36,50 +36,44 @@ super(QuestGiver, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) self._type = GameObjectTypes["QUESTGIVER"] - self._quests = [] - - self._activequest = None - def addQuest(self, quest): - self._quests.append(quest) + pass def offerNextQuest(self): - if self._activequest: - return - - if len(self._quests) > 0: + if self._gamecontroller.questmanager.getNextQuest(self.id): self._gamecontroller.guicontroller.showQuestDialog(self) def getNextQuest(self): - if len(self._quests) > 0: - return self._quests[0] - - return None + return self._gamecontroller.questmanager.getNextQuest(self.id) def activateQuest(self, quest): - self._activequest = quest + self._gamecontroller.questmanager.activateQuest(quest) def completeQuest(self): - if self._activequest in self._quests: - if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player): - self.say("That everything I need. Thank you!") - self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold + for activequest in self._gamecontroller.questmanager.activequests: + if activequest.ownerid == self.id: + if activequest.checkQuestCompleted(self._gamecontroller.scene.player): + self.say("That everything I need. Thank you!") + + self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - activequest.requiredgold - for itemid in self._activequest.requireditems: - self._gamecontroller.scene.player.removeItemFromInventory(itemid) - - self._quests.remove(self._activequest) - self._activequest = None - else: - self.say("Come back when you have all the items I requested!") - else: - #something went wrong - self._activequest = None + for itemid in activequest.requireditems: + self._gamecontroller.scene.player.removeItemFromInventory(itemid) + + self._gamecontroller.questmanager.completeQuest(activequest) + else: + self.say("Come back when you have all the items I requested!") def haveQuest(self): - return len(self._quests) > 0 + return bool(self._gamecontroller.questmanager.getNextQuest(self.id)) or bool(self._getActiveQuest()) def _getActiveQuest(self): - return self._activequest + """ + Returns the first active quest in the list. There should only be one + active quest per questgiver anyway. + """ + for quest in self._gamecontroller.questmanager.activequests: + if quest.ownerid == self.id: + return quest activequest = property(_getActiveQuest)