Esempio n. 1
0
def create_room(room_name, character, location, roomtype_key="Generic", roomtype_value="Generic"):
    """
    Create room(if doesn't exist) based on location metadata, 
    attach script to control room state and move player to the room
    """
    rooms = search_object(room_name, typeclass='typeclasses.rooms.Room')

    if not rooms:                                                      # If room doesn't exists
        room = create_object("typeclasses.rooms.Room", key=room_name)  # then create room
        logger.log_info("Room %s Created" % room)
    else:
        room=rooms[0]

    # set room type if changed or new room
    if room.db.roomtype_key != roomtype_key or room.db.roomtype_value != roomtype_value:
        room.db.roomtype_key = roomtype_key
        room.db.roomtype_value = roomtype_value

        if roomtype_key != 'building':  # if outdoors
            room.scripts.add("typeclasses.scripts.Weather")             # attach script to get weather
            room.scripts.add("typeclasses.scripts.Outdoors")            # and attach script to control room state
        
        if roomtype_value == 'library':  # if library
            room.scripts.add('typeclasses.scripts.Library')

        logger.log_info("Room Type Updated to %s: %s" % (room.db.roomtype_key,room.db.roomtype_value))

    if not room.db.location:
        room.db.location = location

    # teleport character to room, if not already in room
    if character.location.name != room_name:
        character.move_to(room, quiet=True)
        logger.log_info("User entered %s" % room_name)
        character.msg("You've entered %s" % room_name)
        character.db.just_entered = False

    elif character.db.just_entered:
        character.msg("You're in %s" % room_name)
        character.db.just_entered = False
Esempio n. 2
0
    def del_callback(self, obj, callback_name, number):
        """
        Delete the specified callback.

        Args:
            obj (Object): the typeclassed object containing the callback.
            callback_name (str): the name of the callback to delete.
            number (int): the number of the callback to delete.

        Raises:
            RuntimeError if the callback is locked.

        """
        obj_callbacks = self.db.callbacks.get(obj, {})
        callbacks = obj_callbacks.get(callback_name, [])

        # If locked, don't edit it
        if (obj, callback_name, number) in self.db.locked:
            raise RuntimeError("this callback is locked.")

        # Delete the callback itself
        try:
            code = callbacks[number]["code"]
        except IndexError:
            return
        else:
            logger.log_info("Deleting callback {} {} of {}:\n{}".format(
                    callback_name, number, obj, code))
            del callbacks[number]

        # Change IDs of callbacks to be validated
        i = 0
        while i < len(self.db.to_valid):
            t_obj, t_callback_name, t_number = self.db.to_valid[i]
            if obj is t_obj and callback_name == t_callback_name:
                if t_number == number:
                    # Strictly equal, delete the callback
                    del self.db.to_valid[i]
                    i -= 1
                elif t_number > number:
                    # Change the ID for this callback
                    self.db.to_valid.insert(i, (t_obj, t_callback_name,
                            t_number - 1))
                    del self.db.to_valid[i + 1]
            i += 1

        # Update locked callback
        for i, line in enumerate(self.db.locked):
            t_obj, t_callback_name, t_number = line
            if obj is t_obj and callback_name == t_callback_name:
                if number < t_number:
                    self.db.locked[i] = (t_obj, t_callback_name, t_number - 1)

        # Delete time-related callbacks associated with this object
        for script in list(obj.scripts.all()):
            if isinstance(script, TimecallbackScript):
                if script.obj is obj and script.db.callback_name == callback_name:
                    if script.db.number == number:
                        script.stop()
                    elif script.db.number > number:
                        script.db.number -= 1
