'Implements the ooc look command
We use an attribute _character_dbrefs on the player in order
to figure out which characters are "theirs". A drawback of this
is that only the CmdCharacterCreate command adds this attribute,
and thus e.g. player #1 will not be listed (although it will work).
Existence in this list does not depend on puppeting rights though,
that is checked by the @ic command directly.'

def func(self):

    self.character = None
    if utils.inherits_from(self.caller, 'evennia.objects.objects.Object'):
        self.character = self.caller
        if hasattr(self.caller, 'player'):
            self.caller = self.caller.player
    if (not self.character):
        avail_chars = self.caller.db._character_dbrefs
        if self.args:
            if (not avail_chars):
                self.caller.msg('You    have    no    characters    to    look    at.    Why    not    create    one?')
                return
            objs = managers.objects.get_objs_with_key_and_typeclass(self.args.strip(), CHARACTER_TYPECLASS)
            objs = [obj for obj in objs if (obj.id in avail_chars)]
            if (not objs):
                self.caller.msg('You    cannot    see    this    Character.')
                return
            self.caller.msg(objs[0].return_appearance(self.caller))
            return
        charnames = []
        if self.caller.db._character_dbrefs:
            dbrefs = self.caller.db._character_dbrefs
            charobjs = [managers.objects.get_id(dbref) for dbref in dbrefs]
            charnames = [charobj.key for charobj in charobjs if charobj]
        if charnames:
            charlist = 'The    following    Character(s)    are    available:\n\n'
            charlist += '\n\r'.join([('|w                %s|n' % charname) for charname in charnames])
            charlist += '\n\n            Use    |w@ic    <character    name>|n    to    switch    to    that    Character.'
        else:
            charlist = 'You    have    no    Characters.'
        string = ('            You,    %s,    are    an    |wOOC    ghost|n    without    form.    The    world    is    hidden\n            from    you    and    besides    chatting    on    channels    your    options    are    limited.\n            You    need    to    have    a    Character    in    order    to    interact    with    the    world.\n\n            %s\n\n            Use    |wcreate    <name>|n    to    create    a    new    character    and    |whelp|n    for    a\n            list    of    available    commands.' % (self.caller.key, charlist))
        self.caller.msg(string)
    else:
        self.caller = self.character
        super(CmdOOCLook, self).func()
