示例#1
0
文件: builder.py 项目: j3b4/Mutiny
    def func(self):
        usage = "@raise lat,lon = Room Name"
        caller = self.caller

        if "," in self.lhs:
            for coord in self.lhslist:
                try:
                    int(coord)
                except ValueError:
                    usage = "\nOnly integers allowed"
                    usage += " for lat, lon.\n"
                    usage += " For example: @raise -17,177 = Fiji"
                    caller.msg(usage)
                    return
            lat, lon = self.lhslist  # `self.lhs` split into list by comma.
        else:
            caller.msg(usage)
            return

        # convert coordinates to int
        coordinates = (int(lat), int(lon))

        # search for matching coordinates in db
        conflict = search.search_object_attribute(key="coordinates",
                                                  value=coordinates)
        if conflict:
            report = "There is already a room at %s: %s"
            report += "\n%s is accessible as %s"
            report = report % (coordinates, conflict,
                               conflict[0].name, conflict[0].dbref)
            caller.msg(report)
            return

        # choose the typeclass
        if "inland" in self.switches:
            typeclass = "rooms.DryLandRoom"
            room = "Inland"
        else:
            typeclass = "rooms.CoastalRoom"
            room = "Coastline"

        # over write the default name if name was provided
        if self.rhs:
            room = self.rhs

        # create a room
        lockstring = "control:id(%s) or perm(Immortals); delete:id(%s)"
        lockstring += " or perm(Wizards); edit:id(%s) or perm(Wizards)"
        lockstring = lockstring % (caller.dbref, caller.dbref, caller.dbref)

        new_room = create.create_object(typeclass, room, report_to=caller)
        new_room.locks.add(lockstring)
        new_room.db.coordinates = coordinates  # save those coordinates
        room_string = "Created room %s(%s) of type %s." % (new_room,
                                                           new_room.dbref,
                                                           typeclass)
        caller.msg(room_string)
        if new_room and ('teleport' in self.switches
                         or "tel" in self.switches):
            caller.move_to(new_room)
示例#2
0
文件: builder.py 项目: cn591/muddery
def build_details(model_name, caller=None):
    """
    Build details of a model.

    Args:
        model_name: (string) The name of the data model.
        caller: (command caller) If provide, running messages will send to the caller.
    """

    model_detail = apps.get_model(settings.WORLD_DATA_APP, model_name)

    # Remove all details
    objects = search.search_object_attribute(key="details")
    for obj in objects:
        obj.attributes.remove("details")

    # Set details.
    count = 0
    for record in model_detail.objects.all():
        location_objs = utils.search_obj_data_key(record.location)

        # Detail's location.
        for location in location_objs:
            for name in record.name.split(";"):
                location.set_detail(name, record.desc)

            count += 1

    ostring = "Set %d detail(s)." % count
    print(ostring)
    if caller:
        caller.msg(ostring)
示例#3
0
def build_details(model_name, caller=None):
    """
    Build details of a model.

    Args:
        model_name: (string) The name of the data model.
        caller: (command caller) If provide, running messages will send to the caller.
    """

    model_detail = get_model(settings.WORLD_DATA_APP, model_name)

    # Remove all details
    objects = search.search_object_attribute(key="details")
    for obj in objects:
        obj.attributes.remove("details")

    # Set details.
    count = 0
    for record in model_detail.objects.all():
        location_objs = utils.search_obj_info_key(record.location)

        # Detail's location.
        for location in location_objs:
            for name in record.name.split(";"):
                location.set_detail(name, record.desc)

            count += 1

    ostring = "Set %d detail(s)." % count
    print(ostring)
    if caller:
        caller.msg(ostring)
