annotate demos/rpg/scripts/objects/items.py @ 529:d0bce896a526

Changed the quest format in the object xml file. Quests can now required gold or items to complete.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 28 May 2010 16:25:00 +0000
parents 19db5a8619a4
children 2e739ae9a8bc
rev   line source
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #!/usr/bin/env python
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # -*- coding: utf-8 -*-
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # ####################################################################
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # Copyright (C) 2005-2010 by the FIFE team
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 # http://www.fifengine.net
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # This file is part of FIFE.
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 #
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # FIFE is free software; you can redistribute it and/or
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # modify it under the terms of the GNU Lesser General Public
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 # License as published by the Free Software Foundation; either
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # version 2.1 of the License, or (at your option) any later version.
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 #
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # This library is distributed in the hope that it will be useful,
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # Lesser General Public License for more details.
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 #
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # You should have received a copy of the GNU Lesser General Public
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # License along with this library; if not, write to the
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # Free Software Foundation, Inc.,
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 # ####################################################################
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 # This is the rio de hola client for FIFE.
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 import sys, os, re, math, random, shutil
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 from fife import fife
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 from scripts.objects.baseobject import BaseGameObject, GameObjectTypes
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 class BaseItem(BaseGameObject):
525
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
35 def __init__(self, gamecontroller, itemtype, itemname):
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 self._type = GameObjectTypes["ITEM"]
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 520
diff changeset
37 super(BaseItem, self).__init__(gamecontroller, itemtype, itemname, True)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 def onPickUp(self):
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
40 #remove item from the scene
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
41 self._gamecontroller.scene.removeObjectFromScene(self)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 def onDrop(self, dropx, dropy):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 #recreate object
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 520
diff changeset
45 self._createFIFEInstance(self, self._gamecontroller.scene.itemlayer)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 self.setMapPosition(dropx, dropy)
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
48 self._gamecontroller.scene.addObjectToScene(self)
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
49
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 def _getItemType(self):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 return self._name
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 def _getItemName(self):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 return self._id
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 itemtype = property(_getItemType)
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 itemname = property(_getItemName)
525
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
58
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
59 class GoldStack(BaseItem):
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
60 def __init__(self, gamecontroller, itemtype, itemname):
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
61 super(GoldStack, self).__init__(gamecontroller, itemtype, itemname)
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
62
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
63 self._value = 0
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
64
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
65 def _getValue(self):
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
66 return self._value
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
67
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
68 def _setValue(self, value):
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
69 self._value = int(value)
525
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
70
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
71 value = property(_getValue, _setValue)