Mercurial > parpg-core
comparison src/parpg/dialogueactions.py @ 109:bb0e09112a1f
take_stuff and give_stuff in dialogues work again.
author | KarstenBock@gmx.net |
---|---|
date | Fri, 23 Sep 2011 13:35:44 +0200 |
parents | 2e307c4f78e3 |
children | 371b17bc9113 |
comparison
equal
deleted
inserted
replaced
108:2f928c913c78 | 109:bb0e09112a1f |
---|---|
16 Provides classes used to implement dialogue logic and allow dialogues to have | 16 Provides classes used to implement dialogue logic and allow dialogues to have |
17 external effects on the game state. | 17 external effects on the game state. |
18 """ | 18 """ |
19 import logging | 19 import logging |
20 | 20 |
21 from parpg.components import container | |
22 | |
21 logger = logging.getLogger('dialogueaction') | 23 logger = logging.getLogger('dialogueaction') |
22 | 24 |
23 class DialogueAction(object): | 25 class DialogueAction(object): |
24 """ | 26 """ |
25 Abstract base class for subclasses that represent dialogue actions embedded | 27 Abstract base class for subclasses that represent dialogue actions embedded |
145 @param game_state: variables and functions that make up the current | 147 @param game_state: variables and functions that make up the current |
146 game state. | 148 game state. |
147 @type game_state: dict of objects | 149 @type game_state: dict of objects |
148 """ | 150 """ |
149 item_types = self.item_types | 151 item_types = self.item_types |
150 for item_type in item_types: | 152 for item_type in item_types: |
151 item = game_state['npc'].inventory.findItem(item_type=item_type) | 153 item = container.take_item(game_state['npc'].container, item_type) |
152 if (item): | 154 if (item): |
153 game_state['npc'].give(item, game_state['pc']) | 155 container.put_item(game_state['pc'].container, item) |
154 print("{0} gave you the {1}".format(game_state['npc'].name, | 156 print("{0} gave you the {1}".format(game_state['npc'].description.view_name, |
155 item_type)) | 157 item_type)) |
156 else: | 158 else: |
157 print("{0} doesn't have the {1}".format(game_state['npc'].name, | 159 print("{0} doesn't have the {1}".format(game_state['npc']. |
160 description.view_name, | |
158 item_type)) | 161 item_type)) |
159 DialogueAction.registerAction(TakeStuffAction) | 162 DialogueAction.registerAction(TakeStuffAction) |
160 | 163 |
161 | 164 |
162 class GiveStuffAction(InventoryAction): | 165 class GiveStuffAction(InventoryAction): |
174 game state. | 177 game state. |
175 @type game_state: dict of objects | 178 @type game_state: dict of objects |
176 """ | 179 """ |
177 item_types = self.item_types | 180 item_types = self.item_types |
178 for item_type in item_types: | 181 for item_type in item_types: |
179 item = game_state['npc'].inventory.findItem(item_type = item_type) | 182 item = container.take_item(game_state['pc'].container, item_type) |
180 if (item): | 183 if (item): |
181 game_state['pc'].give(item, game_state['npc']) | 184 container.put_item(game_state['npc'].container, item) |
182 print("You give the {0} to {1}".format(item_type, | 185 print("You give the {0} to {1}".format(item_type, |
183 game_state['npc'].name)) | 186 game_state['npc']. |
187 description.view_name)) | |
184 else: | 188 else: |
185 print("You don't have the {0}".format(item_type)) | 189 print("You don't have the {0}".format(item_type)) |
186 DialogueAction.registerAction(GiveStuffAction) | 190 DialogueAction.registerAction(GiveStuffAction) |
187 | 191 |
188 | 192 |