示例#4
0
    def at_desc(self, looker=None):
        """
        I'd love to also maybe show how many items each character has incinerated too, I tried using the source_location arg of at_obj_received in incinerator, but it gets the room, not the player who gave the item.
        """
        cursed = search_object_attribute(key="cursed",
                                         category=None,
                                         value="true")
        cursedList = []
        for item in cursed:
            cursedList.append(item.name)
        cursedCount = len(cursedList)
        cursedNames = "\n \t".join(cursedList)
        arts = search_object_attribute(key="artwork",
                                       category=None,
                                       value="true")
        artsList = []
        for item in arts:
            artsList.append(item.name)
        artsCount = len(artsList)
        artsNames = "\n \t".join(artsList)
        cnt_omit = Object.objects.filter(
            db_typeclass_path=
            "typeclasses.rooms.DefaultRoom, typeclasses.hybrid_room.HybridRoom, typeclasses.exits.Exit"
        ).count()
        cnt_all = ObjectDB.objects.all().count()
        cnt = cnt_all - cnt_omit
        signtext = "|355    ___  ___    _ ___ ___ _____   ___ _  _ ___  _____  __ \n  / _ \|| _ )_ || || __/ __||_   _|| ||_ _|| \|| ||   \|| __\ \/ / \n || (_) || _ \ |||| || _|| (__  || ||    || |||| .` || ||) || _|| >  <\n  \\___/||___/\__/||___\___|| ||_||   ||___||_||\_||___/||___/_/\_\     |n"
        countertext = "There are currently {count} items in Zone 25. Maximum count is 1000 items.".format(
            count=cnt)
        warningtext = " "
        breakdowntext = "\n \n|555CITIZENS AND BELONGINGS:|n"
        for x in Character.objects.all():
            breakdowntext += "\n |035" + "{x}|n".format(x=x)
            for i in x.contents:
                breakdowntext += "\n \t |555{i}|n".format(i=i)
        if cnt > 1000:
            overcount = 1000 - cnt
            warningtext = "|500Warning, Zone 25 is now {overcount} item(s) over allowed limits.|n".format(
                overcount=overcount)
        self.db.readable_text = signtext + "\n" + countertext + "\n" + warningtext + breakdowntext + "\n|044Masterpeices: {artsCount}".format(
            artsCount=artsCount
        ) + "\n \t" + artsNames + "\n|500Cursed Objects: {cursedCount}".format(
            cursedCount=cursedCount
        ) + "\n \t" + cursedNames + "|n" + "\n" + "Check your own inventory at any time with |555inv|n."

        self.db.desc = self.db.readable_text
        super().at_desc(looker)
示例#5
0
    def func(self):
        usage = "@raise lat,lon = Room Name"
        caller = self.caller

        if "," in self.lhs:
            for coord in self.lhslist:
                try:
                    int(coord)
                except ValueError:
                    usage = "\nOnly integers allowed"
                    usage += " for lat, lon.\n"
                    usage += " For example: @raise -17,177 = Fiji"
                    caller.msg(usage)
                    return
            lat, lon = self.lhslist  # `self.lhs` split into list by comma.
        else:
            caller.msg(usage)
            return

        # convert coordinates to int
        coordinates = (int(lat), int(lon))

        # search for matching coordinates in db
        conflict = search.search_object_attribute(key="coordinates",
                                                  value=coordinates)
        if conflict:
            report = "There is already a room at %s: %s"
            report += "\n%s is accessible as %s"
            report = report % (coordinates, conflict, conflict[0].name,
                               conflict[0].dbref)
            caller.msg(report)
            return

        # choose the typeclass
        if "inland" in self.switches:
            typeclass = "rooms.DryLandRoom"
            room = "Inland"
        else:
            typeclass = "rooms.CoastalRoom"
            room = "Coastline"

        # over write the default name if name was provided
        if self.rhs:
            room = self.rhs

        # create a room
        lockstring = "control:id(%s) or perm(Immortals); delete:id(%s)"
        lockstring += " or perm(Wizards); edit:id(%s) or perm(Wizards)"
        lockstring = lockstring % (caller.dbref, caller.dbref, caller.dbref)

        new_room = create.create_object(typeclass, room, report_to=caller)
        new_room.locks.add(lockstring)
        new_room.db.coordinates = coordinates  # save those coordinates
        room_string = "Created room %s(%s) of type %s." % (
            new_room, new_room.dbref, typeclass)
        caller.msg(room_string)
        if new_room and ('teleport' in self.switches
                         or "tel" in self.switches):
            caller.move_to(new_room)
