annotate demos/rpg/scripts/objects/items.py @ 540:2e739ae9a8bc

Some misc code cleanup. Added the EnterPortalAction action. You can now move between town and level1.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 01 Jun 2010 19:17:30 +0000
parents d0bce896a526
children cb7ec12214a9
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):
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
35 def __init__(self, gamecontroller, objtype, itemtype, itemname):
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
36 super(BaseItem, self).__init__(gamecontroller, objtype, itemtype, itemname, True)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
38 def onLeftClick(self):
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
39 #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
40 self._gamecontroller.scene.removeObjectFromScene(self)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 def onDrop(self, dropx, dropy):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 #recreate object
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 520
diff changeset
44 self._createFIFEInstance(self, self._gamecontroller.scene.itemlayer)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 self.setMapPosition(dropx, dropy)
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
47 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
48
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 def _getItemType(self):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 return self._name
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 def _getItemName(self):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 return self._id
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 itemtype = property(_getItemType)
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 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
57
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 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
59 def __init__(self, gamecontroller, itemtype, itemname):
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
60 super(GoldStack, self).__init__(gamecontroller, GameObjectTypes["ITEM"], itemtype, itemname)
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
61
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 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
63
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 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
65 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
66
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 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
68 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
69
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 value = property(_getValue, _setValue)
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
71
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
72 class Portal(BaseItem):
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
73 def __init__(self, gamecontroller, itemtype, itemname):
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
74 super(Portal, self).__init__(gamecontroller, GameObjectTypes["PORTAL"], itemtype, itemname)
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
75
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
76 self._dest = None
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
77
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
78 def onLeftClick(self):
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
79 pass
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
80
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
81 def _getDest(self):
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
82 return self._dest
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
83
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
84 def _setDest(self, dest):
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
85 self._dest = dest
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
86
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 529
diff changeset
87 dest = property(_getDest, _setDest)