diff src/parpg/objects/action.py @ 164:ede6f6b31bf8

Changed BrewBeerAction to work with components.
author KarstenBock@gmx.net
date Sat, 08 Oct 2011 14:19:35 +0200
parents 9ba129380af8
children 7f044776de60
line wrap: on
line diff
--- a/src/parpg/objects/action.py	Sat Oct 08 14:19:11 2011 +0200
+++ b/src/parpg/objects/action.py	Sat Oct 08 14:19:35 2011 +0200
@@ -457,7 +457,7 @@
     """Action for brewing beer in a pot"""
     def __init__(self, controller, pot, commands = None):
         super(BrewBeerAction, self).__init__(controller, commands)
-        self.pot = pot
+        self.pot = pot.container
         self.view = controller.view
         
     def execute(self):
@@ -467,8 +467,11 @@
         has_fruit = False
         has_wood = False
         has_bottle = False
-        player_character = self.model.game_state.getObjectById("PlayerCharacter").fifeagent
-        for item in self.pot.items.itervalues():
+        player_character = (self.model.game_state.
+                            getObjectById("PlayerCharacter").container)
+        for item in self.pot.children:
+            if not item:
+                continue
             if item.item_type == "Questionable water":
                 if has_water:
                     self.view.hud.addAction(unicode(\
@@ -517,30 +520,30 @@
                 has_yeast = True
                 yeast = item 
             else:
-                self.view.hud.addAction(unicode("Item " + item.name + \
-                                                " is not needed for brewing beer"))
+                self.view.hud.addAction(unicode(
+                    "Item " + (item.entity.description.view_name) + 
+                    " is not needed for brewing beer"))
                 self.view.hud.addAction(unicode(\
                     "Please put only ingredients for the beer in the pot.\
                     Things like bottles and wood have to be in your inventory"))
                 return
-        wood = player_character.hasItem("Wood")
+        wood = container.get_item(player_character, "Wood")
         if wood:
             has_wood = True        
-        bottle = player_character.hasItem("Empty beer bottle")
+        bottle = container.get_item(player_character, "Empty beer bottle")
         if bottle:
             has_bottle = True        
         if has_water and has_fruit and has_wood and has_bottle:
-            self.pot.removeItem(water)
-            self.pot.removeItem(fruit)
+            container.remove_item(self.pot, water.slot)
+            container.remove_item(self.pot, fruit.slot)
             if has_yeast:
-                self.pot.removeItem(yeast)
-            player_character.inventory.removeItem(wood)
-            inst_dict = {}
-            inst_dict["ID"] = "Beer"
-            inst_dict["object_type"] = "Beer"
-            new_item = self.model.createContainerObject(inst_dict)
-            player_character.inventory.placeItem(new_item)
-            self.view.hud.inventory.updateInventoryButtons()
+                container.remove_item(self.pot, yeast.slot)
+            container.remove_item(player_character, wood.slot)
+            new_item = (self.model.createItemByType("Beer", "Beer", 
+                                                    self.pot.entity.world)
+                        )
+            container.put_item(player_character, new_item.containable)
+            self.view.hud.inventory.updateImages()
             beer_quality = 0
             if water_type == 1:
                 if fruit_type == 1: