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