# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1275428294 0 # Node ID 67f6f3538e88aa40d21e73eb93e3570c24e36e5b # Parent eb19630846573ff0a71c1a938c7a9b729f7d6fdd Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type. diff -r eb1963084657 -r 67f6f3538e88 demos/rpg/maps/allobjects.xml --- a/demos/rpg/maps/allobjects.xml Tue Jun 01 19:19:08 2010 +0000 +++ b/demos/rpg/maps/allobjects.xml Tue Jun 01 21:38:14 2010 +0000 @@ -9,7 +9,7 @@ 2 - name : Test quest ; desc : This is the first quest you will get ; items : GoldStack ; value : 5000 - name : Second quest ; desc : This is the second quest you will get ; items : GoldStack ; value : 5000 + type : RETURN_ITEM ; name : Test quest ; desc : This is the first quest you will get ; items : GoldStack ; value : 5000 + type : RETURN_ITEM ; name : Second quest ; desc : This is the second quest you will get ; items : GoldStack ; value : 5000 diff -r eb1963084657 -r 67f6f3538e88 demos/rpg/scripts/quests/basequest.py --- a/demos/rpg/scripts/quests/basequest.py Tue Jun 01 19:19:08 2010 +0000 +++ b/demos/rpg/scripts/quests/basequest.py Tue Jun 01 21:38:14 2010 +0000 @@ -29,14 +29,41 @@ from fife import fife +QuestTypes = {'DEFAULT':0, + 'RETURN_ITEM':1} + class Quest(object): - """ - @todo: do a little refactoring here to split out the type of quests. - """ def __init__(self, owner, questname, questtext): self._owner = owner self._name = questname self._text = questtext + + def checkQuestCompleted(self, actor): + pass + + def _getOwner(self): + return self._owner + + def _getName(self): + return self._name + + def _setName(self, questname): + self._name = questname + + def _getText(self): + return self._text + + def _setText(self, questtext): + self._text = questtext + + owner = property(_getOwner) + name = property(_getName, _setName) + text = property(_getText, _setText) + +class ReturnItemQuest(Quest): + def __init__(self, owner, questname, questtext): + super(ReturnItemQuest, self).__init__(owner, questname, questtext) + self._requireditems = [] self._requiredgold = 0 @@ -59,30 +86,11 @@ return completed - def _getOwner(self): - return self._owner - - def _getName(self): - return self._name - - def _setName(self, questname): - self._name = questname - - def _getText(self): - return self._text - - def _setText(self, questtext): - self._text = questtext - def _getRequiredGold(self): return self._requiredgold def _getRequiredItems(self): return self._requireditems - owner = property(_getOwner) - name = property(_getName, _setName) - text = property(_getText, _setText) requiredgold = property(_getRequiredGold) requireditems = property(_getRequiredItems) - diff -r eb1963084657 -r 67f6f3538e88 demos/rpg/scripts/scene.py --- a/demos/rpg/scripts/scene.py Tue Jun 01 19:19:08 2010 +0000 +++ b/demos/rpg/scripts/scene.py Tue Jun 01 21:38:14 2010 +0000 @@ -33,7 +33,7 @@ from scripts.actors.baseactor import Actor from scripts.actors.questgiver import QuestGiver -from scripts.quests.basequest import Quest +from scripts.quests.basequest import Quest, ReturnItemQuest, QuestTypes from scripts.actors.player import Player from scripts.objects.baseobject import GameObjectTypes from scripts.objects.items import BaseItem, GoldStack, Portal @@ -93,13 +93,16 @@ for x in range(1,questcount+1): quest = "quest" + str(x) questdict = self._modelsettings.get(actorid, quest, {}) - quest = Quest(actor, questdict['name'], questdict['desc']) - for ritem in questdict['items'].split(" , "): - if ritem == "GoldStack": - quest.addRequiredGold(int(questdict['value'])) - else: - quest.addRequiredItem(ritem) + if questdict['type'] == "RETURN_ITEM": + quest = ReturnItemQuest(actor, questdict['name'], questdict['desc']) + for ritem in questdict['items'].split(" , "): + if ritem == "GoldStack": + quest.addRequiredGold(int(questdict['value'])) + else: + quest.addRequiredItem(ritem) + else: + quest = Quest(actor, questdict['name'], questdict['desc']) actor.addQuest(quest) @@ -141,7 +144,7 @@ except ObjectAlreadyInSceneError, e: self._gamecontroller.logger.log_error("Actor already part of scene:" + actor) - def loadPlayer(self): + def createPlayerObject(self): """ @todo: once we have all art assets this should be able to load one of 3 player models """ @@ -175,7 +178,7 @@ self.loadActors(mapfilename) #finally load the player - self.loadPlayer() + self.createPlayerObject() def destroyScene(self): for obj in self._objectlist.values():