示例#6
0
def search_obj_info_model(model):
    """
    Search objects which have the given model.

    Args:
    model: (string) Data model's name.
    """
    obj = search.search_object_attribute(key="model", strvalue=model, category=settings.WORLD_DATA_INFO_CATEGORY)
    return obj
示例#7
0
文件: utils.py 项目: muddery/muddery
def search_obj_unique_type(type):
    """
    Search objects which have the given unique type.

    Args:
        type: (string) unique object's type.
    """
    obj = search.search_object_attribute(key="type", strvalue=type, category=settings.DATA_KEY_CATEGORY)
    return obj
示例#8
0
def search_obj_unique_type(type):
    """
    Search objects which have the given unique type.

    Args:
        type: (string) unique object's type.
    """
    obj = search.search_object_attribute(key="type", strvalue=type, category=settings.DATA_KEY_CATEGORY)
    return obj
示例#9
0
def search_obj_data_key(key):
    """
    Search objects which have the given key.

    Args:
        key: (string) Data's key.
    """
    if not key:
        return None

    return search.search_object_attribute(key="key", strvalue=key, category=settings.DATA_KEY_CATEGORY)
示例#10
0
文件: utils.py 项目: muddery/muddery
def search_obj_data_key(key):
    """
    Search objects which have the given key.

    Args:
        key: (string) Data's key.
    """
    if not key:
        return None

    return search.search_object_attribute(key="key", strvalue=key, category=settings.DATA_KEY_CATEGORY)
示例#11
0
def search_obj_info_model(model):
    """
    Search objects which have the given model.

    Args:
    model: (string) Data model's name.
    """
    obj = search.search_object_attribute(
        key="model",
        strvalue=model,
        category=settings.WORLD_DATA_INFO_CATEGORY)
    return obj
示例#12
0
def search_obj_info_key(key):
    """
    Search objects which have the given key.

    Args:
    key: (string) Data info key.
    """
    if not key:
        return None

    obj = search.search_object_attribute(key="key", strvalue=key, category=settings.WORLD_DATA_INFO_CATEGORY)
    return obj
示例#13
0
def search_obj_info_key(key):
    """
    Search objects which have the given key.

    Args:
    key: (string) Data info key.
    """
    if not key:
        return None

    obj = search.search_object_attribute(
        key="key", strvalue=key, category=settings.WORLD_DATA_INFO_CATEGORY)
    return obj
示例#14
0
 def func(self):
     "Ask the globe module to look in the atlas:"
     position = self.args
     if not position:
         print "usage: fix <x,y>"
         return
     print position, type(position)
     # must send a tuple to the globe module
     position = map(int, position.split(','))
     position = tuple(position)
     # "Find the room by searching the DB for an object"
     # "With the correct position attribute."
     room = search.search_object_attribute(key="coordinates",
                                           value=position)
     self.caller.msg(room)
示例#15
0
文件: vessel.py 项目: j3b4/Mutiny
    def arrive_at(self, position):
        """
        # The following code moves an object to a new position and room that
        # matches that position.
        """
        vessel = self

        # Check the arguments to make sure vessel is a vessel and
        # position is a position

        # Look up room in teh entier DB
        if position:
            room = search.search_object_attribute(key="coordinates", value=position)
        else:
            string = "position: %s" % str(position)
            self.msg_contents(string)
            return
        # move to room
        if room:
            # If the destination room exists, we go there.
            vessel.msg_contents("%s already exists." % room)
            room = room[0]
            # TODO: fix this^ throw on multimatch rooms there should only
            # ever be one room per coordinates
            # unless it is dry land
            if inherits_from(room, "typeclasses.rooms.DryLandRoom"):
                vessel.msg_contents("It's dry land so cancelling move.")
                return
            # but if not dry land
            # ... lets get on with it and move
            else:
                vessel.msg_contents("Moving to %s" % room)
                vessel.move_to(room)
                return
        elif vessel.location.is_typeclass("rooms.DynamicRoom") and len(vessel.location.contents) == 1:
            # This means we are in a dynamic room alone
            vessel.msg_contents("updating room coordinates to %s" % str(position))
            vessel.location.db.coordinates = position
            # have to update vessel position to match rooms new position
            vessel.db.position = position
            return
        else:  # Assume the current room is occupied or not dynamic
            # create the room
            vessel.msg_contents("Creating new room at %s" % str(position))
            room = create_object(typeclass="rooms.DynamicRoom", key="The Open Ocean", location=None)
            room.db.coordinates = position
            vessel.msg_contents("Moving to %s" % room)
            vessel.move_to(room)
            return

        def make_way(self, course):
            old_position = self.db.position
            position = move_vector(old_position, course)
            self.msg_contents("New position = %s" % str(position))
            self.arrive_at(self, position)

        def at_tick(self):
            """
            All floating objects move every tick unless anchored/moored.
            So at tick, we calculate course and make_way
            """
            pass
