annotate demos/rpg/scripts/actors/questgiver.py @ 589:d1df6cf5ff23

* Fixed a bug in RenderBackendSDL, the clip area was not properly set. * Renamed the backquad and border commands of the FloatingTextRenderer. * Added the TransparentArea commands to the InstanceRenderer. Note: with addTransparentArea(instance, string, width, height, transparent, front) you can enable an area, that make all instances in this zone and with the same namespace transparent. The string is for the namespace, so you can set one or more namespaces to be transparent. Width and height specifies the size of the area. Transparent defines the intensity of transparency, 255 = invisible. The bool front, enable or disable the z check, so that only instances in front of the source instance could be transparent.
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 13 Aug 2010 16:33:36 +0000
parents 69d50e751c9a
children
rev   line source
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #!/usr/bin/env python
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # -*- coding: utf-8 -*-
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # ####################################################################
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # Copyright (C) 2005-2010 by the FIFE team
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 # http://www.fifengine.net
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # This file is part of FIFE.
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 #
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # FIFE is free software; you can redistribute it and/or
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # modify it under the terms of the GNU Lesser General Public
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 # License as published by the Free Software Foundation; either
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # version 2.1 of the License, or (at your option) any later version.
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 #
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # This library is distributed in the hope that it will be useful,
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # Lesser General Public License for more details.
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 #
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # You should have received a copy of the GNU Lesser General Public
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # License along with this library; if not, write to the
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # Free Software Foundation, Inc.,
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 # ####################################################################
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 # This is the rio de hola client for FIFE.
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 import sys, os, re, math, random, shutil
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 from fife import fife
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 from scripts.objects.baseobject import BaseGameObject, GameObjectTypes
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 from scripts.actors.baseactor import Actor
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 class QuestGiver(Actor):
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
35 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
36 super(QuestGiver, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance)
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
37 self._type = GameObjectTypes["QUESTGIVER"]
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
38
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
39 self._noquest_dialog = "I've got nothing for you... leave me alone."
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 def offerNextQuest(self):
551
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
42 """
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
43 Brings up the quest dialog of there is a quest to be offered to the player.
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
44 """
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
45 if self._gamecontroller.questmanager.getNextQuest(self.id):
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 self._gamecontroller.guicontroller.showQuestDialog(self)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 def getNextQuest(self):
551
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
49 """
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
50 Returns the next quest that will be offered by this QuestGiver.
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
51 """
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
52 return self._gamecontroller.questmanager.getNextQuest(self.id)
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 def activateQuest(self, quest):
551
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
55 """
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
56 This is called after the player accepts a quest. It marks it as active or "in progress".
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
57 """
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
58 self._gamecontroller.questmanager.activateQuest(quest)
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
59
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
60 def showNoQuestDialog(self):
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
61 self.say(self._noquest_dialog)
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
62
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 def completeQuest(self):
551
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
64 """
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
65 Checks to see if the active quest owned by this QuestGiver is complete and
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
66 removes the required items or gold from the players inventory.
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
67 """
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
68 for activequest in self._gamecontroller.questmanager.activequests:
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
69 if activequest.ownerid == self.id:
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
70 if activequest.checkQuestCompleted(self._gamecontroller.scene.player):
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
71 self.say(activequest._complete_dialog)
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
72
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
73 self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - activequest.requiredgold
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
75 for itemid in activequest.requireditems:
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
76 self._gamecontroller.scene.player.removeItemFromInventory(itemid)
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
77
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
78 self._gamecontroller.questmanager.completeQuest(activequest)
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
79 else:
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
80 self.say(activequest._incomplete_dialog)
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 def haveQuest(self):
551
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
83 """
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
84 Returns True if there is either an active quest or the QuestGiver has a new quest to give
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
85 the player. Returns False otherwise.
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
86 """
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
87 return bool(self._gamecontroller.questmanager.getNextQuest(self.id)) or bool(self._getActiveQuest())
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
88
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
89 def serialize(self):
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
90 lvars = super(QuestGiver, self).serialize()
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
91
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
92 lvars['noquest_dialog'] = self._noquest_dialog
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
93
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
94 return lvars
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
95
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
96 def deserialize(self, valuedict):
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
97 super(QuestGiver, self).deserialize(valuedict)
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
98
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
99 self._noquest_dialog = valuedict['noquest_dialog']
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
100
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 def _getActiveQuest(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
103 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
104 Returns the first active quest in the list. There should only be one
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
105 active quest per questgiver anyway.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
106 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
107 for quest in self._gamecontroller.questmanager.activequests:
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
108 if quest.ownerid == self.id:
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
109 return quest
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 activequest = property(_getActiveQuest)