Beispiel #1
0
    def func(self):
        ch = self.caller
        args = self.args.strip()
        table = self.styled_table("Contents")

        if not args:
            ch.msg("You peek at yourself")
            for obj in ch.contents:
                table.add_row(obj.db.sdesc)

            ch.msg(table)
            return
        for obj in ch.location.contents:
            if is_pc_npc(obj) and match_name(args, obj):
                items = list(obj.contents)
                items.sort(key=lambda x: x.db.sdesc.lower())

                for item in items:
                    if is_worn(item) or is_wielded(item):
                        continue

                    if not can_see_obj(ch, item):
                        continue

                    table.add_row(raw_ansi(item.obj_desc()))
                ch.msg(f"You peek into {get_name(obj)}'s inventory")
                ch.msg(table)
                return
        ch.msg("You couldn't find anyone like that.")
Beispiel #2
0
    def func(self):
        ch = self.caller
        wear_loc = ch.equipment._valid_wear_loc

        # # equipment
        table = self.styled_table(border=None)
        for loc in wear_loc:
            obj = ch.equipment.location[loc.name]
            if is_obj(obj):
                if not can_see_obj(ch, obj):
                    sdesc = "|C<something>|n"
                else:
                    sdesc = obj.obj_desc()
            else:
                sdesc = "|Mnothing|n"
            table.add_row(loc.display_msg, sdesc)

        msg = f"You are using\n{table}"
        ch.msg(msg)
Beispiel #3
0
    def func(self):
        """check inventory"""
        ch = self.caller
        items = list(ch.contents)
        if not items:
            string = "You are not carrying anything."
        else:

            items.sort(key=lambda x: x.db.sdesc.lower())
            table = self.styled_table(border="header")
            for item in items:
                if is_worn(item) or is_wielded(item):
                    continue

                if not can_see_obj(ch, item):
                    sdesc = "<something>"
                else:
                    sdesc = f"{item.obj_desc()}"
                table.add_row("{}|n".format(raw_ansi(sdesc)))
            string = f"|wYou are carrying:\n{table}"
        ch.msg(string)
Beispiel #4
0
    def func(self):
        ch = self.caller

        def success_put(obj, con_obj):
            act("$n puts $p in $P", True, True, ch, obj, con_obj,
                Announce.ToRoom)
            act("You put $p in $P", True, True, ch, obj, con_obj,
                Announce.ToChar)

        def find_container(con_name, pos=None):
            locs = [ch, ch.location]
            for loc in locs:
                if pos is None:
                    # find first container
                    _container = None
                    for obj in loc.contents:
                        if is_container(obj) and match_name(con_name, obj):
                            # match
                            _container = obj
                            return _container
                else:
                    try:
                        pos = int(pos)
                    except:
                        raise ValueError('pos should be a integer value')

                    # find <pos> container
                    cntr = 1
                    _container = None
                    for obj in loc.contents:
                        if is_container(obj) and match_name(con_name, obj):
                            if cntr == con_pos:
                                # match container
                                _container = obj
                                return _container
                            cntr += 1

        def find_obj(obj_name, pos=None):
            # get all objects
            if pos is None and obj_name == 'all':
                # simple return all contents that isn't container type
                matched_objs = []

                for obj in ch.contents:
                    if is_container(obj) or is_equipped(obj):
                        continue
                    matched_objs.append(obj)
                return matched_objs

            # put book in bag
            elif pos is None:
                for obj in ch.contents:
                    if not is_container(obj) and match_name(
                            obj_name, obj) and not is_equipped(obj):
                        return make_iter(obj)
                return None

            # put all.book in bag
            elif pos == 'all':
                matched_objs = []
                for obj in ch.contents:
                    if not is_container(obj) and match_name(
                            obj_name, obj) and not is_equipped(obj):
                        matched_objs.append(obj)
                return matched_objs

            else:
                # get <pos> of matching name
                cntr = 1
                for obj in ch.contents:
                    if not is_container(obj) and match_name(
                            obj_name, obj) and not is_equipped(obj):
                        if cntr == pos:
                            return make_iter(obj)
                        cntr += 1
                return None

        args = self.args.strip().split()
        if not args or len(args) != 3:
            ch.msg("Put what in what?")
            return

        obj_name, _filler, container = args
        if _filler != 'in':
            ch.msg("You must speicify `in`")
            return

        all_objs = False
        obj_pos = con_pos = None

        obj_pos, obj_name = parse_dot_notation(obj_name)
        if obj_pos == 'all':
            all_objs = True

        con_pos, container = parse_dot_notation(container)

        if not obj_pos and not con_pos:
            _container = find_container(container)
            objs = find_obj(obj_name)
            if not _container:
                ch.msg("You couldn't find such container")
                return
            if not objs:
                ch.msg("You couldn't find such item")
                return

            for obj in objs:
                if not can_see_obj(ch,
                                   obj) or is_equipped(obj) or is_cursed(obj):
                    ch.msg("You can't do that.")
                    continue

                if can_contain_more(_container):
                    obj.move_to(_container)
                    success_put(obj, _container)
                else:
                    ch.msg("You can't fit anymore items in there.")

            return

        # obj=all.<obj>
        _container = find_container(container, pos=con_pos)
        if not _container:
            ch.msg("You could't find that container.")
            return

        pos = 'all' if all_objs else obj_pos

        objs = find_obj(obj_name, pos=pos)
        if not objs:
            ch.msg("You can't find anything like that.")
            return

        for obj in objs:
            if not can_see_obj(ch, obj) or is_cursed(obj):
                ch.msg("You can't do that.")
                continue
            if can_contain_more(_container):
                obj.move_to(_container)
                success_put(obj, _container)
            else:
                ch.msg("You can't fit anymore items in there.")
        return
