changeset 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 082e919cc348
children 9fbe3dce925a
files demos/rpg/misc/help.txt demos/rpg/scripts/actors/baseactor.py demos/rpg/scripts/actors/questgiver.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/quests/__init__.py demos/rpg/scripts/quests/basequest.py demos/rpg/scripts/rpg.py demos/rpg/scripts/scene.py
diffstat 7 files changed, 196 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/demos/rpg/misc/help.txt	Sat May 29 17:52:07 2010 +0000
+++ b/demos/rpg/misc/help.txt	Mon May 31 17:45:04 2010 +0000
@@ -1,3 +1,4 @@
-help - This message
-exit - Quit the game
-quit - Quit the game
+eval - Evaluate a python expression
+exit, quit - Quit the game
+help - Displays this message
+spawn - Spawns an item or actor
--- a/demos/rpg/scripts/actors/baseactor.py	Sat May 29 17:52:07 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py	Mon May 31 17:45:04 2010 +0000
@@ -169,110 +169,3 @@
 	nextaction = property(_getNextAction, _setNextAction)
 	gold = property(_getGold, _setGold)
 	inventory = property(_getInventory)
-
-class Quest(object):
-	def __init__(self, owner, questname, questtext):
-		self._owner = owner
-		self._name = questname
-		self._text = questtext
-		self._requireditems = []
-		self._requiredgold = 0
-		
-	def addRequiredItem(self, itemid):
-		self._requireditems.append(itemid)
-		
-	def addRequiredGold(self, goldcount):
-		self._requiredgold += goldcount
-		
-	def checkQuestCompleted(self, actor):
-		completed = False
-		
-		if self._requiredgold > 0:
-			if actor.gold >= self._requiredgold:
-				completed = True
-				
-		for item in self._requireditems:
-			if item in actor.inventory:
-				completed = True
-				
-		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)
-
-class QuestGiver(Actor):
-	def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
-		self._type = GameObjectTypes["QUESTGIVER"]
-		super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance)
-	
-		self._quests = []
-		
-		self._activequest = None
-	
-	def addQuest(self, 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):
-		if self._activequest in self._quests:
-			if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player):
-				self.say("That everything I need.  Thank you!")
-				self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold
-				
-				for itemid in self._activequest.requireditems:
-					self._gamecontroller.scene.player.removeItemFromInventory(itemid)
-					
-				self._quests.remove(self._activequest)
-				self._activequest = None
-			else:
-				self.say("Come back when you have all the items I requested!")
-		else:
-			#something went wrong
-			self._activequest = None
-	
-	def haveQuest(self):
-		return len(self._quests) > 0
-	
-	def _getActiveQuest(self):
-		return self._activequest
-		
-	activequest = property(_getActiveQuest)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/actors/questgiver.py	Mon May 31 17:45:04 2010 +0000
@@ -0,0 +1,85 @@
+#!/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, instancename, instanceid=None, createInstance=False):
+		self._type = GameObjectTypes["QUESTGIVER"]
+		super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance)
+	
+		self._quests = []
+		
+		self._activequest = None
+	
+	def addQuest(self, 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):
+		if self._activequest in self._quests:
+			if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player):
+				self.say("That everything I need.  Thank you!")
+				self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold
+				
+				for itemid in self._activequest.requireditems:
+					self._gamecontroller.scene.player.removeItemFromInventory(itemid)
+					
+				self._quests.remove(self._activequest)
+				self._activequest = None
+			else:
+				self.say("Come back when you have all the items I requested!")
+		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/gamecontroller.py	Sat May 29 17:52:07 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Mon May 31 17:45:04 2010 +0000
@@ -207,7 +207,6 @@
 			if arg != "":
 				cmd.append(arg)
 		
-	
 		if cmd[0] == "spawn":
 			result = "Usage: spawn [item|actor] [id] [posx] [posy]"
 			if len(cmd) != 5:
@@ -222,7 +221,7 @@
 					return result
 				if obj:
 					self._scene.addObjectToScene(obj)
-					result = "Success!"
+					result = "--OK--"
 				else:
 					result = "Error: Not Found!"
 			
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/quests/basequest.py	Mon May 31 17:45:04 2010 +0000
@@ -0,0 +1,85 @@
+#!/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, time
+from datetime import datetime
+
+from fife import fife
+
+class Quest(object):
+	def __init__(self, owner, questname, questtext):
+		self._owner = owner
+		self._name = questname
+		self._text = questtext
+		self._requireditems = []
+		self._requiredgold = 0
+		
+	def addRequiredItem(self, itemid):
+		self._requireditems.append(itemid)
+		
+	def addRequiredGold(self, goldcount):
+		self._requiredgold += goldcount
+		
+	def checkQuestCompleted(self, actor):
+		completed = False
+		
+		if self._requiredgold > 0:
+			if actor.gold >= self._requiredgold:
+				completed = True
+				
+		for item in self._requireditems:
+			if item in actor.inventory:
+				completed = True
+				
+		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/rpg.py	Sat May 29 17:52:07 2010 +0000
+++ b/demos/rpg/scripts/rpg.py	Mon May 31 17:45:04 2010 +0000
@@ -91,23 +91,33 @@
 			command.consume()
 
 	def onConsoleCommand(self, command):
-		result = ''
-		if command.lower() in ('quit', 'exit'):
+		result = ""
+		
+		args = command.split(" ")
+		cmd = []
+		for arg in args:
+			arg = arg.strip()
+			if arg != "":
+				cmd.append(arg)		
+		
+		if cmd[0].lower() in ('quit', 'exit'):
 			self.quit = True
 			result = 'quitting'
-		elif command.lower() in ( 'help', 'help()' ):
+		elif cmd[0].lower() in ( 'help' ):
 			helptextfile = self._gamecontroller.settings.get("RPG", "HelpText", "misc/help.txt")
 			self._engine.getGuiManager().getConsole().println( open( helptextfile, 'r' ).read() )
-			result = "-OK-"
+			result = "--OK--"
+		elif cmd[0].lower() in ( 'eval' ):
+			try:
+				result = str(eval(command.lstrip(cmd[0])))
+			except:
+				result = "Invalid eval statement..."
 		else:
 			result = self._gamecontroller.onConsoleCommand(command)
-		if not result:
-			try:
-				result = str(eval(command))
-			except:
-				pass
+			
 		if not result:
 			result = 'Command Not Found...'
+		
 		return result
 		
 	def onToolsClick(self):
--- a/demos/rpg/scripts/scene.py	Sat May 29 17:52:07 2010 +0000
+++ b/demos/rpg/scripts/scene.py	Mon May 31 17:45:04 2010 +0000
@@ -32,7 +32,8 @@
 from fife.extensions.fife_settings import Setting
 
 from scripts.actors.baseactor import Actor
-from scripts.actors.baseactor import QuestGiver, Quest
+from scripts.actors.questgiver import QuestGiver
+from scripts.quests.basequest import Quest
 from scripts.actors.player import Player
 from scripts.objects.baseobject import GameObjectTypes
 from scripts.objects.items import BaseItem, GoldStack