示例#1
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()
    CLIENT_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reset default locations
    builder.reset_default_locations()

    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()
示例#2
0
def build_all(caller=None):
    """
    Build all objects in the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Reset object key's info.
    OBJECT_KEY_HANDLER.reload()

    # Build rooms.
    for room_info in settings.WORLD_ROOMS:
        build_objects(room_info, True, caller)

    # Build exits.
    for exit_info in settings.WORLD_EXITS:
        build_objects(exit_info, True, caller)

    # Build objects.
    for object_info in settings.WORLD_OBJECTS:
        build_objects(object_info, True, caller)

    # Build NPCs.
    for npc_info in settings.WORLD_NPCS:
        build_objects(npc_info, True, caller)
示例#3
0
def build_all(caller=None):
    """
    Build all objects in the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Reset object key's info.
    OBJECT_KEY_HANDLER.reload()

    # Build areas.
    build_unique_objects(DATA_SETS.world_areas.objects,
                         DATA_SETS.world_areas.model_name, caller)

    # Build rooms.
    build_unique_objects(DATA_SETS.world_rooms.objects,
                         DATA_SETS.world_rooms.model_name, caller)

    # Build exits.
    build_unique_objects(DATA_SETS.world_exits.objects,
                         DATA_SETS.world_exits.model_name, caller)

    # Build objects.
    build_unique_objects(DATA_SETS.world_objects.objects,
                         DATA_SETS.world_objects.model_name, caller)

    # Build NPCs.
    build_unique_objects(DATA_SETS.world_npcs.objects,
                         DATA_SETS.world_npcs.model_name, caller)
示例#4
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reset default locations
    builder.reset_default_locations()
    
    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()
示例#5
0
def build_all(caller=None):
    """
    Build all objects in the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    print("build_all")

    # Reset object key's info.
    OBJECT_KEY_HANDLER.reload()

    # Build areas.
    build_unique_objects(CM.WORLD_AREAS.all(), "world_areas", caller)

    # Build rooms.
    build_unique_objects(CM.WORLD_ROOMS.all(), "world_rooms", caller)

    # Build exits.
    build_unique_objects(CM.WORLD_EXITS.all(), "world_exits", caller)

    # Build objects.
    build_unique_objects(CM.WORLD_OBJECTS.all(), "world_objects", caller)

    # Build NPCs.
    build_unique_objects(CM.WORLD_NPCS.all(), "world_npcs", caller)
示例#6
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reset default locations
    builder.reset_default_locations()
    
    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # reload skill modules
    MudderySkill.load_skill_modules()
示例#7
0
    def load_data_fields(self):
        """
        Get object's data record from database.
        """
        # Get model and key names.
        key = self.get_data_key()
        if not key:
            return
        
        models = OBJECT_KEY_HANDLER.get_models(key)

        for model in models:
            # Get db model
            model_obj = apps.get_model(settings.WORLD_DATA_APP, model)
            if not model_obj:
                logger.log_errmsg("%s can not open model %s" % (key, model))
                continue

            # Get data record.
            try:
                data = model_obj.objects.get(key=key)
            except Exception, e:
                logger.log_errmsg("%s can not find key %s" % (key, key))
                continue

            # Set data.
            for field in data._meta.fields:
                setattr(self.dfield, field.name, data.serializable_value(field.name))
示例#8
0
    def load_data_fields(self):
        """
        Get object's data record from database.
        """
        # Get model and key names.
        key = self.get_data_key()
        if not key:
            return

        models = OBJECT_KEY_HANDLER.get_models(key)

        for model in models:
            # Get db model
            model_obj = apps.get_model(settings.WORLD_DATA_APP, model)
            if not model_obj:
                logger.log_errmsg("%s can not open model %s" % (key, model))
                continue

            # Get data record.
            try:
                data = model_obj.objects.get(key=key)
            except Exception, e:
                logger.log_errmsg("%s can not find key %s" % (key, key))
                continue

            # Set data.
            for field in data._meta.fields:
                setattr(self.dfield, field.name,
                        data.serializable_value(field.name))
示例#9
0
文件: builder.py 项目: cn591/muddery
def build_object(obj_key, caller=None):
    """
    Build objects of a model.

    Args:
        obj_key: (string) The key of the object.
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # get typeclass model
    model_typeclass = apps.get_model(settings.WORLD_DATA_APP,
                                     settings.TYPECLASSES)

    # Get object's model name.
    record = None
    typeclass = None
    model_names = OBJECT_KEY_HANDLER.get_models(obj_key)
    for model_name in model_names:
        try:
            # Get record.
            model_obj = apps.get_model(settings.WORLD_DATA_APP, model_name)
            record_obj = model_obj.objects.get(key=obj_key)
            typeclass = model_typeclass.objects.get(key=record_obj.typeclass)
            record = record_obj
            break
        except Exception, e:
            continue
