changeset 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 7b451e3b2439
files demos/rpg/gui/quest.xml demos/rpg/maps/town_objects.xml demos/rpg/scripts/actors/baseactor.py demos/rpg/scripts/actors/player.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/guicontroller.py demos/rpg/scripts/scene.py
diffstat 7 files changed, 91 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/demos/rpg/gui/quest.xml	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/gui/quest.xml	Thu May 27 17:31:28 2010 +0000
@@ -2,7 +2,7 @@
 	<VBox name="credits" position="312,200" opaque="1" base_color="188,0,0">
 		<HBox>
 			<Spacer />
-			<Label name="questlabel" border_size="0" text="Quest" />
+			<Label name="questname" border_size="0" text="Quest" />
 			<Spacer />
 		</HBox>
 		<HBox>
--- a/demos/rpg/maps/town_objects.xml	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/maps/town_objects.xml	Thu May 27 17:31:28 2010 +0000
@@ -4,4 +4,8 @@
     <Setting name="npclist" type="list"> Quiller </Setting>
     <Setting name="Quiller" type="list"> QUESTGIVER ; warrior ; 1.0 ; 1.0 </Setting>
   </Module>
+  <Module name="Quiller">
+  	<Setting name="questcount" type="int"> 1 </Setting>
+  	<Setting name="quest1" type="list"> Test quest ; This is the first quest you will get </Setting>
+  </Module>
 </Settings>
--- a/demos/rpg/scripts/actors/baseactor.py	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py	Thu May 27 17:31:28 2010 +0000
@@ -53,7 +53,12 @@
 		
 	def execute(self):
 		print "talking to: " + self._dest.instance.getId()
-		self._source.showQuestDialog()
+		
+		if self._dest.haveQuest():
+			if not self._dest.activequest:
+				self._dest.offerNextQuest()
+			else:
+				self._dest.completeQuest()
 
 ActorStates = {'STAND':0,
 			   'WALK':1,
@@ -110,12 +115,73 @@
 	state = property(_getState, _setState)
 	nextaction = property(_getNextAction, _setNextAction)
 
+class Quest(object):
+	def __init__(self, owner, questname, questtext):
+		self._owner = owner
+		self._name = questname
+		self._text = questtext
+	
+	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 QuestGiver(Actor):
 	def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
 		super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance)
 	
 		self._type = GameObjectTypes["QUESTGIVER"]
 		self._quests = []
+		
+		self._activequest = None
 	
 	def addQuest(self, quest):
-		self._quests.append(quest)	
+		self._quests.append(quest)
+		
+	def offerNextQuest(self):
+		if self._activequest:
+			return
+	
+		if len(self._quests) > 0:
+			self._gamecontroller.guicontroller.showQuestDialog(self)
+		
+	def getNextQuest(self):
+		if len(self._quests) > 0:
+			return self._quests[0]
+		
+		return None
+		
+	def activateQuest(self, quest):
+		self._activequest = quest
+			
+	def completeQuest(self):
+		#@todo check to see if requirements are met
+		if self._activequest in self._quests:
+			print "quest completed"
+			self._quests.remove(self._activequest)
+			self._activequest = None
+		else:
+			#something went wrong
+			self._activequest = None
+	
+	def haveQuest(self):
+		return len(self._quests) > 0
+	
+	def _getActiveQuest(self):
+		return self._activequest
+		
+	activequest = property(_getActiveQuest)
--- a/demos/rpg/scripts/actors/player.py	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/scripts/actors/player.py	Thu May 27 17:31:28 2010 +0000
@@ -37,7 +37,7 @@
 	def onInstanceActionFinished(self, instance, action):
 		super(PlayerActionListener, self).onInstanceActionFinished(instance, action)
 		if action.getId() == 'walk':
-			print "player done walking"
+			pass
 			#self._object.completeAction()
 
 class Player(Actor):
@@ -48,6 +48,3 @@
 		self._playeractionlistener = PlayerActionListener(self._gamecontroller, self)
 		
 		self._type = GameObjectTypes["PLAYER"]
-		
-	def showQuestDialog(self):
-		self._gamecontroller.guicontroller.showQuestDialog()
--- a/demos/rpg/scripts/gamecontroller.py	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Thu May 27 17:31:28 2010 +0000
@@ -90,7 +90,6 @@
 			instances = self._gamecontroller.scene.getInstancesAt(clickpoint)
 			if instances:
 				obj = self._gamecontroller.scene.objectlist[instances[0].getId()]
-				print obj.type
 				if obj.type == GameObjectTypes["QUESTGIVER"]:
 					action = TalkAction(self._gamecontroller.scene.player, obj)
 					self._gamecontroller.scene.player.nextaction = action
--- a/demos/rpg/scripts/guicontroller.py	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/scripts/guicontroller.py	Thu May 27 17:31:28 2010 +0000
@@ -75,11 +75,17 @@
 		self._widget.mapEvents(eventMap)
 	
 class QuestDialog(Window):
-	def __init__(self, guicontroller):
+	def __init__(self, guicontroller, questgiver):
 		super(QuestDialog, self).__init__(guicontroller)
 		self._widget = pychan.loadXML('gui/quest.xml')
+		self._questgiver = questgiver
+		self._quest = questgiver.getNextQuest()
+		
+		self._questname = self._widget.findChild(name="questname")
+		self._questname.text = unicode(self._quest.name)
 		
 		self._questtext = self._widget.findChild(name="questtext")
+		self._questtext.text = unicode(self._quest.text)
 
 		eventMap = {
 			'accept': self.questAccepted,
@@ -90,6 +96,7 @@
 		
 	def questAccepted(self):
 		print "quest has been accepted"
+		self._questgiver.activateQuest(self._quest)
 		self._widget.hide()
 	
 class GUIController(object):
@@ -126,6 +133,6 @@
 			self._credits.widget.hide()
 			self._credits = None
 			
-	def showQuestDialog(self):
-		questdlg = QuestDialog(self._gamecontroller)
+	def showQuestDialog(self, questgiver):
+		questdlg = QuestDialog(self._gamecontroller, questgiver)
 		questdlg.widget.show()
--- a/demos/rpg/scripts/scene.py	Thu May 27 16:29:07 2010 +0000
+++ b/demos/rpg/scripts/scene.py	Thu May 27 17:31:28 2010 +0000
@@ -31,7 +31,7 @@
 from fife.extensions.fife_settings import Setting
 
 from scripts.actors.baseactor import Actor
-from scripts.actors.baseactor import QuestGiver
+from scripts.actors.baseactor import QuestGiver, Quest
 from scripts.actors.player import Player
 from scripts.objects.baseobject import GameObjectTypes
 
@@ -71,6 +71,12 @@
 			(objtype, modelname, posx, posy) = objectsettings.get(mapname[0], npc, ["NPC", "warrior", "0", "0"])
 			if objtype == "QUESTGIVER":
 				actor = QuestGiver(self._gamecontroller, modelname, npc, True)
+				questcount = objectsettings.get(npc, "questcount", 0)
+				for x in range(1,questcount+1):
+					quest = "quest" + str(x)
+					(qname, qtext) = objectsettings.get(npc, quest, [])
+					actor.addQuest(Quest(actor, qname, qtext))
+						
 			elif objtype == "NPC":
 				actor = Actor(self._gamecontroller, modelname, npc, True)