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')
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
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)
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
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