comparison demos/rpg/scripts/actors/baseactor.py @ 534:65a92a2449d5

Doing some re-factoring. Minor change to the way the console commands are parsed. Added the spawn command to the help file.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 31 May 2010 17:45:04 +0000
parents d0bce896a526
children 9fbe3dce925a
comparison
equal deleted inserted replaced
533:082e919cc348 534:65a92a2449d5
167 167
168 state = property(_getState, _setState) 168 state = property(_getState, _setState)
169 nextaction = property(_getNextAction, _setNextAction) 169 nextaction = property(_getNextAction, _setNextAction)
170 gold = property(_getGold, _setGold) 170 gold = property(_getGold, _setGold)
171 inventory = property(_getInventory) 171 inventory = property(_getInventory)
172
173 class Quest(object):
174 def __init__(self, owner, questname, questtext):
175 self._owner = owner
176 self._name = questname
177 self._text = questtext
178 self._requireditems = []
179 self._requiredgold = 0
180
181 def addRequiredItem(self, itemid):
182 self._requireditems.append(itemid)
183
184 def addRequiredGold(self, goldcount):
185 self._requiredgold += goldcount
186
187 def checkQuestCompleted(self, actor):
188 completed = False
189
190 if self._requiredgold > 0:
191 if actor.gold >= self._requiredgold:
192 completed = True
193
194 for item in self._requireditems:
195 if item in actor.inventory:
196 completed = True
197
198 return completed
199
200 def _getOwner(self):
201 return self._owner
202
203 def _getName(self):
204 return self._name
205
206 def _setName(self, questname):
207 self._name = questname
208
209 def _getText(self):
210 return self._text
211
212 def _setText(self, questtext):
213 self._text = questtext
214
215 def _getRequiredGold(self):
216 return self._requiredgold
217
218 def _getRequiredItems(self):
219 return self._requireditems
220
221 owner = property(_getOwner)
222 name = property(_getName, _setName)
223 text = property(_getText, _setText)
224 requiredgold = property(_getRequiredGold)
225 requireditems = property(_getRequiredItems)
226
227 class QuestGiver(Actor):
228 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
229 self._type = GameObjectTypes["QUESTGIVER"]
230 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance)
231
232 self._quests = []
233
234 self._activequest = None
235
236 def addQuest(self, quest):
237 self._quests.append(quest)
238
239 def offerNextQuest(self):
240 if self._activequest:
241 return
242
243 if len(self._quests) > 0:
244 self._gamecontroller.guicontroller.showQuestDialog(self)
245
246 def getNextQuest(self):
247 if len(self._quests) > 0:
248 return self._quests[0]
249
250 return None
251
252 def activateQuest(self, quest):
253 self._activequest = quest
254
255 def completeQuest(self):
256 if self._activequest in self._quests:
257 if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player):
258 self.say("That everything I need. Thank you!")
259 self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold
260
261 for itemid in self._activequest.requireditems:
262 self._gamecontroller.scene.player.removeItemFromInventory(itemid)
263
264 self._quests.remove(self._activequest)
265 self._activequest = None
266 else:
267 self.say("Come back when you have all the items I requested!")
268 else:
269 #something went wrong
270 self._activequest = None
271
272 def haveQuest(self):
273 return len(self._quests) > 0
274
275 def _getActiveQuest(self):
276 return self._activequest
277
278 activequest = property(_getActiveQuest)