def at_object_creation(self): """ Called once, when this object is first created. This is the normal hook to overload for most object types. """ super(MudderyPlayerCharacter, self).at_object_creation() # honour if not HONOURS_MAPPER.has_info(self): if self.db.level >= settings.MIN_HONOUR_LEVEL: HONOURS_MAPPER.set_honour(self, 0) else: HONOURS_MAPPER.set_honour(self, -1) # Set default data. if not self.attributes.has("nickname"): self.db.nickname = "" if not self.attributes.has("unlocked_exits"): self.db.unlocked_exits = set() if not self.attributes.has("revealed_map"): self.db.revealed_map = set() # set custom attributes if not self.attributes.has("attributes"): self.db.attributes = {} """
def at_object_creation(self): """ Called once, when this object is first created. This is the normal hook to overload for most object types. """ super(MudderyPlayerCharacter, self).at_object_creation() # honour if not HONOURS_MAPPER.has_info(self): HONOURS_MAPPER.set_honour(self, -1) # Set default data. if not self.attributes.has("nickname"): self.db.nickname = "" if not self.attributes.has("unlocked_exits"): self.db.unlocked_exits = set() if not self.attributes.has("revealed_map"): self.db.revealed_map = set() # set custom attributes if not self.attributes.has("attributes"): self.db.attributes = {} # Choose a random career. if not self.attributes.has("career"): self.db.career = "" try: careers = DATA_SETS.character_careers.objects.all() if careers: career = random.choice(careers) self.db.career = career.key except Exception, e: pass
def func(self): "delete the character" player = self.account session = self.session args = self.args if not args: self.msg({"alert": _("Please select a character")}) return dbref = args["dbref"] password = args["password"] check = player.check_password(password) if not check: # No password match session.msg({"alert": _("Incorrect password.")}) return # use the playable_characters list to search match = [ char for char in make_iter(player.db._playable_characters) if char.dbref == dbref ] if not match: session.msg({"alert": _("You have no such character to delete.")}) return elif len(match) > 1: session.msg({ "alert": _("Aborting - there are two characters with the same name. Ask an admin to delete the right one." ) }) return else: # one match delobj = match[0] # get new playable characters new_characters = [ char for char in player.db._playable_characters if char != delobj ] # remove honour HONOURS_MAPPER.remove_honour(delobj) # remove object deleted = delobj.delete() if not deleted: session.msg({"alert": _("Can not delete this character.")}) return player.db._playable_characters = new_characters session.msg({ "char_deleted": True, "char_all": player.get_all_characters() })
def at_initial_setup(): """ Build up the default world and set default locations. """ try: # load world data import_local_data() print("Import local data.") # load game settings GAME_SETTINGS.reset() print("Reset game settings.") # build world builder.build_all() print("Builder build all.") # set limbo's desc limbo_obj = search.search_object("#2", exact=True) if limbo_obj: limbo_obj[0].db.desc = LIMBO_DESC limbo_obj[0].position = None print("Set limbo object.") # set default locations builder.reset_default_locations() print("Set default locations.") superuser = search.search_object("#1", exact=True) if superuser: superuser = superuser[0] # move the superuser to the start location start_location = search.search_object(settings.START_LOCATION, exact=True) if start_location: start_location = start_location[0] superuser.move_to(start_location, quiet=True) # set superuser's data superuser.set_data_key( GAME_SETTINGS.get("default_player_character_key")) superuser.set_level(1) superuser.set_nickname("superuser") # set superuser's honour to -1 HONOURS_MAPPER.set_honour(superuser, -1) print("Set supervisor.") except Exception, e: ostring = "Can't set initial data: %s" % e print(ostring) print(traceback.format_exc())
def at_server_start(): """ This is called every time the server starts up, regardless of how it was shut down. """ # reset settings from muddery.utils.game_settings import GAME_SETTINGS GAME_SETTINGS.reset() # reload local strings from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER LOCALIZED_STRINGS_HANDLER.reload() # reload attributes from muddery.utils.attributes_info_handler import CHARACTER_ATTRIBUTES_INFO CHARACTER_ATTRIBUTES_INFO.reload() from muddery.utils.attributes_info_handler import EQUIPMENT_ATTRIBUTES_INFO EQUIPMENT_ATTRIBUTES_INFO.reload() from muddery.utils.attributes_info_handler import FOOD_ATTRIBUTES_INFO FOOD_ATTRIBUTES_INFO.reload() # reset default locations from muddery.utils import builder builder.reset_default_locations() # clear dialogues from muddery.utils.dialogue_handler import DIALOGUE_HANDLER DIALOGUE_HANDLER.clear() # reload equipment types from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER EQUIP_TYPE_HANDLER.reload() # localize model fields from muddery.utils.localiztion_handler import 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 from muddery.utils.desc_handler import DESC_HANDLER DESC_HANDLER.reload() # load honours from muddery.dao.honours_mapper import HONOURS_MAPPER HONOURS_MAPPER.reload()
def at_initial_setup(): """ Build up the default world and set default locations. """ try: # load game settings GAME_SETTINGS.reset() print("Reset game settings.") # build world builder.build_all() print("Builder build all.") # set limbo's desc limbo_obj = search.search_object("#2", exact=True) if limbo_obj: limbo_obj[0].db.desc = LIMBO_DESC limbo_obj[0].position = None print("Set limbo object.") # set default locations builder.reset_default_locations() print("Set default locations.") superuser = search.search_object("#1", exact=True) if superuser: superuser = superuser[0] # move the superuser to the start location start_location = search.search_object(settings.START_LOCATION, exact=True) if start_location: start_location = start_location[0] superuser.move_to(start_location, quiet=True) # set superuser's data superuser.set_data_key(GAME_SETTINGS.get("default_player_character_key")) superuser.set_level(1) superuser.set_nickname("superuser") # set superuser's honour to -1 HONOURS_MAPPER.set_honour(superuser, -1) print("Set superuser.") except Exception, e: ostring = "Can't set initial data: %s" % e print(ostring) print(traceback.format_exc())
def show_rankings(self): """ Show character's rankings. """ top_rankings = HONOURS_MAPPER.get_top_rankings(settings.TOP_RANKINGS_NUMBER) nearest_rankings = HONOURS_MAPPER.get_nearest_rankings(self, settings.NEAREST_RANKINGS_NUMBER) rankings = top_rankings rankings.extend([id for id in nearest_rankings if id not in top_rankings]) characters = [self.search_dbref("#%s" % id) for id in rankings] data = [{"name": char.get_name(), "dbref": char.dbref, "ranking": HONOURS_MAPPER.get_ranking(char), "honour": HONOURS_MAPPER.get_honour(char)} for char in characters] self.msg({"rankings": data})
def func(self): "Handle command" caller = self.caller if not caller: return if caller.db.level < settings.MIN_HONOUR_LEVEL: caller.msg({"alert":_("You need to reach level %s." % settings.MIN_HONOUR_LEVEL)}) return try: # getcandidates ids = HONOURS_MAPPER.get_characters(caller, settings.HONOUR_OPPONENTS_NUMBER) characters = [caller.search_dbref("#%s" % id) for id in ids] candidates = [char for char in characters if char and not char.is_in_combat()] if candidates: match = random.choice(candidates) # create a new combat handler chandler = create_script(settings.HONOUR_COMBAT_HANDLER) # set combat team and desc chandler.set_combat({1:[match], 2:[caller]}, _("Fight of Honour"), settings.AUTO_COMBAT_TIMEOUT) else: caller.msg({"alert":_("Can not make match.")}) except Exception, e: logger.log_err("Find match error: %s" % e) caller.msg({"alert":_("Can not make match.")})
def level_up(self): """ Upgrade level. Returns: None """ super(MudderyPlayerCharacter, self).level_up() # set honour if self.db.level >= settings.MIN_HONOUR_LEVEL: if not HONOURS_MAPPER.has_info(self): HONOURS_MAPPER.set_honour(self, 0) self.msg({"msg": _("{rThe honour hall is now opened.{n")}) # notify the player self.msg({"msg": _("{c%s upgraded to level %s.{n") % (self.get_name(), self.db.level)})
def func(self): "delete the character" player = self.account session = self.session args = self.args if not args: self.msg({"alert":_("Please select a character")}) return dbref = args["dbref"] password = args["password"] check = player.check_password(password) if not check: # No password match session.msg({"alert":_("Incorrect password.")}) return # use the playable_characters list to search match = [char for char in make_iter(player.db._playable_characters) if char.dbref == dbref] if not match: session.msg({"alert":_("You have no such character to delete.")}) return elif len(match) > 1: session.msg({"alert":_("Aborting - there are two characters with the same name. Ask an admin to delete the right one.")}) return else: # one match delobj = match[0] # get new playable characters new_characters = [char for char in player.db._playable_characters if char != delobj] # remove honour HONOURS_MAPPER.remove_honour(delobj) # remove object deleted = delobj.delete() if not deleted: session.msg({"alert":_("Can not delete this character.")}) return player.db._playable_characters = new_characters session.msg({"char_deleted": True, "char_all": player.get_all_characters()})
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 set_honours(self, winners, losers): """ Set combat winner's honour. """ total_losers = 0 for char in losers: total_losers += HONOURS_MAPPER.get_honour(char, 0) average_losers = total_losers / len(losers) total_winners = 0 for char in winners: total_winners += HONOURS_MAPPER.get_honour(char, 0) average_winners = total_winners / len(winners) total_honours = {} for char in winners: self_honour = HONOURS_MAPPER.get_honour(char, 0) diff = average_losers - self_honour change = 0 if diff > 200: change = 20 elif diff > 100: change = 15 elif diff >= -100: change = 10 elif diff >= -200: change = 5 else: change = 0 value = self_honour + change if value < 0: value = 0 total_honours[char.id] = value for char in losers: self_honour = HONOURS_MAPPER.get_honour(char, 0) diff = average_winners - self_honour change = 0 if diff > 200: change = 20 elif diff > 100: change = 15 elif diff >= -100: change = 10 elif diff >= -200: change = 5 else: change = 0 value = self_honour - change if value < 0: value = 0 total_honours[char.id] = value HONOURS_MAPPER.set_honours(total_honours)
def func(self): "Handle command" caller = self.caller if not caller: return if caller.db.level < settings.MIN_HONOUR_LEVEL: caller.msg({ "alert": _("You need to reach level %s." % settings.MIN_HONOUR_LEVEL) }) return try: # getcandidates ids = HONOURS_MAPPER.get_characters( caller, settings.HONOUR_OPPONENTS_NUMBER) characters = [caller.search_dbref("#%s" % id) for id in ids] candidates = [ char for char in characters if char and not char.is_in_combat() ] if candidates: match = random.choice(candidates) # create a new combat handler chandler = create_script(settings.HONOUR_COMBAT_HANDLER) # set combat team and desc chandler.set_combat({ 1: [match], 2: [caller] }, _("Fight of Honour"), settings.AUTO_COMBAT_TIMEOUT) else: caller.msg({"alert": _("Can not make match.")}) except Exception, e: logger.log_err("Find match error: %s" % e) caller.msg({"alert": _("Can not make match.")})
def match(self): """ Match opponents according to character's scores. The longer a character in the queue, the score is higher. The nearer of two character's rank, the score is higher. """ if len(self.queue) < 2: return time_now = time.time() candidates = [] count = 0 max = self.max_candidates for id in self.queue: if count >= max: break if id in self.preparing: continue characters = search_object("#%s" % id) if not characters or characters[0].is_in_combat(): continue candidates.append(id) count += 1 max_score = 0 opponents = () for i in xrange(len(candidates) - 1): for j in xrange(i + 1, len(candidates)): score_A = time_now - self.waiting_time[candidates[i]] score_B = time_now - self.waiting_time[candidates[j]] honour_A = HONOURS_MAPPER.get_honour_by_id(candidates[i], 0) honour_B = HONOURS_MAPPER.get_honour_by_id(candidates[j], 0) score_C = self.max_honour_diff - math.fabs(honour_A - honour_B) if score_A <= self.min_waiting_time or score_B <= self.min_waiting_time or score_C <= 0: break score = score_A + score_B + score_C if score > max_score: max_score = score opponents = candidates[i], candidates[j] if opponents: self.preparing[opponents[0]] = {"time": time.time(), "opponent": opponents[1], "confirmed": False} self.preparing[opponents[1]] = {"time": time.time(), "opponent": opponents[0], "confirmed": False} character_A = search_object("#%s" % opponents[0]) character_B = search_object("#%s" % opponents[1]) if character_A: character_A[0].msg({"prepare_match": self.preparing_time}) if character_B: character_B[0].msg({"prepare_match": self.preparing_time}) call_id = reactor.callLater(self.preparing_time, self.fight, opponents) self.preparing[opponents[0]]["call_id"] = call_id self.preparing[opponents[1]]["call_id"] = call_id self.ave_samples.append(time_now - self.waiting_time[opponents[0]]) self.ave_samples.append(time_now - self.waiting_time[opponents[1]]) while len(self.ave_samples) > self.ave_samples_number: self.ave_samples.popleft() self.ave_waiting = float(sum(self.ave_samples)) / len(self.ave_samples)