Mercurial > fife-parpg
comparison demos/rpg/scripts/actors/baseactor.py @ 560:69d50e751c9a
Lots of changes.
- Added the Serializer class
- Made exceptions a little more usable
- Added actor attributes (not used yet but will be with the combat engine)
- Made the quest dialogs more customizable
- Many other small changes
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 23 Jun 2010 19:20:24 +0000 |
parents | e59ece21ab3e |
children | f85762e634c5 |
comparison
equal
deleted
inserted
replaced
559:cccff9b04f57 | 560:69d50e751c9a |
---|---|
20 # You should have received a copy of the GNU Lesser General Public | 20 # You should have received a copy of the GNU Lesser General Public |
21 # License along with this library; if not, write to the | 21 # License along with this library; if not, write to the |
22 # Free Software Foundation, Inc., | 22 # Free Software Foundation, Inc., |
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 # #################################################################### | 24 # #################################################################### |
25 # This is the rio de hola client for FIFE. | |
26 | 25 |
27 import sys, os, re, math, random, shutil | 26 import sys, os, re, math, random, shutil |
28 | 27 |
29 from fife import fife | 28 from fife import fife |
30 from fife.extensions.loaders import loadMapFile | 29 from fife.extensions.loaders import loadMapFile |
31 | 30 |
32 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes | 31 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes |
33 from scripts.objects.items import GoldStack | 32 from scripts.objects.items import GoldStack |
33 from scripts.misc.serializer import Serializer | |
34 | 34 |
35 Actions = {'NONE':0, | 35 Actions = {'NONE':0, |
36 'PICKUP':1, | 36 'PICKUP':1, |
37 'TALK':2, | 37 'TALK':2, |
38 'ATTACK':3, | 38 'ATTACK':3, |
58 if not self._dest.activequest: | 58 if not self._dest.activequest: |
59 self._dest.offerNextQuest() | 59 self._dest.offerNextQuest() |
60 else: | 60 else: |
61 self._dest.completeQuest() | 61 self._dest.completeQuest() |
62 else: | 62 else: |
63 self._dest.say("I've got nothing for you... leave me alone.") | 63 self._dest.showNoQuestDialog() |
64 else: | 64 else: |
65 self._dest.instance.say("Hello there!") | 65 self._dest.instance.say("Hello there!") |
66 | 66 |
67 class PickUpItemAction(BaseAction): | 67 class PickUpItemAction(BaseAction): |
68 def __init__(self, actor, item): | 68 def __init__(self, actor, item): |
93 def onInstanceActionFinished(self, instance, action): | 93 def onInstanceActionFinished(self, instance, action): |
94 if action.getId() == 'walk': | 94 if action.getId() == 'walk': |
95 self._object.stand() | 95 self._object.stand() |
96 self._object.performNextAction() | 96 self._object.performNextAction() |
97 | 97 |
98 class ActorAttributes(Serializer): | |
99 def __init__(self, strength=0, dexterity=0, intelligence=0, health=0): | |
100 self._str = strength | |
101 self._dex = dexterity | |
102 self._int = intelligence | |
103 self._hp = health | |
104 | |
105 def serialize(self): | |
106 lvars['str'] = self._str | |
107 lvars['dex'] = self._dex | |
108 lvars['int'] = self._int | |
109 lvars['hp'] = self._hp | |
110 | |
111 return lvars | |
112 | |
113 def deserialize(self, valuedict): | |
114 if valuedict.has_key("str"): | |
115 self._str = int(valuedict['str']) | |
116 if valuedict.has_key("dex"): | |
117 self._dex = int(valuedict['dex']) | |
118 if valuedict.has_key("int"): | |
119 self._int = int(valuedict['int']) | |
120 if valuedict.has_key("hp"): | |
121 self._hp = int(valuedict['hp']) | |
122 | |
123 def _getStrength(self): | |
124 return self._str | |
125 | |
126 def _setStrength(self, strength): | |
127 self._str = strength | |
128 | |
129 def _getDexterity(self): | |
130 return self._dexterity | |
131 | |
132 def _setDexterity(self, dexterity): | |
133 self._dexterity = dexterity | |
134 | |
135 def _getIntelligence(self): | |
136 return self._int | |
137 | |
138 def _setIntelligence(self, intelligence): | |
139 self._int = intelligence | |
140 | |
141 def _getHealth(self): | |
142 return self._hp | |
143 | |
144 def _setHealth(self, health): | |
145 self._hp = health | |
146 | |
147 | |
148 strength = property(_getStrength, _setStrength) | |
149 dexterity = property(_getDexterity, _setDexterity) | |
150 intelligence = property(_getIntelligence, _setIntelligence) | |
151 health = property(_getHealth, _setHealth) | |
152 | |
153 | |
98 class Actor(BaseGameObject): | 154 class Actor(BaseGameObject): |
99 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): | 155 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): |
100 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) | 156 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) |
101 | 157 |
102 self._type = GameObjectTypes["DEFAULT"] | 158 self._type = GameObjectTypes["DEFAULT"] |
103 | 159 |
104 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) | |
105 | |
106 self._nextaction = None | 160 self._nextaction = None |
107 self._inventory = [] | 161 self._inventory = [] |
108 self._maxinventoryitems = 20 | 162 self._maxinventoryitems = 20 |
163 | |
164 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) | |
109 | 165 |
110 self._gold = 0 | 166 self._gold = 0 |
167 self._attributes = ActorAttributes() | |
111 | 168 |
112 self.stand() | 169 self.stand() |
113 | 170 |
114 def stand(self): | 171 def stand(self): |
115 self._state = ActorStates["STAND"] | 172 self._state = ActorStates["STAND"] |
126 if self._nextaction: | 183 if self._nextaction: |
127 self._nextaction.execute() | 184 self._nextaction.execute() |
128 self._nextaction = None | 185 self._nextaction = None |
129 | 186 |
130 def pickUpItem(self, item): | 187 def pickUpItem(self, item): |
188 if self.addItemToInventory(item): | |
189 item.onPickUp() | |
190 else: | |
191 #could do something cool like throw the item back on the ground | |
192 pass | |
193 | |
194 def enterPortal(self, portal): | |
195 if self._id == "player": | |
196 self._gamecontroller.switchMap(portal.dest) | |
197 else: | |
198 self._gamecontroller.scene.removeObjectFromScene(self._id) | |
199 | |
200 def addItemToInventory(self, item): | |
131 if len(self._inventory) >= self._maxinventoryitems: | 201 if len(self._inventory) >= self._maxinventoryitems: |
132 return | 202 return False |
133 else: | 203 else: |
134 if type(item) == GoldStack: | 204 if type(item) == GoldStack: |
135 self._gold += item.value | 205 self._gold += item.value |
136 else: | 206 else: |
137 self._inventory.append(item) | 207 self._inventory.append(item) |
138 | 208 |
139 item.onPickUp() | 209 return True |
140 | |
141 def enterPortal(self, portal): | |
142 if self._id == "player": | |
143 self._gamecontroller.switchMap(portal.dest) | |
144 else: | |
145 self._gamecontroller.scene.removeObjectFromScene(self._id) | |
146 | 210 |
147 def removeItemFromInventory(self, itemid): | 211 def removeItemFromInventory(self, itemid): |
148 itemtoremove = None | 212 itemtoremove = None |
149 for item in self._inventory: | 213 for item in self._inventory: |
150 if item.id == itemid: | 214 if item.id == itemid: |
165 | 229 |
166 if valuedict.has_key("gold"): | 230 if valuedict.has_key("gold"): |
167 self._gold = int(valuedict['gold']) | 231 self._gold = int(valuedict['gold']) |
168 else: | 232 else: |
169 self._gold = 0 | 233 self._gold = 0 |
234 | |
235 if valuedict.has_key("walk_speed"): | |
236 self._walkspeed = float(valuedict['walk_speed']) | |
170 | 237 |
171 def _getState(self): | 238 def _getState(self): |
172 return self._state | 239 return self._state |
173 | 240 |
174 def _setState(self, state): | 241 def _setState(self, state): |
186 def _setGold(self, gold): | 253 def _setGold(self, gold): |
187 self._gold = gold | 254 self._gold = gold |
188 | 255 |
189 def _getInventory(self): | 256 def _getInventory(self): |
190 return self._inventory | 257 return self._inventory |
258 | |
259 def _getAttributes(self): | |
260 return self._attributes | |
191 | 261 |
192 state = property(_getState, _setState) | 262 state = property(_getState, _setState) |
193 nextaction = property(_getNextAction, _setNextAction) | 263 nextaction = property(_getNextAction, _setNextAction) |
194 gold = property(_getGold, _setGold) | 264 gold = property(_getGold, _setGold) |
195 inventory = property(_getInventory) | 265 inventory = property(_getInventory) |
266 attributes = property(_getAttributes) |