示例#1
0
文件: wiz.py 项目: ChrisLR/scrolls
    def func(self):
        ch = self.caller

        if not ch.attributes.has('assigned_zone'):
            self.msg("You must be assigned a zone before you can edit rooms.")
            return

        if not self.args.strip():
            # see if you ca edit the current room you are in.
            cur_room = ch.location

            room_zone = cur_room.db.zone
            if has_zone(ch) == room_zone:
                vnum = int(cur_room.key)
            else:
                self.msg("You don't have permission to edit this zones room.")
                return
        else:

            roomdb = GLOBAL_SCRIPTS.roomdb

            if 'new' in self.args.lower():
                if not roomdb.vnum.keys():
                    vnum = 1
                else:
                    vnum = max(roomdb.vnum.keys()) + 1
            else:
                vnum = self.args
                try:
                    vnum = int(vnum)
                except ValueError:
                    ch.msg("You must supply a valid vnum")
                    return

        ch.ndb._redit = REditMode(ch, vnum)
        ch.cmdset.add("world.edit.redit.REditCmdSet")
        ch.cmdset.all()[-1].add([
            CmdRList(),
            CmdZoneSet(),
            CmdNorth(),
            CmdSouth(),
            CmdEast(),
            CmdWest(),
            CmdUp(),
            CmdDown()
        ])

        ch.execute_cmd("look")
示例#2
0
    def summarize(self):
        exit_summary = ""

        for ename, rvnum in self.obj['exits'].items():
            room = "" if get_room(rvnum) is None else get_room(rvnum).db.name
            exit_summary += f"    |y{ename.capitalize():<5}|n: {rvnum:<7} {room:<15}\n"

        edesc_msg = ""
        for key, edesc in self.obj['edesc'].items():
            edesc_msg += f"|c{key}|n:\n{crop(edesc)}\n"

        room_flags = list_to_string(self.obj['flags'])

        sector = self.obj['type']
        sector_symbol = VALID_ROOM_SECTORS[self.obj['type']].symbol

        status = "(|rCAN NOT EDIT|n)" if self.obj['zone'] != has_zone(
            self.caller) else ""
        msg = f"""
********Room Summary*******
        {status}
VNUM: [{self.vnum}]      ZONE:[|m{self.obj['zone']}|n]

name    : |y{self.obj['name']}|n
desc    : |y{self.obj['desc']}|n
flags   : 
|y{room_flags}|n

sector  : |m{sector}|n, [{sector_symbol}]
exits  : 
{exit_summary}

edesc   : 
{edesc_msg}
----------------Extras---------------------
"""
        for efield, evalue in self.obj['extra'].items():
            msg += f"{efield:<7}: {crop(evalue, width=50)}\n"
        self.caller.msg(msg)