示例#16
0
文件: utils.py 项目: muddery/muddery
def search_db_data_type(key, value, typeclass):
    """
    Search objects of the given typeclass which have the given value.
    """
    objs = search.search_object_attribute(key=key, value=value)
    return [obj for obj in objs if obj.is_typeclass(typeclass, exact=False)]
示例#17
0
文件: builder.py 项目: j3b4/Mutiny
    def func(self):
        caller = self.caller
        location = caller.location
        old_coord = location.db.coordinates  # lat,lon of starting room
        if not old_coord:
            string = ("%s has no coordinates we cannot use 'walk' from here")
            string = string % location
            caller.msg(string)
            return
        "Implements the walk command"
        if not self.args or not self.lhs:
            string = "Usage: @walk[/switch] <direction> "
            string += "[= roomname]"
            self.caller.msg(string)
            return
        if self.lhs not in self.directions:
            string = "@walk only works in the following directions: %s."
            string = string % ",".join(sorted(self.directions.keys()))
            string += "\n(use @dig or @raise for more freedom)"
            self.caller.msg(string)
            return
        # retrieve all input and parse it
        sd = self.directions
        ex = self.lhs
        exname, back = sd[ex][0], sd[ex][1]
        backname = sd[back][0]
        string = "backname = %s" % backname
        vector = sd[ex][2]
        # caller.msg("Vector for %s is %s" % (ex, vector))
        caller.msg(string)
        string = ""

        # calculate location of new_coord for new room
        new_coord = (old_coord[0] + vector[0],
                     old_coord[1] + vector[1])

        # search for matching coordinates in db
        conflict = search.search_object_attribute(key="coordinates",
                                                  value=new_coord)
        if conflict:
            report = "There is already a room at %s: %s"
            report += "\n%s is accessible as %s"
            report = report % (new_coord, conflict,
                               conflict[0].name, conflict[0].dbref)
            report += "\nSo you can delete it now then re-run this"
            report += "command, or just try to link to it.\n"
            report += "Automating this is on my todo list."
            caller.msg(report)
            return

        # find the backwards exit from the directions
        # backstring = ", %s;%s" % (backname, back)

        # choose the typeclass
        if "inland" in self.switches:
            typeclass_path = "rooms.DryLandRoom"
            roomname = "Inland"
        elif "coast" in self.switches:
            typeclass_path = "rooms.CoastalRoom"
            roomname = "Coastline"
        else:
            # no switches  default type and name of start room
            # but name can be over written
            typeclass_path = location.typeclass_path
            roomname = location.name

        # name the new room
        if self.rhs:
            roomname = self.rhs  # this may include aliases; that's fine.

        # create room
        lockstring = "control:id(%s) or perm(Immortals); delete:id(%s) "
        lockstring += "or perm(Wizards); edit:id(%s) or perm(Wizards)"
        lockstring = lockstring % (caller.dbref, caller.dbref, caller.dbref)
        new_room = create.create_object(typeclass_path, roomname,
                                        report_to=caller)

        # lock the room after creation
        new_room.locks.add(lockstring)

        # add the coordinates
        new_room.db.coordinates = new_coord

        room_string = "Created room %s(%s) of type %s." % (
            new_room, new_room.dbref, typeclass_path)

        # create exit to room
        # Build the exit to the new room from the current one
        xtc = settings.BASE_EXIT_TYPECLASS

        new_to_exit = create.create_object(xtc, exname,
                                           location,
                                           aliases=ex[0],
                                           locks=lockstring,
                                           destination=new_room,
                                           report_to=caller)
        alias_string = ""
        exit_to_string = "\nCreated Exit from %s to %s: %s(%s)%s."
        exit_to_string = exit_to_string % (location.name,
                                           new_room.name,
                                           new_to_exit,
                                           new_to_exit.dbref,
                                           alias_string)
        # Create exit back from new room
        # Building the exit back to the current room
        if not location:
            exit_back_string = \
                "\nYou cannot create an exit back to a None-location."
        else:
            typeclass = settings.BASE_EXIT_TYPECLASS
            new_back_exit = create.create_object(typeclass,
                                                 backname,
                                                 new_room,
                                                 aliases=back,
                                                 locks=lockstring,
                                                 destination=location,
                                                 report_to=caller)
            alias_string = ""
            exit_back_string = "\nCreated Exit back from %s to %s: %s(%s)%s."
            exit_back_string = exit_back_string % (new_room.name,
                                                   location.name,
                                                   new_back_exit,
                                                   new_back_exit.dbref,
                                                   alias_string)
        caller.msg("%s%s%s" % (room_string, exit_to_string, exit_back_string))
        if new_room and ('still' not in self.switches):
            caller.move_to(new_room)
