Ignore:
Timestamp:
07/24/10 14:09:19 (9 years ago)
Author:
beliar
Message:

Patch by Beliar.

  • Items can now be dropped and picked up again
  • Added generic image for items (Made by Q_x, he did the other items too).
Location:
trunk/game/scripts/objects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/objects/action.py

    r595 r596  
    289289    def __init__(self, controller, map_item, commands = None): 
    290290        super(PickUpAction, self).__init__(controller, commands) 
    291         self.view = controller.view 
    292291        self.map_item = map_item 
    293292 
     
    299298        super(PickUpAction, self).execute() 
    300299         
     300class DropItemAction(Action): 
     301    """Action for dropping an items on a map""" 
     302 
     303    def __init__(self, controller, item, container_gui, commands = None): 
     304        super(DropItemAction, self).__init__(controller, commands) 
     305        self.item = item 
     306        self.container_gui = container_gui 
     307 
     308    def execute(self): 
     309        item_data = self.item.getStateForSaving() 
     310        item_data["type"] = self.item.item_type 
     311        map_name = self.model.game_state.current_map_name 
     312        map_item_values = {} 
     313        map_item_values["ViewName"] = self.item.name 
     314        map_item_values["ObjectType"] = "MapItem" 
     315        map_item_values["ItemType"] = self.item.item_type 
     316        map_item_values["Map"] = map_name 
     317        coords = self.model.game_state.player_character.\ 
     318                                        getLocation().getExactLayerCoordinates() 
     319        map_item_values["Position"] = (coords.x - 1.0, coords.y + 1.0) 
     320        map_item_values["Rotation"] = 0 
     321        map_item_values["item"] = item_data 
     322        agent = {} 
     323        agent[self.item.ID] = map_item_values 
     324        self.model.addAgent("All", agent) 
     325        self.model.placeAgents() 
     326        self.item.in_container.takeItem(self.item)         
     327        self.container_gui.updateImages() 
     328        super(DropItemAction, self).execute() 
     329 
    301330ACTIONS = {"ChangeMap":ChangeMapAction,  
    302331           "OpenBox":OpenBoxAction,  
     
    308337           "Talk":TalkAction, 
    309338           "Use":UseAction, 
    310            "PickUp":PickUpAction} 
     339           "PickUp":PickUpAction, 
     340           "Drop":DropItemAction} 
  • trunk/game/scripts/objects/base.py

    r592 r596  
    376376        return sum((item.bulk for item in self.items.values())) 
    377377 
     378    def getItemAt(self, index): 
     379        return self.items[index] 
     380     
    378381    def indexOf(self, ID): 
    379382        """Returns the index of the item with the passed ID""" 
     
    414417                continue 
    415418            return self.items[index] 
    416         return None 
     419        return None     
    417420     
    418421    def serializeItems(self): 
  • trunk/game/scripts/objects/composed.py

    r592 r596  
    6363 
    6464    bulk = property(getBulk, setBulk, "Total bulk of container") 
    65  
     65     
    6666    def __repr__(self): 
    6767        return "[%s" % self.name + str(reduce((lambda a, b: a + ', ' + \ 
     
    8181class CarryableItem (GameObject, Carryable, Usable): 
    8282    """Composite class that will be used for all carryable items""" 
    83     def __init__(self, item_id, **kwargs): 
     83    def __init__(self, item_id, type = "CarryableItem", **kwargs): 
    8484        GameObject.__init__(self, **kwargs) 
    8585        Carryable.__init__(self, **kwargs) 
    8686        Usable.__init__(self, **kwargs) 
    8787        self.item_id = item_id 
     88        self.item_type = type 
    8889 
    8990    def prepareStateForSaving(self, state): 
Note: See TracChangeset for help on using the changeset viewer.