Beispiel #5
0
    def func(self):
        ch = self.caller
        location = ch.location
        if not self.args:
            if not self:
                ch.msg("You have no location to look at!")
                return

            room_msg = ""

            # get room title
            room_msg += f"|c{location.db.name}|n\n"

            #get room_desc
            room_msg += f"|G{location.db.desc}|n\n\n"

            # get room exits
            room_msg += "|C[ Exits: "
            for direction, dvnum in location.db.exits.items():
                if dvnum < 0:
                    continue  # not set

                room_msg += f"|lc{direction}|lt{direction}|le "
            room_msg += "]|n\n\n"

            # get room contents
            # get objects
            for obj in sorted(location.contents,
                              key=lambda x: x.db.look_index):
                if is_pc(obj):
                    if obj.id == ch.id:
                        continue
                    room_msg += f"{obj.name.capitalize()}{obj.attrs.title.value} is {obj.attrs.position.value.name.lower()} here\n"

                elif is_npc(obj) and can_see_obj(ch, obj):
                    room_msg += f"{obj.db.ldesc}\n"

                elif is_obj(obj):
                    if is_invis(obj) and not can_see_obj(ch, obj):
                        ch.msg("Couldn't see")
                        continue
                    else:
                        room_msg += f"{obj.obj_desc(ldesc=True)}\n"
            ch.msg(room_msg)
            return

        args = self.args.strip().split()
        # attempt to look at something specific in the room

        # try looking for obj in room based on name or aliases

        if len(args) == 1:
            obj_name = args[0]

            # attempt to look for edesc in room itself
            edesc = location.db.edesc
            if obj_name in edesc.keys():
                msg = f"\n\n{rplanguage_parse_string(ch, edesc[obj_name])}"
                evmore.EvMore(ch, msg)
                return
            # look for obj in room
            for obj in ch.location.contents:
                if is_obj(obj):
                    if obj_name in obj.db.name:
                        edesc = rplanguage_parse_string(ch, obj.db.edesc)
                        ch.msg(f"You look at {obj.db.sdesc}\n{edesc}")
                        return
                elif is_npc(obj):
                    if obj_name in obj.db.key:
                        edesc = rplanguage_parse_string(ch, obj.db.edesc)
                        ch.msg(f"You look at {obj.db.sdesc}\n{edesc}")
                        return

                elif is_pc(obj):
                    if obj_name in obj.name:
                        edesc = rplanguage_parse_string(ch, obj.db.desc)
                        ch.msg(f"You look at {obj.full_title()}\n{edesc}")
                        return
            # try looking for an obj in your inventory, if found send back edesc
            for obj in ch.contents:
                if is_equipped(obj):
                    continue
                if match_name(obj_name, obj):
                    edesc = obj.db.edesc
                    if not edesc:
                        ch.msg("You see nothing interesting.")
                    else:
                        edesc = rplanguage_parse_string(ch, edesc)
                        ch.msg(edesc)
                    return
            ch.msg("You don't see anything like that.")
            return

        if len(args) == 2:
            _filler, con_name = args
            if _filler != 'in':
                ch.msg("Supply `in` when looking in a container")
                return
            pos, con_name = parse_dot_notation(con_name)

            cntr = 1
            locs = [ch, ch.location]
            for loc in locs:
                for obj in loc.contents:
                    if not is_container(obj):
                        continue
                    if match_name(con_name, obj) and (cntr == pos or not pos):
                        # found container; display contents, sorted
                        objs = list(obj.contents)
                        objs.sort(key=lambda x: x.db.sdesc.lower())
                        table = self.styled_table(border="header")
                        for item in objs:
                            if not can_see_obj(ch, item):
                                sdesc = "<something>"
                            else:
                                sdesc = f"{item.obj_desc()}"
                            table.add_row("{}|n".format(raw_ansi(sdesc)))
                        extra = "" if not is_pc_npc(
                            loc) else ", that you are holding,"
                        string = f"|w{obj.db.sdesc}{extra} has:\n{table}"
                        ch.msg(string)
                        return
                    cntr += 1
            ch.msg("You couldn't find anything like that.")