示例#1
0
    def do_eat(self, item: Entity):
        if not self.same_position(item):
            logging.error(
                '{}({}) is not located in {}, impossible to drink it {}'.
                format(self.entity.name, self.entity.pos, item.pos, item.name))
            return False

        raise NotImplementedError('Add this component : hunger')
示例#2
0
    def remove(self, item: Entity):

        if item not in self.content:
            logging.error('{} is not in {} inventory'.format(
                item.name, self.entity.name))
            return False
        else:
            self.content.remove(item)
            self.filled -= item.size
            return True
示例#3
0
    def enter_area(self, area: Entity, pos: Tuple[int, int]):

        if not area:
            logging.error('{} mov component cannot enter area {}'.format(
                self, area))
            return KeyError('error')

        self.leave_area(pos)
        self.entity.area = area
        self.moveto(pos)
        area.map[pos].entities.append(self.entity)
示例#4
0
    def drop(self, item: Entity):

        if not item.carriable:
            logging.error('{} cannot be dropped, not a carriable item.'.format(
                item.name))
            return False
        if item not in self.content:
            logging.error('{} is not in {} inventory'.format(
                item.name, self.entity.name))
            return False
        else:
            self.remove(item)
            item.dropped()
            return True
示例#5
0
    def pickup(self, item: Entity):

        if not self.same_position(item):
            logging.error(
                '{}({}) is not located in {}, impossible to pickup {}'.format(
                    self.entity.name, self.entity.pos, item.pos, item.name))
            return False
        elif not item.carriable:
            logging.error(
                '{} cannot be picked up, it is not a carriable item'.format(
                    item.name))
            return False
        elif item.size > self.space_left:
            logging.error(
                'Not enough space left in {} inventory. '
                'The item is {} units big, and there is only {} space left.'.
                format(self.entity.name, item.size, self.space_left))
            return False
        else:
            self.add(item)
            item.carriedby(self.owner)
            return True