示例#10
0
def build_object(obj_key, caller=None):
    """
    Build objects of a model.

    Args:
        obj_key: (string) The key of the object.
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Get object's model name.
    model_name = OBJECT_KEY_HANDLER.get_model(obj_key)
    if not model_name:
        ostring = "Can not find the model of %s." % obj_key
        print(ostring)
        print(traceback.print_exc())
        if caller:
            caller.msg(ostring)
        return

    try:
        # Get record.
        model_obj = get_model(settings.WORLD_DATA_APP, model_name)
        record = model_obj.objects.get(key=obj_key)
    except Exception, e:
        ostring = "Can not load record %s:%s %s" % (model_name, obj_key, e)
        print(ostring)
        print(traceback.print_exc())
        if caller:
            caller.msg(ostring)
        return
示例#11
0
    def match_condition(self, quest_key):
        """
        Check if the quest matches its condition.
        Args:
            quest_key: (string) quest's key

        Returns:
            (boolean) result
        """
        # Get quest's record.
        model_names = OBJECT_KEY_HANDLER.get_models(quest_key)
        if not model_names:
            return False

        for model_name in model_names:
            model_quest = apps.get_model(settings.WORLD_DATA_APP, model_name)

            try:
                record = model_quest.objects.get(key=quest_key)
                return STATEMENT_HANDLER.match_condition(
                    record.condition, self.owner, None)
            except ObjectDoesNotExist:
                continue
            except AttributeError:
                continue

        return True
示例#12
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reload attributes
    CHARACTER_ATTRIBUTES_INFO.reload()
    EQUIPMENT_ATTRIBUTES_INFO.reload()
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    builder.reset_default_locations()

    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()

    # load condition descriptions
    DESC_HANDLER.reload()

    # load honours
    HONOURS_MAPPER.reload()
示例#13
0
def build_all(caller=None):
    """
    Build all objects in the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Reset object key's info.
    OBJECT_KEY_HANDLER.reload()

    # Build rooms.
    build_unique_objects(settings.WORLD_ROOMS, caller)

    # Build exits.
    build_unique_objects(settings.WORLD_EXITS, caller)

    # Build objects.
    build_unique_objects(settings.WORLD_OBJECTS, caller)

    # Build NPCs.
    build_unique_objects(settings.WORLD_NPCS, caller)
示例#14
0
def build_all(caller=None):
    """
    Load csv data and build the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    
    OBJECT_KEY_HANDLER.reload()

    for room_info in settings.WORLD_ROOMS:
        build_objects(room_info, True, caller)

    for exit_info in settings.WORLD_EXITS:
        build_objects(exit_info, True, caller)

    for object_info in settings.WORLD_OBJECTS:
        build_objects(object_info, True, caller)

    for npc_info in settings.WORLD_NPCS:
        build_objects(npc_info, True, caller)
示例#15
0
文件: builder.py 项目: cn591/muddery
def build_all(caller=None):
    """
    Build all objects in the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Reset object key's info.
    OBJECT_KEY_HANDLER.reload()

    # Build rooms.
    build_unique_objects(settings.WORLD_ROOMS, caller)

    # Build exits.
    build_unique_objects(settings.WORLD_EXITS, caller)

    # Build objects.
    build_unique_objects(settings.WORLD_OBJECTS, caller)

    # Build NPCs.
    build_unique_objects(settings.WORLD_NPCS, caller)
