ranking as commands or at the end of each day
This commit is contained in:
@@ -51,6 +51,54 @@ class BrSimArena():
|
||||
res.append(p)
|
||||
return res
|
||||
|
||||
def sort_players_by_kills_and_health(self, players):
|
||||
def player_sort_key(player):
|
||||
kills= player.get_kills()
|
||||
health= player.get_health()
|
||||
#Negative values to sort in decr mode
|
||||
return (-kills, -health)
|
||||
return sorted(players, key=player_sort_key)
|
||||
|
||||
def get_ranking(self):
|
||||
medals = ['🥇', '🥈', '🥉']
|
||||
leaderboard = []
|
||||
leaderboard.append('🏆 *Classifica attuale:* \n')
|
||||
alive_players= self.get_alive_players();
|
||||
alive_sorted= self.sort_players_by_kills_and_health(alive_players)
|
||||
death_players= self.get_death_players()
|
||||
death_sorted= self.sort_players_by_kills_and_health(death_players)
|
||||
|
||||
# Alive Players
|
||||
alive_players= self.get_alive_players();
|
||||
alive_sorted= self.sort_players_by_kills_and_health(alive_players)
|
||||
for index, player in enumerate(alive_sorted):
|
||||
name = player.get_name()
|
||||
kills = player.get_kills()
|
||||
health = '♥️' * player.get_health()
|
||||
if index < 3:
|
||||
position = medals[index]
|
||||
else:
|
||||
position = f"{index + 1}."
|
||||
|
||||
line = f"{position} {name} - {kills} uccision{'i' if kills != 1 else 'e'}, {health}"
|
||||
leaderboard.append(line)
|
||||
|
||||
# Death players:
|
||||
death_players= self.get_death_players()
|
||||
death_sorted= self.sort_players_by_kills_and_health(death_players)
|
||||
|
||||
if death_sorted:
|
||||
leaderboard.append("\n-- GIOCATORI ELIMINATI --")
|
||||
for player in death_sorted:
|
||||
name = player.get_name()
|
||||
kills = player.get_kills()
|
||||
health = player.get_health()
|
||||
|
||||
line = f"💀 {name} - {kills} uccision{'i' if kills != 1 else 'e'}"
|
||||
leaderboard.append(line)
|
||||
|
||||
return '\n'.join(leaderboard)
|
||||
|
||||
def do_random_event(self):
|
||||
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user