annotate demos/rpg/scripts/quests/basequest.py @ 542:67f6f3538e88

Refactored the Quest class a bit. Made it a base class for other possible quest types. Added the RETURN_ITEM quest type.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 01 Jun 2010 21:38:14 +0000
parents 2e739ae9a8bc
children d0282579668c
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):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 def __init__(self, owner, questname, questtext):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 self._owner = owner
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 self._name = questname
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 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
40
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 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
42 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
43
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
44 def _getOwner(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
45 return self._owner
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
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 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
48 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
49
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 def _setName(self, questname):
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 self._name = questname
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
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 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
54 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
55
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 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
57 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
58
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 owner = property(_getOwner)
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 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
61 text = property(_getText, _setText)
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
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 class ReturnItemQuest(Quest):
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
64 def __init__(self, owner, questname, 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
65 super(ReturnItemQuest, self).__init__(owner, questname, 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
66
534
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 self._requireditems = []
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 self._requiredgold = 0
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 def addRequiredItem(self, itemid):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 self._requireditems.append(itemid)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 def addRequiredGold(self, goldcount):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 self._requiredgold += goldcount
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 def checkQuestCompleted(self, actor):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 completed = False
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 if self._requiredgold > 0:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 if actor.gold >= self._requiredgold:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 completed = True
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 for item in self._requireditems:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 if item in actor.inventory:
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 completed = True
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 return completed
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 def _getRequiredGold(self):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 return self._requiredgold
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 def _getRequiredItems(self):
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 return self._requireditems
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 requiredgold = property(_getRequiredGold)
65a92a2449d5 Doing some re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 requireditems = property(_getRequiredItems)