comparison demos/rpg/scripts/actors/baseactor.py @ 521:494c60cf61cf

Player can now receive a quest, accept it, and complete it. Quests do not have any requirements (i.e. bring me back an item.. etc etc) to be completed at this time.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 27 May 2010 17:31:28 +0000
parents b6bd314df28a
children d01eb65b2726
comparison
equal deleted inserted replaced
520:b6bd314df28a 521:494c60cf61cf
51 self._source = sourceobj 51 self._source = sourceobj
52 self._dest = destobj 52 self._dest = destobj
53 53
54 def execute(self): 54 def execute(self):
55 print "talking to: " + self._dest.instance.getId() 55 print "talking to: " + self._dest.instance.getId()
56 self._source.showQuestDialog() 56
57 if self._dest.haveQuest():
58 if not self._dest.activequest:
59 self._dest.offerNextQuest()
60 else:
61 self._dest.completeQuest()
57 62
58 ActorStates = {'STAND':0, 63 ActorStates = {'STAND':0,
59 'WALK':1, 64 'WALK':1,
60 'ATTACK':2} 65 'ATTACK':2}
61 66
108 self._nextaction = action 113 self._nextaction = action
109 114
110 state = property(_getState, _setState) 115 state = property(_getState, _setState)
111 nextaction = property(_getNextAction, _setNextAction) 116 nextaction = property(_getNextAction, _setNextAction)
112 117
118 class Quest(object):
119 def __init__(self, owner, questname, questtext):
120 self._owner = owner
121 self._name = questname
122 self._text = questtext
123
124 def _getOwner(self):
125 return self._owner
126
127 def _getName(self):
128 return self._name
129
130 def _setName(self, questname):
131 self._name = questname
132
133 def _getText(self):
134 return self._text
135
136 def _setText(self, questtext):
137 self._text = questtext
138
139 owner = property(_getOwner)
140 name = property(_getName, _setName)
141 text = property(_getText, _setText)
142
113 class QuestGiver(Actor): 143 class QuestGiver(Actor):
114 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): 144 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
115 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance) 145 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance)
116 146
117 self._type = GameObjectTypes["QUESTGIVER"] 147 self._type = GameObjectTypes["QUESTGIVER"]
118 self._quests = [] 148 self._quests = []
149
150 self._activequest = None
119 151
120 def addQuest(self, quest): 152 def addQuest(self, quest):
121 self._quests.append(quest) 153 self._quests.append(quest)
154
155 def offerNextQuest(self):
156 if self._activequest:
157 return
158
159 if len(self._quests) > 0:
160 self._gamecontroller.guicontroller.showQuestDialog(self)
161
162 def getNextQuest(self):
163 if len(self._quests) > 0:
164 return self._quests[0]
165
166 return None
167
168 def activateQuest(self, quest):
169 self._activequest = quest
170
171 def completeQuest(self):
172 #@todo check to see if requirements are met
173 if self._activequest in self._quests:
174 print "quest completed"
175 self._quests.remove(self._activequest)
176 self._activequest = None
177 else:
178 #something went wrong
179 self._activequest = None
180
181 def haveQuest(self):
182 return len(self._quests) > 0
183
184 def _getActiveQuest(self):
185 return self._activequest
186
187 activequest = property(_getActiveQuest)