Beispiel #1
0
    def _execute(self):
        # find the item to give in inventory
        items = find_items_in_container(self.tokens[0],
                                        self.anima.inventory)
        if not items:
            return "You are not carrying %s." % self.tokens[0]

        # find the target in the room
        target = None
        for player in self.anima.room.player_related.all():
            if self.tokens[1] in (player.id, player.name):
                target = player
                break
        if not target:
            return "No-one by the name %s here." % self.tokens[1]
            
        # transfer each item
        output = []
        room_msg = []
        for item in items:
            # weight check
            if can_hold_item(target, item):
                output.append("You give %s to %s" % (item.get_name(),
                                                     target.get_name()))
                item.owner = self.anima
            else:
                output.append("You can't carry %s: it's too heavy"
                              % item.get_name())
        self.anima.room.notify('\n'.join(room_msg), exclude=[self.anima])
        return '\n'.join(output), ['room', 'player']
Beispiel #2
0
    def _get_items_in(self, container, source=None):
        """
        Common bit of code used by both get_from_room and get_from_container
        and therefore pulled out for DRY.
        room is pass True if it's a get specifically from a room,
        False if it's from any other container (so that it doesn't say
        "you get a dagger from The Central Square" but rather simply
        "you get a dagger" when from a room).
        """
        output = []
        room_output = []
        for item in container:
            # weight check
            if can_hold_item(self.anima, item):
                item.owner = self.anima
                item.save()
                
                # log to room
                room_msg = "%s gets %s" % (self.anima.get_name(),
                                           item.get_name())
                if source:
                    room_msg += " from %s" % source
                room_output.append(room_msg + '.')
                
                # log to self
                self_msg = "You get %s" % item.get_name()
                if source:
                    self_msg += " from %s" % source
                output.append(self_msg + '.')
            else:
                output.append("You can't carry %s: it's too heavy."
                              % item.get_name())

        self.anima.room.notify('\n'.join(room_output), exclude=[self.anima])
        return '\n'.join(output), ['room', 'player']
Beispiel #3
0
    def _execute(self):
        # get the items that the user wants to put somewhere
        items = find_items_in_container(self.tokens[0],
                                        self.anima.inventory)
        if not items:
            return ("You are not carrying a '%s'" % self.tokens[0])
        
        # find the container
        containers = find_actionable_item(self.anima, self.tokens[1])

        if not containers:
            return "No such item: %s" % self.tokens[1]
        elif not containers[0].base.capacity:
            return "%s is not a container" % self.tokens[1]
            
        room_msg = []
        source_msg = []
        for item in items:
            # weight check
            if can_hold_item(containers[0], item):
                item.owner = containers[0]
                item.save()
                room_msg.append("%s puts %s in %s." % (
                                    self.anima.get_name(),
                                    item.get_name(),
                                    containers[0].get_name(),
                                ))
                source_msg.append("You put %s in %s." %
                              (item.get_name(), containers[0].get_name()))
                item.owner = containers[0]
                item.save()
            else:
                source_msg.append("%s cannot fit inside %s."
                                  % self.tokens[0:1])

        self.anima.room.notify('\n'.join(room_msg), exclude=[self.anima])
        return '\n'.join(source_msg), ['player', 'room']