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()
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)
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)
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()
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)
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()
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))
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
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
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
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()
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)
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)
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
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))
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))
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
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
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))
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
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, })
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, })