Esempio n. 3
0
    def del_callback(self, obj, callback_name, number):
        """
        Delete the specified callback.

        Args:
            obj (Object): the typeclassed object containing the callback.
            callback_name (str): the name of the callback to delete.
            number (int): the number of the callback to delete.

        Raises:
            RuntimeError if the callback is locked.

        """
        obj_callbacks = self.db.callbacks.get(obj, {})
        callbacks = obj_callbacks.get(callback_name, [])

        # If locked, don't edit it
        if (obj, callback_name, number) in self.db.locked:
            raise RuntimeError("this callback is locked.")

        # Delete the callback itself
        try:
            code = callbacks[number]["code"]
        except IndexError:
            return
        else:
            logger.log_info("Deleting callback {} {} of {}:\n{}".format(
                callback_name, number, obj, code))
            del callbacks[number]

        # Change IDs of callbacks to be validated
        i = 0
        while i < len(self.db.to_valid):
            t_obj, t_callback_name, t_number = self.db.to_valid[i]
            if obj is t_obj and callback_name == t_callback_name:
                if t_number == number:
                    # Strictly equal, delete the callback
                    del self.db.to_valid[i]
                    i -= 1
                elif t_number > number:
                    # Change the ID for this callback
                    self.db.to_valid.insert(
                        i, (t_obj, t_callback_name, t_number - 1))
                    del self.db.to_valid[i + 1]
            i += 1

        # Update locked callback
        for i, line in enumerate(self.db.locked):
            t_obj, t_callback_name, t_number = line
            if obj is t_obj and callback_name == t_callback_name:
                if number < t_number:
                    self.db.locked[i] = (t_obj, t_callback_name, t_number - 1)

        # Delete time-related callbacks associated with this object
        for script in list(obj.scripts.all()):
            if isinstance(script, TimecallbackScript):
                if script.obj is obj and script.db.callback_name == callback_name:
                    if script.db.number == number:
                        script.stop()
                    elif script.db.number > number:
                        script.db.number -= 1
Esempio n. 4
0
    def func(self):
        "Implement function using the Msg methods"
        # todo: Add admin "Player" paging

        caller = self.caller

        if not self.args:
            if len(caller.db.last_paged) > 0:
                names = []
                for target in caller.db.last_paged:
                    names.append(target.name)
                self.msg("You last paged {c%s{n." % ", ".join(names))
            else:
                self.msg("You haven't paged anyone, yet.")
            return

        if not self.rhs:
            if len(caller.db.last_paged) > 0:
                targets = caller.db.last_paged
            else:
                self.msg("You haven't paged anyone, yet.")
                return
        else:
            targets = []
            problems = []
            for target in set(self.lhslist):
                character = caller.search(target, global_search=True)
                if character is None:
                    problems.append("%s is not a valid character." % target)
                    continue
                if not character.access(caller, 'msg'):
                    problems.append("You are not allowed to page %s." % character.name)
                    continue
                if not hasattr(character, 'sessions') and not character.sessions:
                    problems.append("%s is offline." % character.name)
                    continue
                targets.append(character)
            if problems and targets:
                self.msg("\n".join(problems))

        if not targets:
            self.msg("No one found to page.")
            return

        msg = self.rhs

        multipage = None
        if len(targets) > 1:
            names = []
            for target in targets:
                names.append("{c%s{n" % target.name)
            multipage = ", ".join(names)

        # if message begins with a :, we assume it is a 'page-pose'
        if msg.startswith(":"):
            oheader = "From afar,"
            iheader = "Long distance to"
            if multipage is not None:
                oheader = "%s to (%s)" % (oheader, multipage)
                iheader = "%s (%s)" % (iheader, multipage)
            else:
                iheader = "%s {c%s{n" % (iheader, targets[0].name)
            message = ": {c%s{n(%s) %s" % (caller.name, caller.dbref, msg.strip(':').strip())
        elif msg.startswith(";"):
            oheader = "From afar,"
            iheader = "Long distance to"
            if multipage is not None:
                oheader = "%s to (%s)" % (oheader, multipage)
                iheader = "%s (%s)" % (iheader, multipage)
            else:
                iheader = "%s {c%s{n" % (iheader, targets[0].name)
            message = ": {c%s{n(%s)%s" % (caller.name, caller.dbref, msg.strip(';').strip())
        else:
            if multipage is not None:
                oheader = "To (%s), {c%s{n(%s) pages: %s" % (multipage, caller.name, caller.dbref, msg)
                iheader = "You paged (%s): %s" % (multipage, msg)
            else:
                oheader = "{c%s{n(%s) pages: %s" % (caller.name, caller.dbref, msg)
                iheader = "You paged {c%s{n with '%s'" % (targets[0].name, msg)
            message = ""

        # send the messages to their destinations

       
        logger.log_info("%s" % (caller == targets[0]))
        logger.log_info("%s\n%s" % (caller.__dict__, targets[0].__dict__))
        caller.msg("%s%s" % (iheader, message))
        for target in targets:
            target.msg("%s%s" % (oheader, message))
        # save the last paged
        caller.db.last_paged = targets