Mercurial > fife-parpg
changeset 542:67f6f3538e88
Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 01 Jun 2010 21:38:14 +0000 |
parents | eb1963084657 |
children | cb7ec12214a9 |
files | demos/rpg/maps/allobjects.xml demos/rpg/scripts/quests/basequest.py demos/rpg/scripts/scene.py |
diffstat | 3 files changed, 44 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <Module name="Quiller"> <Setting name="questcount" type="int"> 2 </Setting> - <Setting name="quest1" type="dict"> name : Test quest ; desc : This is the first quest you will get ; items : GoldStack ; value : 5000 </Setting> - <Setting name="quest2" type="dict"> name : Second quest ; desc : This is the second quest you will get ; items : GoldStack ; value : 5000 </Setting> + <Setting name="quest1" type="dict"> type : RETURN_ITEM ; name : Test quest ; desc : This is the first quest you will get ; items : GoldStack ; value : 5000 </Setting> + <Setting name="quest2" type="dict"> type : RETURN_ITEM ; name : Second quest ; desc : This is the second quest you will get ; items : GoldStack ; value : 5000 </Setting> </Module> </Settings>
--- 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) -
--- 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():