Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
549:c9113e23b004 | 550:d0282579668c |
---|---|
34 class QuestGiver(Actor): | 34 class QuestGiver(Actor): |
35 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): | 35 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): |
36 super(QuestGiver, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) | 36 super(QuestGiver, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) |
37 self._type = GameObjectTypes["QUESTGIVER"] | 37 self._type = GameObjectTypes["QUESTGIVER"] |
38 | 38 |
39 self._quests = [] | |
40 | |
41 self._activequest = None | |
42 | |
43 def addQuest(self, quest): | 39 def addQuest(self, quest): |
44 self._quests.append(quest) | 40 pass |
45 | 41 |
46 def offerNextQuest(self): | 42 def offerNextQuest(self): |
47 if self._activequest: | 43 if self._gamecontroller.questmanager.getNextQuest(self.id): |
48 return | |
49 | |
50 if len(self._quests) > 0: | |
51 self._gamecontroller.guicontroller.showQuestDialog(self) | 44 self._gamecontroller.guicontroller.showQuestDialog(self) |
52 | 45 |
53 def getNextQuest(self): | 46 def getNextQuest(self): |
54 if len(self._quests) > 0: | 47 return self._gamecontroller.questmanager.getNextQuest(self.id) |
55 return self._quests[0] | |
56 | |
57 return None | |
58 | 48 |
59 def activateQuest(self, quest): | 49 def activateQuest(self, quest): |
60 self._activequest = quest | 50 self._gamecontroller.questmanager.activateQuest(quest) |
61 | 51 |
62 def completeQuest(self): | 52 def completeQuest(self): |
63 if self._activequest in self._quests: | 53 for activequest in self._gamecontroller.questmanager.activequests: |
64 if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player): | 54 if activequest.ownerid == self.id: |
65 self.say("That everything I need. Thank you!") | 55 if activequest.checkQuestCompleted(self._gamecontroller.scene.player): |
66 self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold | 56 self.say("That everything I need. Thank you!") |
57 | |
58 self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - activequest.requiredgold | |
67 | 59 |
68 for itemid in self._activequest.requireditems: | 60 for itemid in activequest.requireditems: |
69 self._gamecontroller.scene.player.removeItemFromInventory(itemid) | 61 self._gamecontroller.scene.player.removeItemFromInventory(itemid) |
70 | 62 |
71 self._quests.remove(self._activequest) | 63 self._gamecontroller.questmanager.completeQuest(activequest) |
72 self._activequest = None | 64 else: |
73 else: | 65 self.say("Come back when you have all the items I requested!") |
74 self.say("Come back when you have all the items I requested!") | |
75 else: | |
76 #something went wrong | |
77 self._activequest = None | |
78 | 66 |
79 def haveQuest(self): | 67 def haveQuest(self): |
80 return len(self._quests) > 0 | 68 return bool(self._gamecontroller.questmanager.getNextQuest(self.id)) or bool(self._getActiveQuest()) |
81 | 69 |
82 def _getActiveQuest(self): | 70 def _getActiveQuest(self): |
83 return self._activequest | 71 """ |
72 Returns the first active quest in the list. There should only be one | |
73 active quest per questgiver anyway. | |
74 """ | |
75 for quest in self._gamecontroller.questmanager.activequests: | |
76 if quest.ownerid == self.id: | |
77 return quest | |
84 | 78 |
85 activequest = property(_getActiveQuest) | 79 activequest = property(_getActiveQuest) |