Mercurial > fife-parpg
comparison demos/rpg/scripts/actors/baseactor.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 | 796d49ab9380 |
children | 65a92a2449d5 |
comparison
equal
deleted
inserted
replaced
528:796d49ab9380 | 529:d0bce896a526 |
---|---|
59 if not self._dest.activequest: | 59 if not self._dest.activequest: |
60 self._dest.offerNextQuest() | 60 self._dest.offerNextQuest() |
61 else: | 61 else: |
62 self._dest.completeQuest() | 62 self._dest.completeQuest() |
63 else: | 63 else: |
64 self._dest.instance.say("I've got nothing for you... leave me alone.", 2500) | 64 self._dest.say("I've got nothing for you... leave me alone.") |
65 else: | 65 else: |
66 self._dest.instance.say("Hello there!") | 66 self._dest.instance.say("Hello there!") |
67 | 67 |
68 class PickUpItemAction(BaseAction): | 68 class PickUpItemAction(BaseAction): |
69 def __init__(self, actor, item): | 69 def __init__(self, actor, item): |
98 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) | 98 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) |
99 | 99 |
100 self._actionlistener = ActorActionListener(self._gamecontroller, self) | 100 self._actionlistener = ActorActionListener(self._gamecontroller, self) |
101 | 101 |
102 self._nextaction = None | 102 self._nextaction = None |
103 self._inventory = [] | |
104 self._maxinventoryitems = 20 | |
105 | |
106 self._gold = 0 | |
103 | 107 |
104 self.stand() | 108 self.stand() |
105 | 109 |
106 def stand(self): | 110 def stand(self): |
107 self._state = ActorStates["STAND"] | 111 self._state = ActorStates["STAND"] |
108 self._instance.act('stand', self._instance.getFacingLocation()) | 112 self._instance.act('stand', self._instance.getFacingLocation()) |
109 | 113 |
110 def walk(self, location): | 114 def walk(self, location): |
111 self._state = ActorStates["WALK"] | 115 self._state = ActorStates["WALK"] |
112 self._instance.move('walk', location, self._walkspeed) | 116 self._instance.move('walk', location, self._walkspeed) |
117 | |
118 def say(self, text): | |
119 self._instance.say(text, 2500) | |
113 | 120 |
114 def performNextAction(self): | 121 def performNextAction(self): |
115 if self._nextaction: | 122 if self._nextaction: |
116 self._nextaction.execute() | 123 self._nextaction.execute() |
117 self._nextaction = None | 124 self._nextaction = None |
118 | 125 |
119 def pickUpItem(self, item): | 126 def pickUpItem(self, item): |
120 self._inventory.append(item) | 127 if len(self._inventory) >= self._maxinventoryitems: |
121 | 128 return |
122 #removes it from FIFE (to stop rendering the item) | 129 else: |
123 item.destroy() | 130 if item.modelname == "goldstack": |
124 | 131 self._gold += item.value |
125 #remove it from the scene | 132 else: |
126 del self._gamecontroller.scene.objectlist[item.id] | 133 self._inventory.append(item) |
134 | |
135 item.onPickUp() | |
136 | |
137 def removeItemFromInventory(self, itemid): | |
138 itemtoremove = None | |
139 for item in self._inventory: | |
140 if item.id == itemid: | |
141 itemtoremove = item | |
142 | |
143 if itemtoremove: | |
144 self._inventory.remove(itemtoremove) | |
145 | |
127 | 146 |
128 def _getState(self): | 147 def _getState(self): |
129 return self._state | 148 return self._state |
130 | 149 |
131 def _setState(self, state): | 150 def _setState(self, state): |
135 return self._nextaction | 154 return self._nextaction |
136 | 155 |
137 def _setNextAction(self, action): | 156 def _setNextAction(self, action): |
138 self._nextaction = action | 157 self._nextaction = action |
139 | 158 |
159 def _getGold(self): | |
160 return self._gold | |
161 | |
162 def _setGold(self, gold): | |
163 self._gold = gold | |
164 | |
165 def _getInventory(self): | |
166 return self._inventory | |
167 | |
140 state = property(_getState, _setState) | 168 state = property(_getState, _setState) |
141 nextaction = property(_getNextAction, _setNextAction) | 169 nextaction = property(_getNextAction, _setNextAction) |
170 gold = property(_getGold, _setGold) | |
171 inventory = property(_getInventory) | |
142 | 172 |
143 class Quest(object): | 173 class Quest(object): |
144 def __init__(self, owner, questname, questtext): | 174 def __init__(self, owner, questname, questtext): |
145 self._owner = owner | 175 self._owner = owner |
146 self._name = questname | 176 self._name = questname |
147 self._text = questtext | 177 self._text = questtext |
178 self._requireditems = [] | |
179 self._requiredgold = 0 | |
180 | |
181 def addRequiredItem(self, itemid): | |
182 self._requireditems.append(itemid) | |
183 | |
184 def addRequiredGold(self, goldcount): | |
185 self._requiredgold += goldcount | |
186 | |
187 def checkQuestCompleted(self, actor): | |
188 completed = False | |
189 | |
190 if self._requiredgold > 0: | |
191 if actor.gold >= self._requiredgold: | |
192 completed = True | |
193 | |
194 for item in self._requireditems: | |
195 if item in actor.inventory: | |
196 completed = True | |
197 | |
198 return completed | |
148 | 199 |
149 def _getOwner(self): | 200 def _getOwner(self): |
150 return self._owner | 201 return self._owner |
151 | 202 |
152 def _getName(self): | 203 def _getName(self): |
158 def _getText(self): | 209 def _getText(self): |
159 return self._text | 210 return self._text |
160 | 211 |
161 def _setText(self, questtext): | 212 def _setText(self, questtext): |
162 self._text = questtext | 213 self._text = questtext |
214 | |
215 def _getRequiredGold(self): | |
216 return self._requiredgold | |
217 | |
218 def _getRequiredItems(self): | |
219 return self._requireditems | |
163 | 220 |
164 owner = property(_getOwner) | 221 owner = property(_getOwner) |
165 name = property(_getName, _setName) | 222 name = property(_getName, _setName) |
166 text = property(_getText, _setText) | 223 text = property(_getText, _setText) |
224 requiredgold = property(_getRequiredGold) | |
225 requireditems = property(_getRequiredItems) | |
167 | 226 |
168 class QuestGiver(Actor): | 227 class QuestGiver(Actor): |
169 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): | 228 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): |
170 self._type = GameObjectTypes["QUESTGIVER"] | 229 self._type = GameObjectTypes["QUESTGIVER"] |
171 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance) | 230 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance) |
192 | 251 |
193 def activateQuest(self, quest): | 252 def activateQuest(self, quest): |
194 self._activequest = quest | 253 self._activequest = quest |
195 | 254 |
196 def completeQuest(self): | 255 def completeQuest(self): |
197 #@todo check to see if requirements are met | |
198 if self._activequest in self._quests: | 256 if self._activequest in self._quests: |
199 print "quest completed" | 257 if self._activequest.checkQuestCompleted(self._gamecontroller.scene.player): |
200 self._quests.remove(self._activequest) | 258 self.say("That everything I need. Thank you!") |
201 self._activequest = None | 259 self._gamecontroller.scene.player.gold = self._gamecontroller.scene.player.gold - self._activequest.requiredgold |
260 | |
261 for itemid in self._activequest.requireditems: | |
262 self._gamecontroller.scene.player.removeItemFromInventory(itemid) | |
263 | |
264 self._quests.remove(self._activequest) | |
265 self._activequest = None | |
266 else: | |
267 self.say("Come back when you have all the items I requested!") | |
202 else: | 268 else: |
203 #something went wrong | 269 #something went wrong |
204 self._activequest = None | 270 self._activequest = None |
205 | 271 |
206 def haveQuest(self): | 272 def haveQuest(self): |