comparison demos/rpg/scripts/quests/questmanager.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
children 3b933753cba8
comparison
equal deleted inserted replaced
549:c9113e23b004 550:d0282579668c
1 #!/usr/bin/env python
2
3 # -*- coding: utf-8 -*-
4
5 # ####################################################################
6 # Copyright (C) 2005-2010 by the FIFE team
7 # http://www.fifengine.net
8 # This file is part of FIFE.
9 #
10 # FIFE is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 # ####################################################################
25 # This is the rio de hola client for FIFE.
26
27 from fife import fife
28
29 class QuestManager(object):
30 def __init__(self, gamecontroller):
31 self._gamecontroller = gamecontroller
32
33 self._quests = {}
34 self._activequests = []
35 self._completedquests = []
36
37 def addQuest(self, quest):
38 if self._quests.has_key(quest.ownerid):
39 if not quest in self._quests[quest.ownerid]:
40 self._quests[quest.ownerid].append(quest)
41 else:
42 self._quests[quest.ownerid] = [quest]
43
44 def getQuest(self, questid):
45 for owner in self._quests:
46 for quest in self._quests[owner]:
47 if quest.id == questid:
48 return quest
49
50 return None
51
52 def getNextQuest(self, ownerid):
53 for quest in self._quests[ownerid]:
54 if not quest in self._activequests and not quest in self._completedquests:
55 return quest
56
57 return None
58
59 def activateQuest(self, quest):
60 if not quest in self._activequests:
61 self._activequests.append(quest)
62
63 def completeQuest(self, quest):
64 if not quest in self._completedquests:
65 self._completedquests.append(quest)
66
67 if quest in self._activequests:
68 self._activequests.remove(quest)
69
70 def activateQuestById(self, questid):
71 quest = self.getQuest(questid)
72 if quest:
73 self.activateQuest(quest)
74
75 def completeQuestById(self, questid):
76 quest = self.getQuest(questid)
77 if quest:
78 self.completeQuest(quest)
79
80 def _getActiveQuests(self):
81 return self._activequests
82
83 def _getCompletedQuests(self):
84 return self._completedquests
85
86 def _getAllQuests(self):
87 return self._quests
88
89 activequests = property(_getActiveQuests)
90 completedquests = property(_getCompletedQuests)
91 quests = property(_getAllQuests)