Ejemplo n.º 1
0
 def test_PutTake(self):
     self.assertIsNone(container.get_item(self.inv_15.container, 0))
     
     container.put_item(self.inv_15.container, self.sword_1.containable, 0)        
     self.assertIsNotNone(container.get_item(self.inv_15.container, 0))        
     self.assertListEqual(self.inv_15.container.children, self.sword_1.containable.container.children)
     self.assertEqual(self.inv_15.container.children[0].container, self.sword_1.containable.container)
     self.assertEqual(self.inv_15.container.children[0].slot, self.sword_1.containable.slot)
     
     container.take_item(self.inv_15.container, 0)
     self.assertIsNone(self.inv_15.container.children[0])
Ejemplo n.º 2
0
    def test_Swap(self):
        self.assertIsNone(self.inv_15.container.children[0])
        
        container.put_item(self.inv_15.container, self.sword_1.containable, 0)        
        sword1 = container.get_item(self.inv_15.container, 0)
        self.assertEqual(sword1.container, self.sword_1.containable.container)
        self.assertEqual(sword1.slot, self.sword_1.containable.slot)
        
        sword2 = container.put_item(self.inv_15.container, self.dagger_1.containable, 0)
        self.assertEqual(sword2.container, sword1.container)
        self.assertEqual(sword2.slot, sword1.slot)

        self.assertIsNotNone(container.get_item(self.inv_15.container, 0))        
        self.assertListEqual(self.inv_15.container.children, self.dagger_1.containable.container.children)
        self.assertEqual(self.inv_15.container.children[0].container, self.dagger_1.containable.container)
        self.assertEqual(self.inv_15.container.children[0].slot, self.dagger_1.containable.slot)
Ejemplo n.º 3
0
    def showContainer(self):
        """Show the container
           @return: None"""
        # Prepare slots 1 through 9
        empty_image = "gui/inv_images/inv_backpack.png"
        slot_count = 9
        for counter in range(1, slot_count+1):
            slot_name = "Slot%i" % counter
            index = counter - 1
            self.empty_images[slot_name] = empty_image
            widget = self.gui.findChild(name=slot_name)
            widget.item = container.get_item(self.container, index)
            widget.index = index
            self.updateImage(widget)
            self.events_to_map[slot_name] = cbwa(self.dragDrop, slot_name)
            self.events_to_map[slot_name + "/mouseReleased"] = \
                                            self.showContextMenu

        self.gui.mapEvents(self.events_to_map)
        self.gui.show()
Ejemplo n.º 4
0
 def execute(self):
     """Brew the beer"""
     has_water = False
     has_yeast = False
     has_fruit = False
     has_wood = False
     has_bottle = False
     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(\
                     "Please put only 1 water in the pot"))
                 return
             has_water = True
             water_type = 1 
             water = item
         elif item.item_type == "Pure water":
             if has_water:
                 self.view.hud.addAction(unicode(\
                     "Please put only 1 water in the pot"))
                 return
             has_water = True
             water_type = 2
             water = item
         elif item.item_type == "Grain":
             if has_fruit:
                 self.view.hud.addAction(unicode(\
                     "Please put only 1 fruit in the pot"))
                 return
             has_fruit = True
             fruit_type = 3
             fruit = item
         elif item.item_type == "Wild potato":
             if has_fruit:
                 self.view.hud.addAction(unicode(\
                     "Please put only 1 fruit in the pot"))
                 return
             has_fruit = True
             fruit_type = 2
             fruit = item
         elif item.item_type == "Rotten yam":
             if has_fruit:
                 self.view.hud.addAction(unicode(\
                     "Please put only 1 fruit in the pot"))
                 return
             has_fruit = True
             fruit_type = 1
             fruit = item
         elif item.item_type == "Yeast":
             if has_yeast:
                 self.view.hud.addAction(unicode(\
                     "Please put only 1 yeast in the pot"))
                 return
             has_yeast = True
             yeast = item 
         else:
             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 = container.get_item(player_character, "Wood")
     if wood:
         has_wood = True        
     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:
         container.remove_item(self.pot, water.slot)
         container.remove_item(self.pot, fruit.slot)
         if has_yeast:
             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:
                 beer_quality = -1
             elif fruit_type == 2:
                 beer_quality = 2
             elif fruit_type == 3:
                 beer_quality = 3
         if water_type == 2:
             if fruit_type == 1:
                 beer_quality = 1
             elif fruit_type == 2:
                 beer_quality = 3
             elif fruit_type == 3:
                 beer_quality = 4
         if beer_quality > 0 and has_yeast:
             beer_quality += 1
         self.model.game_state.quest_engine.quests["beer"].\
                 setValue("beer_quality", beer_quality)
     else:
         self.view.hud.addAction(unicode(
         """For brewing beer you need at least:
         In the pot:
             Fruit (like grain, potato, yam)
             Water
             Optionally:
                 Good quality yeast.
                 Wild yeast will be used if none present.
         In the inventory:
             Wood
             Empty bottle"""))
     super(BrewBeerAction, self).execute()
Ejemplo n.º 5
0
 def updateImages(self):
     for index, button in enumerate(self.buttons):
         widget = self.gui.findChild(name=button)            
         widget.item = container.get_item(self.container, index)
         self.updateImage(widget)