comparison src/parpg/dialogueactions.py @ 170:371b17bc9113

Added ReplaceItemAction, to dialogueactions, which replaces a single item in the players inventory.
author KarstenBock@gmx.net
date Sun, 09 Oct 2011 14:39:02 +0200
parents bb0e09112a1f
children 191f89a22303
comparison
equal deleted inserted replaced
169:87073af1d2d2 170:371b17bc9113
151 item_types = self.item_types 151 item_types = self.item_types
152 for item_type in item_types: 152 for item_type in item_types:
153 item = container.take_item(game_state['npc'].container, item_type) 153 item = container.take_item(game_state['npc'].container, item_type)
154 if (item): 154 if (item):
155 container.put_item(game_state['pc'].container, item) 155 container.put_item(game_state['pc'].container, item)
156 print("{0} gave you the {1}".format(game_state['npc'].description.view_name, 156 print("{0} gave you the {1}".format(game_state['npc'].
157 description.view_name,
157 item_type)) 158 item_type))
158 else: 159 else:
159 print("{0} doesn't have the {1}".format(game_state['npc']. 160 print("{0} doesn't have the {1}".format(game_state['npc'].
160 description.view_name, 161 description.view_name,
161 item_type)) 162 item_type))
188 else: 189 else:
189 print("You don't have the {0}".format(item_type)) 190 print("You don't have the {0}".format(item_type))
190 DialogueAction.registerAction(GiveStuffAction) 191 DialogueAction.registerAction(GiveStuffAction)
191 192
192 193
194 class ReplaceItemAction(InventoryAction):
195 """
196 L{InventoryAction} used to replace an item with another in the player's
197 inventory.
198 """
199
200 keyword = 'replace_item'
201
202 def __call__(self, game_state):
203 """
204 Take an item from the player and place another at its place.
205
206 @param game_state: variables and functions that make up the current
207 game state.
208 @type game_state: dict of objects
209 """
210 old_type = self.item_types[0]
211 new_type = self.item_types[1]
212 item = container.take_item(game_state['pc'].container, old_type)
213 if item:
214 model = game_state['model']
215 new_item = model.createItemByType(new_type, new_type,
216 item.entity.world)
217 container.put_item(game_state['pc'].container,
218 new_item.containable, item.slot)
219 model.deleteObject(item.entity.general.identifier)
220 item.delete()
221 print("{0} took the {1} and gave you the {2}".format(
222 game_state['npc'].description.view_name, old_type, item_type))
223 else:
224 print("You don't have the {0}".format(old_type))
225 DialogueAction.registerAction(ReplaceItemAction)
226
193 class QuestAction(DialogueAction): 227 class QuestAction(DialogueAction):
194 """ 228 """
195 Abstract base class for quest-related L{DialogueActions<DialogueAction>}. 229 Abstract base class for quest-related L{DialogueActions<DialogueAction>}.
196 """ 230 """
197 def __init__(self, *args, **kwargs): 231 def __init__(self, *args, **kwargs):