annotate demos/rpg/scripts/quests/basequest.py @ 575:872a7a94563e

- Updated the soundmanager extension to reflect changes made in last commit. - Made actor walk speed part of the ActorAttributes class. - The ActorAttributes class now gets serialized correctly.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 02 Jul 2010 14:41:27 +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
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 import sys, os, re, math, random, shutil, time
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 from datetime import datetime
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
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
31 QuestTypes = {'DEFAULT':0,
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
32 'RETURN_ITEM':1}
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
33
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 class Quest(object):
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: 542
diff changeset
35 def __init__(self, ownerid, questid, questtitle, questtext):
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: 542
diff changeset
36 self._ownerid = ownerid
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: 542
diff changeset
37 self._questid = questid
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: 542
diff changeset
38 self._name = questtitle
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 self._text = questtext
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
40 self._complete_dialog = "That everything I need. Thank you!"
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
41 self._incomplete_dialog = "Come back when you have all the items I requested!"
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
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: 542
diff changeset
43 def __eq__(self, other):
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: 542
diff changeset
44 return self._questid == other.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: 542
diff changeset
45
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
46 def checkQuestCompleted(self, actor):
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
47 pass
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
48
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: 542
diff changeset
49 def _getOwnerID(self):
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: 542
diff changeset
50 return self._ownerid
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
51
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
52 def _getName(self):
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
53 return self._name
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
54
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: 542
diff changeset
55 def _setName(self, questtitle):
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: 542
diff changeset
56 self._name = questtitle
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
57
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
58 def _getText(self):
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
59 return self._text
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
60
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
61 def _setText(self, questtext):
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
62 self._text = questtext
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
63
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: 542
diff changeset
64 def _getID(self):
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: 542
diff changeset
65 return self._questid
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: 542
diff changeset
66
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: 542
diff changeset
67 ownerid = property(_getOwnerID)
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
68 name = property(_getName, _setName)
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
69 text = property(_getText, _setText)
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: 542
diff changeset
70 id = property(_getID)
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
71
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
72 class ReturnItemQuest(Quest):
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: 542
diff changeset
73 def __init__(self, ownerid, questid, questtitle, questtext):
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: 542
diff changeset
74 super(ReturnItemQuest, self).__init__(ownerid, questid, questtitle, questtext)
542
67f6f3538e88 Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
75
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 self._requireditems = []
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 self._requiredgold = 0
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 def addRequiredItem(self, itemid):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 self._requireditems.append(itemid)
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 addRequiredGold(self, goldcount):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 self._requiredgold += goldcount
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 def checkQuestCompleted(self, actor):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 completed = False
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 if self._requiredgold > 0:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 if actor.gold >= self._requiredgold:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 completed = True
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 for item in self._requireditems:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 if item in actor.inventory:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 completed = True
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 return completed
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 def _getRequiredGold(self):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 return self._requiredgold
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 def _getRequiredItems(self):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 return self._requireditems
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 requiredgold = property(_getRequiredGold)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 requireditems = property(_getRequiredItems)