view demos/rpg/scripts/actors/questgiver.py @ 697:ecaa4d98f05f tip

Abstracted the GUI code and refactored the GUIChan-specific code into its own module. * Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring. * GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass. * The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class. * The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged. * Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 18 Jun 2011 00:28:40 -1000
parents 69d50e751c9a
children
line wrap: on
line source

#!/usr/bin/env python

# -*- coding: utf-8 -*-

# ####################################################################
#  Copyright (C) 2005-2010 by the FIFE team
#  http://www.fifengine.net
#  This file is part of FIFE.
#
#  FIFE is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the
#  Free Software Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
# ####################################################################
# This is the rio de hola client for FIFE.

import sys, os, re, math, random, shutil

from fife import fife

from scripts.objects.baseobject import BaseGameObject, GameObjectTypes
from scripts.actors.baseactor import Actor

class QuestGiver(Actor):
	def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
		super(QuestGiver, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance)
		self._type = GameObjectTypes["QUESTGIVER"]
		
		self._noquest_dialog = "I've got nothing for you...  leave me alone."
	
	def offerNextQuest(self):
		"""
		Brings up the quest dialog of there is a quest to be offered to the player.
		"""
		if self._gamecontroller.questmanager.getNextQuest(self.id):
			self._gamecontroller.guicontroller.showQuestDialog(self)
		
	def getNextQuest(self):
		"""
		Returns the next quest that will be offered by this QuestGiver.
		"""
		return self._gamecontroller.questmanager.getNextQuest(self.id)
		
	def activateQuest(self, quest):
		"""
		This is called after the player accepts a quest.  It marks it as active or "in progress".
		"""
		self._gamecontroller.questmanager.activateQuest(quest)
	
	def showNoQuestDialog(self):
		self.say(self._noquest_dialog)
	
	def completeQuest(self):
		"""
		Checks to see if the active quest owned by this QuestGiver is complete and 
		removes the required items or gold from the players inventory.
		"""
		for activequest in self._gamecontroller.questmanager.activequests:
			if activequest.ownerid == self.id:
				if activequest.checkQuestCompleted(self._gamecontroller.scene.player):
					self.say(activequest._complete_dialog)
			
					self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - activequest.requiredgold
				
					for itemid in activequest.requireditems:
						self._gamecontroller.scene.player.removeItemFromInventory(itemid)
			
					self._gamecontroller.questmanager.completeQuest(activequest)
				else:
					self.say(activequest._incomplete_dialog)
	
	def haveQuest(self):
		"""
		Returns True if there is either an active quest or the QuestGiver has a new quest to give
		the player.  Returns False otherwise.
		"""
		return bool(self._gamecontroller.questmanager.getNextQuest(self.id)) or bool(self._getActiveQuest())

	def serialize(self):
		lvars = super(QuestGiver, self).serialize()

		lvars['noquest_dialog'] = self._noquest_dialog
	
		return lvars

	def deserialize(self, valuedict):
		super(QuestGiver, self).deserialize(valuedict)
		
		self._noquest_dialog = valuedict['noquest_dialog']
		
	
	def _getActiveQuest(self):
		"""
		Returns the first active quest in the list.  There should only be one
		active quest per questgiver anyway.
		"""
		for quest in self._gamecontroller.questmanager.activequests:
			if quest.ownerid == self.id:
				return quest
		
	activequest = property(_getActiveQuest)