示例#1
0
文件: action.py 项目: parpg/parpg
 def execute(self):
     real_item = self.item.containable
     self.item.fifeagent = None
     player = self.model.game_state.getObjectById("PlayerCharacter")
     self.model.moveObject(self.item.general.identifier, None)
     self.model.updateObjectDB(self.item.world)
     container.put_item(player.container, real_item)
     super(PickUpAction, self).execute()
示例#2
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])
示例#3
0
    def dropObject(self, obj):
        """Drops the object being dropped
           @type obj: string
           @param obj: The name of the object
           @return: None"""
        try:
            drop_widget = self.gui.findChildByName(obj)
            drop_index = drop_widget.index
            replace_item = None

            if data_drag.dragging:
                drag_item = data_drag.dragged_item
                # this will get the replacement item and the data for drag_drop if
                ## there is an item all ready occupying the slot
                replace_item = container.put_item(self.container, drag_item, drop_index)

            # if there was no item the stop dragging and reset cursor
            if replace_item:
                image = drop_widget.image
                self.setDragData(replace_item, image, image)
            else:
                data_drag.dragging = False
                # reset the mouse cursor to the normal cursor
                self.controller.resetMouseCursor()
            drop_widget.item = drag_item.entity
            self.updateImage(drop_widget)
        except (container.BulkLimitError):
            # Do we want to notify the player why the item can't be dropped?
            pass
示例#4
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)
示例#5
0
文件: gamemodel.py 项目: parpg/parpg
 def createInventoryItems(self, inv, obj, world):
     slots = inv["Slots"]
     obj.container.children = list()
     for x in xrange(slots):
         obj.container.children.append(None)
     items = inv["Items"] if inv.has_key("Items") else list()
     for data in items:
         item = None
         slot = data["Slot"] if data.has_key("Slot") else -1
         if data.has_key("type"):
             item_type = data["type"]
             item = self.createItemByType(item_type, data["ID"], world)
         else:
             identifier = data["ID"]
             item = self.createItemByID(world, identifier)
                 
         container.put_item(obj.container, item.containable, slot)
示例#6
0
文件: action.py 项目: parpg/parpg
 def execute(self):
     #Check if there are special commands and execute them
     for command_data in self.commands:
         command = command_data["Command"]
         if command == "ReplaceItem":
             object_id = command_data["ID"]
             object_type = command_data["ObjectType"]
             containable = self.item.containable
             new_item = self.model.createItemByType(object_type, 
                                                    object_id, 
                                                    self.item.world)
             container.put_item(containable.container, 
                                new_item.containable,
                                containable.slot)
             self.model.deleteObject(self.item.general.identifier)
             self.item.delete()
             self.view.hud.inventory.updateImages()
     super(UseAction, self).execute()
示例#7
0
 def __call__(self, game_state):
     """
     Move items from the player's inventory to the NPC's inventory.
     
     @param game_state: variables and functions that make up the current
         game state.
     @type game_state: dict of objects
     """
     item_types = self.item_types
     for item_type in item_types:
         item = container.take_item(game_state['pc'].container, item_type)
         if (item):
             container.put_item(game_state['npc'].container, item)
             print("You give the {0} to {1}".format(item_type,
                                                    game_state['npc'].
                                                    description.view_name))
         else:
             print("You don't have the {0}".format(item_type))
示例#8
0
 def __call__(self, game_state):
     """
     Take an item from the player and place another at its place.
     
     @param game_state: variables and functions that make up the current
         game state.
     @type game_state: dict of objects
     """
     old_type = self.item_types[0]
     new_type = self.item_types[1]
     item = container.take_item(game_state['pc'].container, old_type)
     if item:
         model = game_state['model']
         new_item = model.createItemByType(new_type, new_type, 
                                           item.entity.world)
         container.put_item(game_state['pc'].container, 
                            new_item.containable, item.slot)
         model.deleteObject(item.entity.general.identifier)
         item.delete()
         print("{0} took the {1} and gave you the {2}".format(
             game_state['npc'].description.view_name, old_type, item_type))
     else:
         print("You don't have the {0}".format(old_type))
示例#9
0
文件: action.py 项目: parpg/parpg
 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()
示例#10
0
    def test_BulkSlots(self):
        container.put_item(self.inv_15.container, self.sword_1.containable)
        container.put_item(self.inv_25.container, self.sword_2.containable)
        self.assertEqual(container.get_total_bulk(self.inv_15.container), self.sword_1.containable.bulk)
        self.assertEqual(container.get_total_bulk(self.inv_25.container), self.sword_2.containable.bulk)
        
        container.put_item(self.inv_15.container, self.axe_1.containable)
        container.put_item(self.inv_25.container, self.axe_2.containable)
        self.assertEqual(container.get_total_bulk(self.inv_15.container), container.get_total_bulk(self.inv_25.container))
        
        self.assertRaises(container.BulkLimitError, container.put_item, self.inv_15.container, self.spear_1.containable)
        container.put_item(self.inv_25.container, self.spear_2.containable)

        container.put_item(self.inv_15.container, self.dagger_1.containable)
        container.put_item(self.inv_25.container, self.dagger_2.containable)
        self.assertNotEqual(container.get_total_bulk(self.inv_15.container), container.get_total_bulk(self.inv_25.container))

        self.assertRaises(container.NoFreeSlotError, container.put_item, self.inv_15.container, self.mace_1.containable)
        container.put_item(self.inv_25.container, self.mace_2.containable)