示例#3
0
文件: wiz.py 项目: ChrisLR/scrolls
    def func(self):
        ch = self.caller
        ch.msg(self.args)
        args = self.args.strip()
        roomdb = dict(GLOBAL_SCRIPTS.roomdb.vnum)
        if not roomdb:
            ch.msg("There are no rooms within the game")
            return

        vnum_roomdb = roomdb.keys()
        min_ = min(vnum_roomdb)
        max_ = max(vnum_roomdb)

        legend = ["VNum", "Name", "Exits", "Zone"]
        try:
            _ = roomdb[1]
        except KeyError:
            ch.msg("No rooms are saved to database, try creating one first")
            return

        if not args:
            table = self.styled_table(*legend, border='incols')
            ch_zone = has_zone(ch)

            if ch_zone:
                for vnum in range(min_, max_ + 1):
                    data = roomdb[vnum]
                    if match_string(ch_zone, make_iter(data['zone'])):
                        exits = {
                            k: v
                            for k, v in data['exits'].items() if v > 0
                        }
                        vnum = raw_ansi(f"[|G{vnum:<4}|n]")
                        sdesc = crop(raw_ansi(data['name']), width=50) or ''
                        table.add_row(vnum, sdesc, f"{exits}", data['zone'])
            else:
                for vnum in range(min_, max_ + 1):
                    data = roomdb[vnum]
                    exits = {k: v for k, v in data['exits'].items() if v > 0}
                    vnum = raw_ansi(f"[|G{vnum:<4}|n]")
                    sdesc = crop(raw_ansi(data['name']), width=50) or ''
                    table.add_row(vnum, sdesc, f"{exits}", data['zone'])

            msg = str(table)
            ch.msg(msg)
            return

        args = args.split(' ')
        if len(args) < 2:
            ch.msg("Supply either type or name to search for")
            return
        table = self.styled_table(*legend, border='incols')
        type_ = args[0]
        if type_ not in ('zone', 'name'):
            ch.msg("Please supply either (type or name) to searchby")
            return

        criteria = args[1]
        for vnum in range(min_, max_ + 1):
            # for vnum, data in GLOBAL_SCRIPTS.objdb.vnum.items():
            data = roomdb[vnum]
            if type_ == 'zone':
                if match_string(criteria, make_iter(data['zone'])):
                    exits = {k: v for k, v in data['exits'].items() if v > 0}

                    vnum = raw_ansi(f"[|G{vnum:<4}|n]")
                    sdesc = crop(raw_ansi(data['name']), width=50) or ''
                    table.add_row(vnum, sdesc, f"{exits}", data['zone'])
                    continue

            if type_ == 'name':
                if match_string(criteria, data['name'].split()):
                    exits = {k: v for k, v in data['exits'].items() if v > 0}

                    vnum = raw_ansi(f"[|G{vnum:<4}|n]")
                    sdesc = crop(raw_ansi(data['name']), width=50) or ''
                    table.add_row(vnum, sdesc, f"{exits}", data['zone'])
                    continue
        msg = str(table)
        ch.msg(msg)
        return
示例#4
0
    def func(self):
        ch = self.caller
        if not ch.attributes.has('assigned_zone'):
            self.msg("You must be assigned a zone before you can edit rooms.")
            return

        if not self.args:
            ch.msg(
                f"refer to {mxp_string('help dig', 'dig')} for more information"
            )
            return
        args = self.args.strip().split()
        if len(args) >= 2:
            vnum = None
            try:
                type_, direction, vnum = args
            except ValueError:
                type_, direction = args
            except:
                ch.msg(
                    f"incorrect format for dig.\nrefer to {mxp_string('help dig','dig')} for more information"
                )
                return

            if type_ not in ('bi', 'uni'):
                ch.msg("dig type must be either `bi` or `uni`")
                return

            if not match_string(direction, VALID_DIRECTIONS):
                ch.msg("must use a valid direction")
                return

            if not vnum:
                # dig in direction to new room and create exits from both ends
                cur_room = ch.ndb._redit.obj

                # get next available vnum, we are also guarenteed that room will
                # not exist
                nextvnum = next_available_rvnum()
                new_room_info = copy.deepcopy(DEFAULT_ROOM_STRUCT)

                # set exit of new room to the vnum of current room, using opposite
                # direction from what was supplied (north->south, etc...)
                if type_ == 'bi':
                    new_room_info['exits'][
                        OPPOSITE_DIRECTION[direction]] = ch.ndb._redit.vnum

                # also set the zone for new room to cur_zone
                new_room_info['zone'] = has_zone(ch)

                #set exit of current room to the new room just created
                cur_room['exits'][direction] = nextvnum

                # actually create the object of new_room
                # but just to be safe, let's make sure
                room_exists = search_object(
                    str(nextvnum), typeclass='typeclasses.rooms.rooms.Room')

                if room_exists:
                    raise Exception(
                        "trying to create a new room with a vnum that shouldn't exist, but the room does..."
                    )
                # create and store blueprint of new room
                ch.ndb._redit.db.vnum[nextvnum] = new_room_info

                # create object
                room = create_object('typeclasses.rooms.rooms.Room',
                                     key=nextvnum)

                # save current room in redit to update exits
                ch.ndb._redit.save(override=True)

                # change what redit sees, now we are editting new room
                ch.ndb._redit.__init__(ch, nextvnum)
                ch.ndb._redit.save(override=True)
                # move to room
                ch.move_to(room)

                return

            else:
                vnum = int(vnum)
                # first check to see if vnum of room exists
                target_room = search_object(
                    str(vnum), typeclass='typeclasses.rooms.rooms.Room')

                if not target_room:
                    # check to see if is in database
                    try:
                        target_room = GLOBAL_SCRIPTS.roomdb.vnum[vnum]
                    except KeyError:

                        ch.msg(
                            "room doesn't exist create it first and then rerun this command"
                        )
                        return
                    _ = create_object('typeclasses.rooms.rooms.Room', key=vnum)

                cur_room = ch.ndb._redit.obj

                if target_room['zone'] != cur_room['zone']:
                    ch.msg(
                        "You can't create an exit to a room that doesn't belong to this zone"
                    )
                    return

                if type_ == 'bi':
                    target_room['exits'][
                        OPPOSITE_DIRECTION[direction]] = ch.ndb._redit.vnum
                    ch.msg(
                        f"You created an exit in room {vnum} to your current location"
                    )

                cur_room['exits'][direction] = vnum
                ch.ndb._redit.save(override=True)

                # change what redit sees, now we are editting new room
                ch.ndb._redit.__init__(ch, vnum)
                ch.ndb._redit.save(override=True)
                ch.msg("Created exit to room {vnum}")
