コード例 #1
0
ファイル: __init__.py プロジェクト: abliss/stark
    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']
コード例 #2
0
ファイル: __init__.py プロジェクト: abliss/stark
    def _execute(self):
        items = find_items_in_container(self.tokens[0],
                                        self.anima.inventory)
        if not items:
            return "You are not carrying '%s'." % self.tokens[0]
        
        output = []
        room_output = []
        for item in items:
            # to support both wear and wield
            if item.__class__.__name__ == "Weapon":
                wear_verb = 'wield'
            else:
                wear_verb = 'wear'
            
            if getattr(self.anima, item.base.slot):
                output.append("You're already wearing something on this slot.")
                continue
            
            # put the item on the slot
            setattr(self.anima, item.base.slot, item)
            self.anima.save()
            
            # notify room
            room_output.append("%s %ss %s." % (self.anima.get_name(),
                                               wear_verb,
                                               item.base.name))
            
            # notify player
            output.append("You %s %s." % (wear_verb, item.base.name))

        self.anima.room.notify('\n'.join(room_output), exclude=self.anima)
        return '\n'.join(output), ['player']
コード例 #3
0
ファイル: __init__.py プロジェクト: abliss/stark
    def get_from_room(self):
        items = find_items_in_container(self.tokens[0],
                                        self.anima.room.items.all())
        if not items:
            return "There is no %s in this room." % tokens[1]

        return self._get_items_in(items, source=None)
コード例 #4
0
ファイル: __init__.py プロジェクト: abliss/stark
 def get_from_container(self):
     # get 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]
     
     # get the item from the first found container
     # TODO: decide what to do about multiple containers here
     items = find_items_in_container(self.tokens[0],
                                     containers[0].owns.all())
     if not items:
         return "No '%s' found in '%s'" % (self.tokens[0], self.tokens[1])
     
     return self._get_items_in(items, source=containers[0].get_name())
コード例 #5
0
ファイル: __init__.py プロジェクト: abliss/stark
    def _execute(self):
        # get non-empty eq items
        eq = filter(lambda x: x, self.anima.equipment.values())
        items = find_items_in_container(self.tokens[0], eq)
        if not items:
            return "You are not wearing a %s." % self.tokens[0]
        output = []
        room_output = []
        for item in items:
            output.append("You remove %s." % item.get_name())
            room_output.append("%s removes %s." % (self.anima.get_name(),
                                                   item.get_name()))

            setattr(self.anima, item.base.slot, None)
            self.anima.save()

        self.anima.room.notify('\n'.join(room_output), exclude=[self.anima])
        return '\n'.join(output), ['player']
コード例 #6
0
ファイル: __init__.py プロジェクト: abliss/stark
    def _execute(self):
        # get the items that match the argument
        items = find_items_in_container(self.tokens[0],
                                        self.anima.inventory)
        if not items:
            return "You are not carrying a '%s'." % self.tokens[0]
            
        source_msg = []
        room_msg = []
        for item in items:
            item.owner = self.anima.room
            item.save()
            room_msg.append("%s drops %s." % (self.anima.get_name(),
                                              item.get_name()))
            source_msg.append("You drop %s." % item.get_name())

        self.anima.room.notify('\n'.join(room_msg), exclude=[self.anima])
        return '\n'.join(source_msg), ['player', 'room']
コード例 #7
0
ファイル: __init__.py プロジェクト: abliss/stark
    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']