Ejemplo n.º 1
0
        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
Ejemplo n.º 2
0
    def func(self):
        ch = self.caller
        if not self.args:
            ch.msg("What do you want to remove?")
            return

        obj_name = self.args.strip()

        success_remove = False
        for obj in ch.contents:
            if is_equippable(obj) and is_worn(obj) and not is_cursed(obj):
                # equipment
                if obj_name == 'all':
                    ch.equipment.remove(obj)
                    success_remove = True
                elif match_name(obj_name, obj):
                    ch.equipment.remove(obj)
                    return

            elif is_wieldable(obj) and is_wielded(obj) and not is_cursed(obj):
                # weapon
                if obj_name == 'all':
                    ch.equipment.unwield(obj)
                    success_remove = True

                elif match_name(obj_name, obj):
                    ch.equipment.unwield(obj)
                    return

        if not success_remove:
            ch.msg("You can't remove that")
Ejemplo n.º 3
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.")
Ejemplo n.º 4
0
        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
Ejemplo n.º 5
0
    def func(self):
        ch = self.caller

        if not self.args:
            ch.msg("What do you want to wield?")
            return

        args = self.args.strip()
        for obj in ch.contents:
            if is_wieldable(obj) and not is_wielded(obj):
                # potential candidate
                if match_name(args, obj):
                    # match
                    ch.equipment.wield(obj)
                    return

        ch.msg("You couldn't find anything like that to wield.")
Ejemplo n.º 6
0
    def func(self):
        ch = self.caller

        if not self.args:
            ch.msg("What do you want to wear?")
            return

        args = self.args.strip()
        if args == 'all':
            for obj in ch.contents:
                if is_equippable(
                        obj) and not is_worn(obj) and not is_weapon(obj):
                    ch.equipment.add(obj)
            return
        for obj in ch.contents:
            if is_equippable(obj) and not is_worn(obj) and not is_weapon(obj):
                # this object is a potential candidate
                if match_name(args, obj):
                    # we have a match!
                    ch.equipment.add(obj)
                    return
        ch.msg("You couldn't find anything like that to wear")
Ejemplo n.º 7
0
    def func(self):
        """Implement command"""

        ch = self.caller
        args = self.args.strip()

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

        def success_drop(obj):
            # remove obj weight to characters carry rating
            ch.attrs.change_vital('carry', by=-obj.db.weight)
            act("$n drops $p", True, True, ch, obj, None, Announce.ToRoom)
            act("You drop $p", True, True, ch, obj, None, Announce.ToChar)

        if "." in args:
            pos, obj_name = args.split('.')
            do_all = False
            if pos == 'all':
                do_all = True
            else:
                try:
                    pos = int(pos)
                except:
                    ch.msg("pos must be a valid integer")
                    return

            # handles dot notation
            cntr = 1
            for obj in ch.contents:
                if is_equipped(obj):
                    continue
                if match_name(obj_name, obj):
                    if do_all:
                        # match
                        if can_drop(ch, obj):
                            obj.move_to(ch.location, quiet=True)
                            success_drop(obj)
                        else:
                            ch.msg("You can't drop that.")
                        continue

                    if cntr == pos:
                        # match
                        if can_drop(ch, obj):
                            obj.move_to(ch.location, quiet=True)
                            success_drop(obj)
                        else:
                            ch.msg("You can't drop that.")

                    cntr += 1

        else:
            for obj in ch.contents:
                if is_equipped(obj):
                    continue

                if args == 'all':
                    if can_drop(ch, obj):
                        obj.move_to(ch.location, quiet=True)
                        success_drop(obj)

                    else:
                        act("You can't drop $p", False, False, ch, obj, None,
                            Announce.ToChar)
                    continue

                elif match_name(args, obj):
                    if can_drop(ch, obj):
                        obj.move_to(ch.location, quiet=True)
                        success_drop(obj)
                        return
                    else:
                        act("You can't drop $p", False, False, ch, obj, None,
                            Announce.ToChar)
                        return
Ejemplo n.º 8
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
Ejemplo n.º 9
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.")