示例#18
0
    def func(self):
        caller = self.caller
        location = caller.location
        old_coord = location.db.coordinates  # lat,lon of starting room
        if not old_coord:
            string = ("%s has no coordinates we cannot use 'walk' from here")
            string = string % location
            caller.msg(string)
            return
        "Implements the walk command"
        if not self.args or not self.lhs:
            string = "Usage: @walk[/switch] <direction> "
            string += "[= roomname]"
            self.caller.msg(string)
            return
        if self.lhs not in self.directions:
            string = "@walk only works in the following directions: %s."
            string = string % ",".join(sorted(self.directions.keys()))
            string += "\n(use @dig or @raise for more freedom)"
            self.caller.msg(string)
            return
        # retrieve all input and parse it
        sd = self.directions
        ex = self.lhs
        exname, back = sd[ex][0], sd[ex][1]
        backname = sd[back][0]
        string = "backname = %s" % backname
        vector = sd[ex][2]
        # caller.msg("Vector for %s is %s" % (ex, vector))
        caller.msg(string)
        string = ""

        # calculate location of new_coord for new room
        new_coord = (old_coord[0] + vector[0], old_coord[1] + vector[1])

        # search for matching coordinates in db
        conflict = search.search_object_attribute(key="coordinates",
                                                  value=new_coord)
        if conflict:
            report = "There is already a room at %s: %s"
            report += "\n%s is accessible as %s"
            report = report % (new_coord, conflict, conflict[0].name,
                               conflict[0].dbref)
            report += "\nSo you can delete it now then re-run this"
            report += "command, or just try to link to it.\n"
            report += "Automating this is on my todo list."
            caller.msg(report)
            return

        # find the backwards exit from the directions
        # backstring = ", %s;%s" % (backname, back)

        # choose the typeclass
        if "inland" in self.switches:
            typeclass_path = "rooms.DryLandRoom"
            roomname = "Inland"
        elif "coast" in self.switches:
            typeclass_path = "rooms.CoastalRoom"
            roomname = "Coastline"
        else:
            # no switches  default type and name of start room
            # but name can be over written
            typeclass_path = location.typeclass_path
            roomname = location.name

        # name the new room
        if self.rhs:
            roomname = self.rhs  # this may include aliases; that's fine.

        # create room
        lockstring = "control:id(%s) or perm(Immortals); delete:id(%s) "
        lockstring += "or perm(Wizards); edit:id(%s) or perm(Wizards)"
        lockstring = lockstring % (caller.dbref, caller.dbref, caller.dbref)
        new_room = create.create_object(typeclass_path,
                                        roomname,
                                        report_to=caller)

        # lock the room after creation
        new_room.locks.add(lockstring)

        # add the coordinates
        new_room.db.coordinates = new_coord

        room_string = "Created room %s(%s) of type %s." % (
            new_room, new_room.dbref, typeclass_path)

        # create exit to room
        # Build the exit to the new room from the current one
        xtc = settings.BASE_EXIT_TYPECLASS

        new_to_exit = create.create_object(xtc,
                                           exname,
                                           location,
                                           aliases=ex[0],
                                           locks=lockstring,
                                           destination=new_room,
                                           report_to=caller)
        alias_string = ""
        exit_to_string = "\nCreated Exit from %s to %s: %s(%s)%s."
        exit_to_string = exit_to_string % (location.name, new_room.name,
                                           new_to_exit, new_to_exit.dbref,
                                           alias_string)
        # Create exit back from new room
        # Building the exit back to the current room
        if not location:
            exit_back_string = \
                "\nYou cannot create an exit back to a None-location."
        else:
            typeclass = settings.BASE_EXIT_TYPECLASS
            new_back_exit = create.create_object(typeclass,
                                                 backname,
                                                 new_room,
                                                 aliases=back,
                                                 locks=lockstring,
                                                 destination=location,
                                                 report_to=caller)
            alias_string = ""
            exit_back_string = "\nCreated Exit back from %s to %s: %s(%s)%s."
            exit_back_string = exit_back_string % (
                new_room.name, location.name, new_back_exit,
                new_back_exit.dbref, alias_string)
        caller.msg("%s%s%s" % (room_string, exit_to_string, exit_back_string))
        if new_room and ('still' not in self.switches):
            caller.move_to(new_room)
