nakedmudv3.6/
nakedmudv3.6/lib/
nakedmudv3.6/lib/help/A/
nakedmudv3.6/lib/help/B/
nakedmudv3.6/lib/help/C/
nakedmudv3.6/lib/help/D/
nakedmudv3.6/lib/help/G/
nakedmudv3.6/lib/help/H/
nakedmudv3.6/lib/help/J/
nakedmudv3.6/lib/help/L/
nakedmudv3.6/lib/help/M/
nakedmudv3.6/lib/help/O/
nakedmudv3.6/lib/help/P/
nakedmudv3.6/lib/help/R/
nakedmudv3.6/lib/help/S/
nakedmudv3.6/lib/help/W/
nakedmudv3.6/lib/logs/
nakedmudv3.6/lib/misc/
nakedmudv3.6/lib/players/
nakedmudv3.6/lib/txt/
nakedmudv3.6/lib/world/
nakedmudv3.6/lib/world/examples/
nakedmudv3.6/lib/world/examples/mproto/
nakedmudv3.6/lib/world/examples/oproto/
nakedmudv3.6/lib/world/examples/reset/
nakedmudv3.6/lib/world/examples/rproto/
nakedmudv3.6/lib/world/examples/trigger/
nakedmudv3.6/lib/world/limbo/
nakedmudv3.6/lib/world/limbo/room/
nakedmudv3.6/lib/world/limbo/rproto/
nakedmudv3.6/src/alias/
nakedmudv3.6/src/dyn_vars/
nakedmudv3.6/src/editor/
nakedmudv3.6/src/example_module/
nakedmudv3.6/src/help2/
nakedmudv3.6/src/set_val/
nakedmudv3.6/src/socials/
nakedmudv3.6/src/time/
################################################################################
#
# inform.py
#
# Python's mirror of C's inform.c -- contains various functions that perform
# informative duties. Examining places/things, displaying proper names, etc...
#
################################################################################
from mud import *
import utils, char, hooks, mudsock



################################################################################
# utility functions
################################################################################
def see_char_as(ch, tgt):
    '''returns the proper name one character sees another by'''
    if ch.cansee(tgt):
        return tgt.name
    else:
        return "someone"

def see_obj_as(ch, obj):
    '''returns the proper name a character sees an object by'''
    if ch.cansee(obj):
        return obj.name
    else:
        return "something"

def see_exit_as(ch, ex):
    '''returns the proper name a character sees an exit by'''
    if ch.cansee(ex):
        return ex.name
    else:
        return "something"

def show_equipment(ch, tgt):
    '''shows ch tgt\'s equipment'''
    for part in tgt.bodyparts:
        obj = tgt.get_equip(part)

        # if it's not there, or on someone else and we can't see it, skip it
        if obj == None or (ch != tgt and not ch.cansee(obj)):
            continue

        ch.send("%-30s %s" % ("{c<{C" + part + "{c>{n", see_obj_as(ch, obj)))

def build_who():
    '''returns a formatted list of all the people currently online'''
    buf = "--------------------------------------------------------------------------------\r\n"

    # build character info
    count   = len(mudsock.socket_list())
    playing = 0
    for sock in mudsock.socket_list():
        if not (sock.ch == None or sock.ch.room == None):
            buf = buf+(" %-16s %-15s %45s "
                       % (sock.ch.name,sock.ch.race,sock.ch.user_groups))+"\r\n"
            playing = playing + 1

    conn_end = "s"
    if count == 1: conn_end = ""
    play_end = "s"
    if playing == 1: play_end = ""

    # build our footer
    buf = buf + "--------------------------------------------------------------------------------\r\n" + (" %d socket" % count)  + conn_end + " logged in." + (" %d player" % playing) + play_end + " currently playing.\r\n" + "--------------------------------------------------------------------------------\r\n"
    
    return buf



################################################################################
# hooks
################################################################################
def equipment_look_hook(info):
    '''displays a character\'s equipment when looked at'''
    tgt, ch = hooks.parse_info(info)

    if ch != tgt:
        gndr = tgt.heshe
        act  = "is"
    else:
        gndr = "You"
        act  = "are"

    ch.send("\n" + gndr + " " + act + " wearing:")
    show_equipment(ch, tgt)



################################################################################
# add our hooks
################################################################################
hooks.add("look_at_char", equipment_look_hook)



################################################################################
# unload procedure
################################################################################
def __unload__():
    '''things that need to be detached when the module is un/reloaded'''
    hooks.remove("look_at_char", equipment_look_hook)