示例#5
0
    def func(self):
        ch = self.caller

        try:
            vnum = int(self.args.strip())
        except:
            ch.msg("Invalid vnum format")
            return

        room = get_room(vnum)
        if not room:
            # maybe it only exists in blueprints?
            try:
                del GLOBAL_SCRIPTS.roomdb.vnum[vnum]
                ch.msg(f"Successfully deleted room {vnum}")

            except KeyError:
                ch.msg("There is no such room")
            return
        else:

            if room.db.zone != has_zone(ch):
                ch.msg(
                    "You are not permitted to delete a room not in a zone assigned to you."
                )
                return

            # find all rooms that have exits that come to this room
            # delete those exits, since code only allows connecting rooms
            # within the same zone, this should be relatively low computationally
            # heavy.

            # search for all rooms within zone that has exit defined to this vnum
            for v, data in GLOBAL_SCRIPTS.roomdb.vnum.items():
                if data['zone'] != room.db.zone:
                    continue

                # room is in same zone
                #TODO: update redit mode when deleting current room if you are
                # afgfected by it
                for direction, dest_vnum in data['exits'].items():
                    if dest_vnum == vnum:
                        GLOBAL_SCRIPTS.roomdb.vnum[v]['exits'][direction] = -1
                        ch.msg(f"Removed exit from room: {v}")

                        if v == ch.location.db.vnum:
                            # update current rooms redit mode
                            # reinit current location, in case room was affected by change
                            ch.ndb._redit.__init__(ch, ch.location.db.vnum)
                            # and save
                            ch.ndb._redit.save(override=True)

            # first safely remove blueprint of room
            del GLOBAL_SCRIPTS.roomdb.vnum[vnum]

            # move all contents in room to their 'home' location
            for obj in room.contents:
                obj.move_to(obj.home, quiet=True)
            room.delete()

            ch.msg(f"Successfully deleted room {vnum}")
