annotate demos/rpg/scripts/quests/basequest.py @ 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. Started adding more comments.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 15 Jun 2010 17:53:20 +0000
parents 67f6f3538e88
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, time
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 from datetime import datetime
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 from fife import fife
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31
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
32 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
33 '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
34
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 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
36 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
37 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
38 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
39 self._name = questtitle
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 self._text = 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
41
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
42 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
43 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
44
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
45 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
46 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
47
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
48 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
49 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
50
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 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
52 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
53
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
54 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
55 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
56
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 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
58 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
59
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 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
61 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
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: 542
diff changeset
63 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
64 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
65
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 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
67 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
68 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
69 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
70
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 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
72 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
73 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
74
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 self._requireditems = []
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 self._requiredgold = 0
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 def addRequiredItem(self, itemid):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 self._requireditems.append(itemid)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 def addRequiredGold(self, goldcount):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 self._requiredgold += goldcount
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 checkQuestCompleted(self, actor):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 completed = False
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 if self._requiredgold > 0:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 if actor.gold >= self._requiredgold:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 completed = True
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 for item in self._requireditems:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 if item in actor.inventory:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 completed = True
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 return completed
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 def _getRequiredGold(self):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 return self._requiredgold
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 def _getRequiredItems(self):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 return self._requireditems
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 requiredgold = property(_getRequiredGold)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 requireditems = property(_getRequiredItems)