コード例 #1
0
ファイル: informative.py プロジェクト: j3b4/scrolls
    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)
コード例 #2
0
ファイル: characters.py プロジェクト: ChrisLR/scrolls
 def location_contents(self):
     objs = []
     for obj in self.location.contents:
         if is_obj(obj):
             objs.append(obj)
     return objs
コード例 #3
0
    def func(self):
        """implements the command."""

        ch = self.caller

        def success_get(obj, con=None):
            # add obj weight to characters carry rating
            ch.attrs.change_vital('carry', by=obj.db.weight)

            if not con:
                act(f"$n picks up a $p.", True, True, ch, obj, None,
                    Announce.ToRoom)
                act(f"You pick up a $p", False, False, ch, obj, None,
                    Announce.ToChar)
            else:
                act(f"$n gets $p from $P", True, True, ch, obj, con,
                    Announce.ToRoom)
                act(f"You get $p from $P", False, False, ch, obj, con,
                    Announce.ToChar)

        if not self.args:
            ch.msg("Get what?")
            return

        args = self.args.strip().split()

        # example of get
        # get all
        # get book
        # get all.book
        # get 1.book from 1.bag
        # get all.book from all.bag
        # get all from chest

        # TODO: refactor this function

        # arg length == get in room
        if len(args) == 1:  #ex: get all.book, get 1.book, get book
            obj_pos, obj_name = parse_dot_notation(args[0])

            #ex: get all
            if obj_name == 'all':
                for obj in ch.location_contents():
                    if can_pickup(ch, obj):
                        obj.move_to(ch, quiet=True)
                        success_get(obj)
                return

            #ex: get all.book, 1.book
            cntr = 1
            got_something = False
            for obj in ch.location_contents():
                if can_pickup(ch, obj):
                    # all.book
                    if obj_pos == 'all' and match_name(obj_name, obj):
                        obj.move_to(ch, quiet=True)
                        success_get(obj)
                        got_something = True
                    # 1.book
                    if match_name(obj_name, obj):
                        if obj_pos == cntr or not obj_pos:
                            obj.move_to(ch, quiet=True)
                            success_get(obj)
                            return
                        cntr += 1
            if not got_something:
                ch.msg("You can't get that.")
            return

        # arg length == getting from a container either on self or in room
        # get 1.book from 1.bag
        # get book from chest  - in room
        elif len(args) == 3:
            obj_name, _filler, con_name = args
            if "from" != _filler:
                ch.msg("must supply `in` when getting from a container")
                return
            obj_pos, obj_name = parse_dot_notation(obj_name)
            con_pos, con_name = parse_dot_notation(con_name)

            locs = [ch.contents, ch.location.contents]

            ####### first find container(s) ################
            matched_containers = []
            for loc in locs:
                cntr = 1
                for obj in loc:
                    if is_container(obj):
                        # all.bag
                        if con_pos == 'all' and match_name(con_name, obj):
                            matched_containers.append(obj)
                        # 2.bag or bag <= first find
                        if match_name(con_name, obj):
                            if con_pos == cntr or not con_pos:
                                matched_containers.append(obj)

            if not matched_containers:
                ch.msg("Could not find that container.")
                return
            #################################################

            ###### find items from container ################
            found_something = False
            for con in matched_containers:
                cntr = 1
                for obj in con.contents:
                    if is_obj(obj):
                        # all.book
                        if obj_pos == 'all' and match_name(
                                obj_name, obj) or obj_name == 'all':
                            obj.move_to(ch, quiet=True)
                            success_get(obj, con)
                            found_something = True
                        elif match_name(obj_name, obj):
                            if obj_pos == cntr or not obj_pos:
                                obj.move_to(ch, quiet=True)
                                success_get(obj, con)
                                return
            if not found_something:
                ch.msg("Could not find that item.")
            return
コード例 #4
0
ファイル: informative.py プロジェクト: j3b4/scrolls
    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.")