# HG changeset patch
# User prock@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1275063900 0
# Node ID d0bce896a52629ab54a993a17e4c32001da639d9
# Parent 796d49ab9380608d5f5595240500f54972d6902d
Changed the quest format in the object xml file.
Quests can now required gold or items to complete.
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/maps/allobjects.xml
--- a/demos/rpg/maps/allobjects.xml Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/maps/allobjects.xml Fri May 28 16:25:00 2010 +0000
@@ -6,9 +6,9 @@
type : QUESTGIVER ; file : objects/actors/player/warrior/object.xml ; model : warrior
-
+
2
- Test quest ; This is the first quest you will get
- Second quest ; This is the second quest you will get
+ 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
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/maps/town_objects.xml
--- a/demos/rpg/maps/town_objects.xml Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/maps/town_objects.xml Fri May 28 16:25:00 2010 +0000
@@ -2,7 +2,7 @@
gstack1
- typename : GoldStack ; value : 5000 ; posx : 1.0 ; posy : 1.0
+ typename : GoldStack ; value : 5000 ; posx : 3.0 ; posy : 3.0
Quiller
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/scripts/actors/baseactor.py
--- a/demos/rpg/scripts/actors/baseactor.py Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py Fri May 28 16:25:00 2010 +0000
@@ -61,7 +61,7 @@
else:
self._dest.completeQuest()
else:
- self._dest.instance.say("I've got nothing for you... leave me alone.", 2500)
+ self._dest.say("I've got nothing for you... leave me alone.")
else:
self._dest.instance.say("Hello there!")
@@ -100,6 +100,10 @@
self._actionlistener = ActorActionListener(self._gamecontroller, self)
self._nextaction = None
+ self._inventory = []
+ self._maxinventoryitems = 20
+
+ self._gold = 0
self.stand()
@@ -111,19 +115,34 @@
self._state = ActorStates["WALK"]
self._instance.move('walk', location, self._walkspeed)
+ def say(self, text):
+ self._instance.say(text, 2500)
+
def performNextAction(self):
if self._nextaction:
self._nextaction.execute()
self._nextaction = None
def pickUpItem(self, item):
- self._inventory.append(item)
+ if len(self._inventory) >= self._maxinventoryitems:
+ return
+ else:
+ if item.modelname == "goldstack":
+ self._gold += item.value
+ else:
+ self._inventory.append(item)
- #removes it from FIFE (to stop rendering the item)
- item.destroy()
+ item.onPickUp()
+
+ def removeItemFromInventory(self, itemid):
+ itemtoremove = None
+ for item in self._inventory:
+ if item.id == itemid:
+ itemtoremove = item
- #remove it from the scene
- del self._gamecontroller.scene.objectlist[item.id]
+ if itemtoremove:
+ self._inventory.remove(itemtoremove)
+
def _getState(self):
return self._state
@@ -137,14 +156,46 @@
def _setNextAction(self, action):
self._nextaction = action
+ def _getGold(self):
+ return self._gold
+
+ def _setGold(self, gold):
+ self._gold = gold
+
+ def _getInventory(self):
+ return self._inventory
+
state = property(_getState, _setState)
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
@@ -161,9 +212,17 @@
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):
@@ -194,11 +253,18 @@
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
+ 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
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/scripts/actors/player.py
--- a/demos/rpg/scripts/actors/player.py Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/scripts/actors/player.py Fri May 28 16:25:00 2010 +0000
@@ -47,5 +47,3 @@
self._playermodelname = playermodelname
self._playeractionlistener = PlayerActionListener(self._gamecontroller, self)
-
- self._inventory = []
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/scripts/objects/baseobject.py
--- a/demos/rpg/scripts/objects/baseobject.py Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/scripts/objects/baseobject.py Fri May 28 16:25:00 2010 +0000
@@ -134,8 +134,12 @@
def _getId(self):
return self._id
+
+ def _getModelName(self):
+ return self._name
location = property(_getLocation, _setLocation)
instance = property(_getInstance)
type = property(_getType)
id = property(_getId)
+ modelname = property(_getModelName)
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/scripts/objects/items.py
--- a/demos/rpg/scripts/objects/items.py Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/scripts/objects/items.py Fri May 28 16:25:00 2010 +0000
@@ -37,14 +37,16 @@
super(BaseItem, self).__init__(gamecontroller, itemtype, itemname, True)
def onPickUp(self):
- #remove item from the map
- self.destroy()
+ #remove item from the scene
+ self._gamecontroller.scene.removeObjectFromScene(self)
def onDrop(self, dropx, dropy):
#recreate object
self._createFIFEInstance(self, self._gamecontroller.scene.itemlayer)
self.setMapPosition(dropx, dropy)
+ self._gamecontroller.scene.addObjectToScene(self)
+
def _getItemType(self):
return self._name
@@ -64,6 +66,6 @@
return self._value
def _setValue(self, value):
- self._value = value
+ self._value = int(value)
value = property(_getValue, _setValue)
diff -r 796d49ab9380 -r d0bce896a526 demos/rpg/scripts/scene.py
--- a/demos/rpg/scripts/scene.py Fri May 28 14:52:56 2010 +0000
+++ b/demos/rpg/scripts/scene.py Fri May 28 16:25:00 2010 +0000
@@ -102,8 +102,16 @@
questcount = modelsettings.get(npc, "questcount", 0)
for x in range(1,questcount+1):
quest = "quest" + str(x)
- (qname, qtext) = modelsettings.get(npc, quest, [])
- actor.addQuest(Quest(actor, qname, qtext))
+ questdict = modelsettings.get(npc, 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)
+
+ actor.addQuest(quest)
elif modeldict["type"] == "NPC":
actor = Actor(self._gamecontroller, modeldict["model"], npc, True)
@@ -176,7 +184,14 @@
location = fife.Location(self._actorlayer)
location.setMapCoordinates(target_mapcoord)
return location
-
+
+ def addObjectToScene(self, obj):
+ self._objectlist[obj.id] = obj
+
+ def removeObjectFromScene(self, obj):
+ obj.destroy()
+ del self._objectlist[obj.id]
+
def updateScene(self):
pass