Ejemplo n.º 1
0
def cmd_destroy(s, r):
    '''destroy <object>

    Destroy the specified object.

    '''

    objname = r.get('objname', '')
    objtzid = r.get('objtzid', 0)
    if not objname and not objtzid:
        s.message('Try: @destroy <object>')
        raise SyntaxError

    player = s.player
    room = s.room
    obj = find(r, room, player)
    if obj is None:
        obj = rooms.getname(objname) or \
                rooms.get(objtzid) or \
                tzindex.get(objtzid)

    if obj is not None:
        s.message('You speak a word of power and ...')
        s.room.action(dict(act="destroy", actor=player))
        obj.destroy()

    else:
        s.message('Object not found.')
Ejemplo n.º 2
0
def _clone_room(s, objname, objtzid, newname=''):
    # next, try to clone a room
    # first look at existing rooms
    orig = rooms.getname(objname) or \
            rooms.get(objtzid)

    # if it is not there, it might be a Room class
    if orig is None:
        if objname in rooms.classes():
            cls = getattr(rooms, objname)
            obj = cls()
        else:
            obj = None
    else:
        obj = copy.copy(orig)

    if obj:
        if newname:
            obj.name = newname
        s.message(obj, 'created.')
        return obj
Ejemplo n.º 3
0
def cmd_dig(s, r):
    '''dig <exit> to <destination> [return by <exit>]

    Connect exit to room and optionally from the new room back to here.

    Destination or exits can be existing objects, or if they do not
        yet exist, they will be created.

    If the exit out name is one of the compass directions (ie north,
        south, east, northeast, etc) and no return by exit name is
        given, the return by exit will be created automatically with
        the opposite direction name. (eg. if an exit out is dug to
        the west, an exit in will also be added to the east from
        the destination.)

    '''

    room = s.room

    destname = r.get('destname', '')
    desttzid = r.get('desttzid', 0)
    if not destname and not desttzid:
        s.message('Try: @dig <exit> to <destination>')
        raise SyntaxError
    destination = rooms.getname(destname) or rooms.get(desttzid)

    if destination is None and destname:
        destination = rooms.Room(destname)
        s.message(destination, 'created.')
    elif destination is None:
        s.message('#', desttzid, 'is not a room.')
        return

    exitoutname = r.get('exitoutname', '')
    exitouttzid = r.get('exitouttzid', 0)
    xo = room.exitname(exitoutname) or room.exit(exitouttzid)

    exitinname = r.get('exitinname', '')
    exitintzid = r.get('exitintzid', 0)
    if not exitinname and not exitintzid and xo is not None:
        exitinname = xo.autoreturn()

    xi = destination.exitname(exitinname) or destination.exit(exitintzid)
    if xi is not None:
        exitinname = xi.name

    if xo is not None:
        xo.destination = destination
        if xi is not None:
            xi.destination = room
        else:
            exitinname = exitinname or 'door'
            xi = exits.Exit(exitinname, room=destination, destination=room)
            xo.link(xi)
            destination.action(dict(act='dig', actor=None, exit=xi))
        s.message('You connect', xo, 'to', destination, '.')

    elif exitoutname:
        if exitinname or xi is None:
            xo = exits.Exit(exitoutname, room=room, destination=destination, return_name=exitinname)
            room.action(dict(act='dig', actor=s.player, exit=xo))
            xi = xo.get_linked_exit()
            if xi is None:
                exitinname = 'door'
                xi = exits.Exit(exitinname, room=destination, destination=room)
            destination.action(dict(act='dig', actor=None, exit=xi))
            s.message('You dig', xo, 'to', destination, '.')
        else:
            s.message('#', exitintzid, 'is not an exit in', destination, '.')
            raise TypeError

    else:
        s.message('#', exitouttzid, 'is not an exit in this room.')
Ejemplo n.º 4
0
def cmd_teleport(s, r=None):
    '''teleport [to [<room>|<character>]] OR teleport <object> to <room>

    Teleport self to the named room or character, or if no name is given
        teleport self to home, OR

    Teleport the object to the room.

    '''

    room = s.room
    player = s.player
    if room is not None:
        room.action(dict(act='teleport', actor=player))

    objname = r.get('objname', '')
    objtzid = r.get('objtzid', 0)

    destname = r.get('obj2name', '')
    desttzid = r.get('obj2tzid', 0)

    if (objname or objtzid) and (destname or desttzid):
        destination = rooms.getname(destname) or rooms.get(desttzid)
        if destination is None:
            s.message('No such place.')
            return

        obj = find(r, room, player, room) or \
                players.getname(objname) or players.get(objtzid) or \
                mobs.getname(objname) or mobs.get(objtzid) or \
                tzindex.get(objtzid)
        if obj is None:
            s.message('No such object.')
        elif obj._bse == 'Room':
            s.message('You cannot teleport a room.')
        else:
            obj.teleport(destination)
            s.message('You teleport', obj, '.')

    elif not (destname or desttzid):
        # send the player home
        player.teleport()

    else:
        destination = rooms.getname(destname) or \
                        rooms.get(desttzid)

        if destination is None:
            toplayer = players.getname(destname) or \
                        players.get(desttzid)

            if toplayer is not None:
                destination = toplayer.room
                if destination is None:
                    s.message('Player is not logged in.')
                    return
            else:
                tomob = mobs.getname(destname) or \
                        mobs.get(desttzid)

                if tomob is not None:
                    destination = tomob.room
                else:
                    s.message('No such room or character.')
                    return

        player.teleport(destination)