forked from Cryz/battle_royale_sim
ranking as commands or at the end of each day
This commit is contained in:
5
bot.py
5
bot.py
@@ -18,7 +18,7 @@ async def bot_start(update, context):
|
|||||||
keyboard = [
|
keyboard = [
|
||||||
['Init/Restart'],
|
['Init/Restart'],
|
||||||
['Add Player', 'Add random Players', 'Add random color Players'],
|
['Add Player', 'Add random Players', 'Add random color Players'],
|
||||||
['Get Players', 'Get Alive Players', 'Get Death Players'],
|
['Get Players', 'Get Alive Players', 'Get Death Players', 'Get Ranking Players',],
|
||||||
['Simulate Day', 'Run Periodically']
|
['Simulate Day', 'Run Periodically']
|
||||||
]
|
]
|
||||||
reply_markup= ReplyKeyboardMarkup(keyboard, one_time_keyboard=False, resize_keyboard=True)
|
reply_markup= ReplyKeyboardMarkup(keyboard, one_time_keyboard=False, resize_keyboard=True)
|
||||||
@@ -53,6 +53,9 @@ async def bot_commands(update, context):
|
|||||||
if text == 'Get Death Players':
|
if text == 'Get Death Players':
|
||||||
print(f'bot_command: {chat_id} Get Death Players')
|
print(f'bot_command: {chat_id} Get Death Players')
|
||||||
return await _bot_player.get_death_players(update, context)
|
return await _bot_player.get_death_players(update, context)
|
||||||
|
if text == 'Get Ranking Players':
|
||||||
|
print(f'bot_command: {chat_id} Get Ranking Players')
|
||||||
|
return await _bot_player.get_ranking_players(update, context)
|
||||||
if text == 'Simulate Day':
|
if text == 'Simulate Day':
|
||||||
print(f'bot_command: {chat_id} Simulate Day')
|
print(f'bot_command: {chat_id} Simulate Day')
|
||||||
return await _bot_sim.simulate_day(context, chat_id)
|
return await _bot_sim.simulate_day(context, chat_id)
|
||||||
|
|||||||
@@ -39,3 +39,12 @@ async def get_death_players(update, context):
|
|||||||
death_str= '\n'.join(death)
|
death_str= '\n'.join(death)
|
||||||
print(f'get_death_players: {death_str}')
|
print(f'get_death_players: {death_str}')
|
||||||
await update.message.reply_text(f'Ecco i giocatori morti x.x: \n{death_str}')
|
await update.message.reply_text(f'Ecco i giocatori morti x.x: \n{death_str}')
|
||||||
|
|
||||||
|
async def get_ranking_players(update, context):
|
||||||
|
Arena = context.application.bot_data['arena']
|
||||||
|
leaderboard_text = Arena.get_ranking()
|
||||||
|
print(f'{leaderboard_text}')
|
||||||
|
await update.message.reply_text(
|
||||||
|
f'{leaderboard_text}',
|
||||||
|
parse_mode='Markdown'
|
||||||
|
)
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ async def simulate_day(context, chat_id):
|
|||||||
await context.bot.send_message(chat_id, f'Giorno #{Arena.day}')
|
await context.bot.send_message(chat_id, f'Giorno #{Arena.day}')
|
||||||
msg= _dbg.play_one_day_debug(Arena)
|
msg= _dbg.play_one_day_debug(Arena)
|
||||||
await context.bot.send_message(chat_id, msg)
|
await context.bot.send_message(chat_id, msg)
|
||||||
|
#Print the ranking each day
|
||||||
|
msg= Arena.get_ranking()
|
||||||
|
await context.bot.send_message(chat_id, msg)
|
||||||
if len(Arena.get_alive_players()) == 1:
|
if len(Arena.get_alive_players()) == 1:
|
||||||
msg= get_winner(Arena)
|
msg= get_winner(Arena)
|
||||||
return await context.bot.send_message(chat_id, msg)
|
return await context.bot.send_message(chat_id, msg)
|
||||||
|
|||||||
@@ -51,6 +51,54 @@ class BrSimArena():
|
|||||||
res.append(p)
|
res.append(p)
|
||||||
return res
|
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):
|
def do_random_event(self):
|
||||||
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user