Mercurial > fife-parpg
annotate demos/rpg/scripts/actors/questgiver.py @ 551:3b933753cba8
QuestManager now loads all quests.
Added some more comments.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 15 Jun 2010 21:13:01 +0000 |
parents | d0282579668c |
children | 69d50e751c9a |
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"] |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 def offerNextQuest(self): |
551
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
40 """ |
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
41 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
|
42 """ |
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
|
43 if self._gamecontroller.questmanager.getNextQuest(self.id): |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 self._gamecontroller.guicontroller.showQuestDialog(self) |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 def getNextQuest(self): |
551
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
47 """ |
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
48 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
|
49 """ |
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
|
50 return self._gamecontroller.questmanager.getNextQuest(self.id) |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 def activateQuest(self, quest): |
551
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
53 """ |
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
54 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
|
55 """ |
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
|
56 self._gamecontroller.questmanager.activateQuest(quest) |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 def completeQuest(self): |
551
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
59 """ |
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
60 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
|
61 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
|
62 """ |
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
|
63 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
|
64 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
|
65 if activequest.checkQuestCompleted(self._gamecontroller.scene.player): |
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
|
66 self.say("That everything I need. Thank you!") |
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
|
67 |
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 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
|
69 |
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
|
70 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
|
71 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
|
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.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
|
74 else: |
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 self.say("Come back when you have all the items I requested!") |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 def haveQuest(self): |
551
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
78 """ |
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
79 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
|
80 the player. Returns False otherwise. |
3b933753cba8
QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
550
diff
changeset
|
81 """ |
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
|
82 return bool(self._gamecontroller.questmanager.getNextQuest(self.id)) or bool(self._getActiveQuest()) |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 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
|
85 """ |
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
|
86 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
|
87 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
|
88 """ |
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
|
89 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
|
90 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
|
91 return quest |
534
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 |
65a92a2449d5
Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 activequest = property(_getActiveQuest) |