示例#16
0
    def set_data_info(self, key):
        """
        Set data_info's model and key. It puts info into attributes.
            
        Args:
            key: (string) Key of the data info.
        """
        model = OBJECT_KEY_HANDLER.get_model(key)
        utils.set_obj_data_info(self, key, model)
        self.load_data()

        # initialize with data
        if self.db.FIRST_CREATE:
            self.set_initial_data()
            del self.db.FIRST_CREATE
示例#17
0
    def set_data_info(self, key):
        """
        Set data_info's model and key. It puts info into attributes.
            
        Args:
            key: (string) Key of the data info.
        """
        model = OBJECT_KEY_HANDLER.get_model(key)
        utils.set_obj_data_info(self, key, model)
        self.load_data()

        # initialize with data
        if self.db.FIRST_CREATE:
            self.set_initial_data()
            del self.db.FIRST_CREATE
示例#18
0
def build_all(caller=None):
    """
    Build all objects in the world.

    Args:
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Reset object key's info.
    OBJECT_KEY_HANDLER.reload()

    # Build areas.
    build_unique_objects(DATA_SETS.world_areas.objects, DATA_SETS.world_areas.model_name, caller)
    
    # Build rooms.
    build_unique_objects(DATA_SETS.world_rooms.objects, DATA_SETS.world_rooms.model_name, caller)

    # Build exits.
    build_unique_objects(DATA_SETS.world_exits.objects, DATA_SETS.world_exits.model_name, caller)

    # Build objects.
    build_unique_objects(DATA_SETS.world_objects.objects, DATA_SETS.world_objects.model_name, caller)

    # Build NPCs.
    build_unique_objects(DATA_SETS.world_npcs.objects, DATA_SETS.world_npcs.model_name, caller)
示例#19
0
    def load_data_fields(self, key):
        """
        Get object's data record from database.

        Args:
            key: (String) object's data key.

        Returns:
            None
        """
        # Get model and key names.
        if not key:
            key = self.get_data_key()
            if not key:
                return

        if key[:len(settings.REVERSE_EXIT_PREFIX
                    )] == settings.REVERSE_EXIT_PREFIX:
            # Reverse exit loads data without key's prefix.
            key = key[len(settings.REVERSE_EXIT_PREFIX):]

        data_models = OBJECT_KEY_HANDLER.get_models(key)

        for data_model in data_models:
            # Get db model
            model_obj = apps.get_model(settings.WORLD_DATA_APP, data_model)
            if not model_obj:
                logger.log_errmsg("%s can not open model %s" %
                                  (key, data_model))
                continue

            # Get data record.
            try:
                data = model_obj.objects.get(key=key)
            except Exception, e:
                logger.log_errmsg("%s can not find key %s" % (key, key))
                continue

            # Set data.
            for field in data._meta.fields:
                setattr(self.dfield, field.name,
                        data.serializable_value(field.name))
示例#20
0
    def load_data_fields(self, key):
        """
        Get object's data record from database.

        Args:
            key: (String) object's data key.

        Returns:
            None
        """
        # Get model and key names.
        if not key:
            key = self.get_data_key()
            if not key:
                return

        if key[:len(settings.REVERSE_EXIT_PREFIX)] == settings.REVERSE_EXIT_PREFIX:
            # Reverse exit loads data without key's prefix.
            key = key[len(settings.REVERSE_EXIT_PREFIX):]

        data_models = OBJECT_KEY_HANDLER.get_models(key)

        for data_model in data_models:
            # Get db model
            model_obj = apps.get_model(settings.WORLD_DATA_APP, data_model)
            if not model_obj:
                logger.log_errmsg("%s can not open model %s" % (key, data_model))
                continue

            # Get data record.
            try:
                data = model_obj.objects.get(key=key)
            except Exception, e:
                logger.log_errmsg("%s can not find key %s" % (key, key))
                continue

            # Set data.
            for field in data._meta.fields:
                setattr(self.dfield, field.name, data.serializable_value(field.name))
示例#21
0
def build_object(obj_key, caller=None):
    """
    Build objects of a model.

    Args:
        obj_key: (string) The key of the object.
        caller: (command caller) If provide, running messages will send to the caller.
    """
    # Get object's model name.
    record = None
    model_names = OBJECT_KEY_HANDLER.get_models(obj_key)
    for model_name in model_names:
        try:
            # Get record.
            model_obj = apps.get_model(settings.WORLD_DATA_APP, model_name)
            record_obj = model_obj.objects.get(key=obj_key)
            if hasattr(record_obj, "typeclass"):
                if hasattr(record_obj.typeclass, "path"):
                    record = record_obj
                    break
        except Exception, e:
            continue
示例#22
0
def get_object_record(obj_key):
    """
    Query the object's record.

    Args:
        obj_key: (string) The key of the object.

    Returns:
        The object's data record.
    """
    record = None
    model_names = OBJECT_KEY_HANDLER.get_models(obj_key)
    for model_name in model_names:
        try:
            # Get record.
            model_obj = apps.get_model(settings.WORLD_DATA_APP, model_name)
            record = model_obj.objects.get(key=obj_key)
            break
        except Exception, e:
            ostring = "Can not get record %s: %s." % (obj_key, e)
            print(ostring)
            print(traceback.print_exc())
            continue
示例#23
0
def get_object_record(obj_key):
    """
    Query the object's record.

    Args:
        obj_key: (string) The key of the object.

    Returns:
        The object's data record.
    """
    record = None
    model_names = OBJECT_KEY_HANDLER.get_models(obj_key)
    for model_name in model_names:
        try:
            # Get record.
            model_obj = apps.get_model(settings.WORLD_DATA_APP, model_name)
            record = model_obj.objects.get(key=obj_key)
            break
        except Exception, e:
            ostring = "Can not get record %s: %s." % (obj_key, e)
            print(ostring)
            print(traceback.print_exc())
            continue
示例#24
0
    def get_data_record(self):
        """
        Get object's data record from database.
        """
        # Get model and key names.
        key = self.get_info_key()
        if not key:
            return

        model = OBJECT_KEY_HANDLER.get_model(key)
        if not model:
            return

        # Get db model
        model_obj = get_model(settings.WORLD_DATA_APP, model)
        if not model_obj:
            raise MudderyError("%s can not open model %s" % (key, model))

        # Get data record.
        try:
            data = model_obj.objects.get(key=key)
        except Exception, e:
            raise MudderyError("%s can not find key %s" % (key, key))
示例#25
0
def build_object(obj_key, caller=None):
    """
    Build objects of a model.

    Args:
        obj_key: (string) The key of the object.
        caller: (command caller) If provide, running messages will send to the caller.
    """
    model_name = OBJECT_KEY_HANDLER.get_model(obj_key)
    if not model_name:
        ostring = "Can not find the model of %s." % obj_key
        print ostring
        print traceback.print_exc()
        return

    try:
        model_obj = get_model(settings.WORLD_DATA_APP, model_name)
        record = model_obj.objects.get(key=obj_key)
    except Exception, e:
        ostring = "Can not load record %s:%s %s" % (model_name, obj_key, e)
        print ostring
        print traceback.print_exc()
        return
示例#26
0
    def get_data_record(self):
        """
        Get object's data record from database.
        """
        # Get model and key names.
        key = self.get_info_key()
        if not key:
            return

        model = OBJECT_KEY_HANDLER.get_model(key)
        if not model:
            return

        # Get db model
        model_obj = get_model(settings.WORLD_DATA_APP, model)
        if not model_obj:
            raise MudderyError("%s can not open model %s" % (key, model))

        # Get data record.
        try:
            data = model_obj.objects.get(key=key)
        except Exception, e:
            raise MudderyError("%s can not find key %s" % (key, key))
示例#27
0
    def return_objectives(self):
        """
        Get the information of all objectives.
        Set desc to an objective can hide the details of the objective.
        """
        objectives = []
        for ordinal in self.objectives:
            desc = self.objectives[ordinal]["desc"]
            if desc:
                # If an objective has desc, use its desc.
                objectives.append({"desc": self.objectives[ordinal]["desc"]})
            else:
                # Or make a desc by other data.
                obj_num = self.objectives[ordinal]["number"]
                accomplished = self.db.accomplished.get(ordinal, 0)

                if self.objectives[ordinal]["type"] == defines.OBJECTIVE_TALK:
                    # talking
                    target = _("Talk to")
                    name = DIALOGUE_HANDLER.get_npc_name(
                        self.objectives[ordinal]["object"])

                    objectives.append({
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })
                elif self.objectives[ordinal][
                        "type"] == defines.OBJECTIVE_OBJECT:
                    # getting
                    target = _("Get")
                    name = ""

                    # Get the name of the objective object.
                    object_key = self.objectives[ordinal]["object"]
                    model_names = OBJECT_KEY_HANDLER.get_models(object_key)
                    for model_name in model_names:
                        model = apps.get_model(settings.WORLD_DATA_APP,
                                               model_name)
                        # Get record.
                        try:
                            record = model.objects.get(key=object_key)
                            name = record.name
                            break
                        except Exception, e:
                            pass

                    objectives.append({
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })
                elif self.objectives[ordinal][
                        "type"] == defines.OBJECTIVE_KILL:
                    # getting
                    target = _("Kill")
                    name = ""

                    # Get the name of the objective character.
                    object_key = self.objectives[ordinal]["object"]
                    model_names = OBJECT_KEY_HANDLER.get_models(object_key)
                    for model_name in model_names:
                        model = apps.get_model(settings.WORLD_DATA_APP,
                                               model_name)
                        # Get record.
                        try:
                            record = model.objects.get(key=object_key)
                            name = record.name
                            break
                        except Exception, e:
                            pass

                    objectives.append({
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })
示例#28
0
    def return_objectives(self):
        """
        Get the information of all objectives.
        Set desc to an objective can hide the details of the objective.
        """
        objectives = []
        for ordinal in self.objectives:
            desc = self.objectives[ordinal]["desc"]
            if desc:
                # If an objective has desc, use its desc.
                objectives.append({"desc": self.objectives[ordinal]["desc"]})
            else:
                # Or make a desc by other data.
                obj_num = self.objectives[ordinal]["number"]
                accomplished = self.db.accomplished.get(ordinal, 0)
                
                if self.objectives[ordinal]["type"] == defines.OBJECTIVE_TALK:
                    # talking
                    target = _("Talk to")
                    name = DIALOGUE_HANDLER.get_npc_name(self.objectives[ordinal]["object"])
        
                    objectives.append({"target": target,
                                       "object": name,
                                       "accomplished": accomplished,
                                       "total": obj_num,
                                       })
                elif self.objectives[ordinal]["type"] == defines.OBJECTIVE_OBJECT:
                    # getting
                    target = _("Get")
                    name = ""
                    
                    # Get the name of the objective object.
                    object_key = self.objectives[ordinal]["object"]
                    model_names = OBJECT_KEY_HANDLER.get_models(object_key)
                    for model_name in model_names:
                        model = apps.get_model(settings.WORLD_DATA_APP, model_name)
                        # Get record.
                        try:
                            record = model.objects.get(key=object_key)
                            name = record.name
                            break
                        except Exception, e:
                            pass
        
                    objectives.append({"target": target,
                                       "object": name,
                                       "accomplished": accomplished,
                                       "total": obj_num,
                                       })
                elif self.objectives[ordinal]["type"] == defines.OBJECTIVE_KILL:
                    # getting
                    target = _("Kill")
                    name = ""

                    # Get the name of the objective character.
                    object_key = self.objectives[ordinal]["object"]
                    model_names = OBJECT_KEY_HANDLER.get_models(object_key)
                    for model_name in model_names:
                        model = apps.get_model(settings.WORLD_DATA_APP, model_name)
                        # Get record.
                        try:
                            record = model.objects.get(key=object_key)
                            name = record.name
                            break
                        except Exception, e:
                            pass

                    objectives.append({"target": target,
                                       "object": name,
                                       "accomplished": accomplished,
                                       "total": obj_num,
                                       })