示例#19
0
def search_db_data_type(key, value, typeclass):
    """
    Search objects of the given typeclass which have the given value.
    """
    objs = search.search_object_attribute(key=key, value=value)
    return [obj for obj in objs if obj.is_typeclass(typeclass, exact=False)]
示例#20
0
    def arrive_at(self, position):
        '''
        # The following code moves an object to a new position and room that
        # matches that position.
        '''
        vessel = self

        # Check the arguments to make sure vessel is a vessel and
        # position is a position

        # Look up room in teh entier DB
        if position:
            room = search.search_object_attribute(key="coordinates",
                                                  value=position)
        else:
            string = "position: %s" % str(position)
            self.msg_contents(string)
            return
        # move to room
        if room:
            # If the destination room exists, we go there.
            vessel.msg_contents("%s already exists." % room)
            room = room[0]
            # TODO: fix this^ throw on multimatch rooms there should only
            # ever be one room per coordinates
            # unless it is dry land
            if inherits_from(room, "typeclasses.rooms.DryLandRoom"):
                vessel.msg_contents("It's dry land so cancelling move.")
                return
            # but if not dry land
            # ... lets get on with it and move
            else:
                vessel.msg_contents("Moving to %s" % room)
                vessel.move_to(room)
                return
        elif (vessel.location.is_typeclass("rooms.DynamicRoom")
              and len(vessel.location.contents) == 1):
            # This means we are in a dynamic room alone
            vessel.msg_contents("updating room coordinates to %s" %
                                str(position))
            vessel.location.db.coordinates = position
            # have to update vessel position to match rooms new position
            vessel.db.position = position
            return
        else:  # Assume the current room is occupied or not dynamic
            # create the room
            vessel.msg_contents("Creating new room at %s" % str(position))
            room = create_object(
                typeclass="rooms.DynamicRoom",
                key="The Open Ocean",
                location=None,
            )
            room.db.coordinates = position
            vessel.msg_contents("Moving to %s" % room)
            vessel.move_to(room)
            return

        def make_way(self, course):
            old_position = self.db.position
            position = move_vector(old_position, course)
            self.msg_contents("New position = %s" % str(position))
            self.arrive_at(self, position)

        def at_tick(self):
            '''
            All floating objects move every tick unless anchored/moored.
            So at tick, we calculate course and make_way
            '''
            pass