示例#6
0
    def func(self):
        ch = self.caller
        args = self.args.strip().split()
        obj = ch.ndb._redit.obj

        if has_zone(ch) != obj['zone']:
            ch.msg("You do not have permission to edit this zones room")
            return
        if not args:
            attrs = self.valid_room_attributes.copy()
            attrs[attrs.index('type')] = 'sector'
            keywords = "|n\n*|c".join(attrs)
            ch.msg(
                f'You must provide one of the valid keywords.\n*|c{keywords}')
            return

        keyword = args[0].lower()
        set_str = f"{keyword} set"
        if match_string(keyword, 'name'):
            if len(args) == 1:
                ch.msg("Must supply name for room")
                return
            obj['name'] = " ".join(args[1:]).strip()
            ch.msg(set_str)
            return

        elif match_string(keyword, 'desc'):
            if len(args) > 1:
                obj['desc'] = " ".join(args[1:]).strip()
                ch.msg(set_str)
            else:

                def save_func(_caller, buffer):
                    obj['desc'] = buffer
                    ch.msg(set_str)

                _ = EvEditor(ch,
                             loadfunc=(lambda _: obj['desc']),
                             savefunc=save_func)
            return
        elif match_string(keyword, 'sector'):
            if len(args) > 1:
                sector = args[1].strip()
                if sector not in VALID_ROOM_SECTORS.keys():
                    ch.msg("not a valid room sector")
                    return
                obj['type'] = sector
                return
            else:
                # show all sectors
                sectors = ", ".join(VALID_ROOM_SECTORS.keys())
                msg = f"Sectors:\n{wrap(sectors)}"
                ch.msg(msg)
                return
        elif match_string(keyword, 'edesc'):
            if len(args) > 1:
                ch.msg("set `edesc` without any arguments.")
            else:

                def save_func(_caller, buffer):
                    split = [
                        x.strip() for x in re.split("<(.*)>", buffer.strip())
                        if x
                    ]

                    if len(split) == 1:
                        # key not found
                        ch.msg("Keys must have <..> syntax.")
                        return

                    # uneven key/contents
                    if len(split) % 2 != 0:
                        # last elemet is key without content
                        split.append("n/a")

                    # create dictionary from keys/contents
                    edesc = dict([(k, v)
                                  for k, v in zip(split[::2], split[1::2])])

                    obj['edesc'] = edesc
                    ch.msg(set_str)

                if obj['edesc']:
                    edesc = ""
                    for key, contents in obj['edesc'].items():
                        edesc += f"<{key}>\n{contents}\n"
                else:
                    edesc = "<keyword> contents"
                _ = EvEditor(ch,
                             loadfunc=(lambda _: edesc),
                             savefunc=save_func)
        elif keyword == 'zone':
            ch.msg("You can't set zone this way")
            return
        elif keyword == 'flags':
            if len(args) > 1:
                flag = args[1].strip()
                if flag == 'clear':
                    obj['flags'].clear()

                if flag not in VALID_ROOM_FLAGS:
                    ch.msg("Not a valid room flag")
                    return

                if flag in obj['flags']:
                    obj['flags'].remove(flag)
                    ch.msg(f"{flag} flag removed")
                else:
                    obj['flags'].append(flag)
                    ch.msg(f"{flag} flag applied")

            else:
                # show all foom flags
                flags = wrap(", ".join(VALID_ROOM_FLAGS))
                msg = f"Room Flags:\n{flags}"
                ch.msg(msg)
                return
        elif match_string(keyword, 'exits'):
            if len(args) > 1:
                exit_name = args[1]
                if args[2] == 'clear':
                    exit_vnum = 'clear'
                else:
                    try:
                        exit_vnum = int(args[2])
                    except:
                        ch.msg("That is not a valid vnum")
                        return

                if exit_vnum == 'clear':
                    obj['exits'][exit_name] = -1
                else:
                    # check to see if exit_vnum is a valid vnum
                    if not room_exists(exit_vnum):
                        ch.msg("That room vnum does not exist")
                        return
                    obj['exits'][exit_name] = exit_vnum
                    ch.msg(set_str)

            else:
                ch.msg("Must provide a vnum to the exit")
                return
        else:
            ch.msg("That isn't a valid keyword")
            return