diff --git a/bot.py b/bot.py index 8cdbd22..cf58283 100644 --- a/bot.py +++ b/bot.py @@ -17,7 +17,7 @@ async def bot_start(update, context): keyboard = [ ['Init/Restart'], - ['Add Player'], + ['Add Player', 'Add random Players', 'Add random color Players'], ['Get Players', 'Get Alive Players', 'Get Death Players'], ['Simulate Day', 'Run Periodically'] ] @@ -63,6 +63,24 @@ async def bot_commands(update, context): del(context.application.bot_data['ask_name']) return await update.message.reply_text('Inserisci il numero di secondi, ad esempio \n(60 = 1 minuto)(600 = 10 minuti)\n(3600 = 1 ora)\n(86400 = 1 giorno)') + waiting_for_name= context.application.bot_data.get('ask_name') + if waiting_for_name or text in ['Add random Players', 'Add random color Players']: + print(f'bot_command: {chat_id} Collected Player Name {text}') + if 'ask_name' in context.application.bot_data: + del(context.application.bot_data['ask_name']) + players= text.split(',') + for player in players: + await _bot_player.add_player(update, context, player.strip()) + elif text == 'Add random Players': + await _bot_player.add_random_players(update, context, colors_names= False) + elif text == 'Add random color Players': + await _bot_player.add_random_players(update, context, colors_names= True) + + Arena= context.application.bot_data['arena'] + players= [p.get_name() for p in Arena.get_players()] + players_str= '\n'.join(players) + return await update.message.reply_text(f'Ecco i {len(players)} giocatori presenti nel mondo do gioco: \n{players_str}') + waiting_for_seconds= context.application.bot_data.get('ask_seconds') if waiting_for_seconds: print(f'bot_command: {chat_id} User Wants to auto-run the game every {text} seconds') @@ -71,14 +89,6 @@ async def bot_commands(update, context): seconds= max(1, text) return await _bot_repeat.start_loop_game(update, context, seconds) - waiting_for_name= context.application.bot_data.get('ask_name') - if waiting_for_name: - print(f'bot_command: {chat_id} Collected Player Name {text}') - del(context.application.bot_data['ask_name']) - players= text.split(',') - for player in players: - await _bot_player.add_player(update, context, player.strip()) - return print(f'bot_command: {chat_id} sent this text: {text}') await update.message.reply_text(_botsyms.WIP_MSG) diff --git a/bot_libs/player_handling.py b/bot_libs/player_handling.py index 1262b9d..6294b2f 100644 --- a/bot_libs/player_handling.py +++ b/bot_libs/player_handling.py @@ -1,11 +1,27 @@ +import random as _rand +from bot_libs import syms as _bot_syms + async def add_player(update, context, name): #name= " ".join(context.args) print(f'add_player: {name}') Arena= context.application.bot_data['arena'] Arena.add_player(name) - players= [p.get_name() for p in Arena.get_players()] - players_str= '\n'.join(players) - await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{players_str}') + #players= [p.get_name() for p in Arena.get_players()] + #players_str= '\n'.join(players) + #await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{players_str}') + +async def add_random_players(update, context, colors_names= False): + if colors_names: names= _bot_syms.COLORS_NAMES + else: names= _bot_syms.RANDOM_NAMES + + max_players= len(names) + min_players= min(7, max_players) + + players_num= _rand.randint(min_players, max_players) + _rand.shuffle(names) + lucky_players= _rand.sample(names, players_num) + print(f'add_random_players: extracting {players_num} random players for the game') + for name in names: await add_player(update, context, name) async def get_players(update, context): Arena= context.application.bot_data['arena'] diff --git a/bot_libs/simulation.py b/bot_libs/simulation.py index 49a5102..513b10e 100644 --- a/bot_libs/simulation.py +++ b/bot_libs/simulation.py @@ -8,11 +8,11 @@ def get_winner(Arena): except: pass day= Arena.day if winner.player_gender_is_male(): - msg= f'Giorno #{day}: {winner.get_name()} Vince la cruenta battaglia, e vive felice e contento con Guarino' + msg= f'{winner.get_name()} Vince la cruenta battaglia uccidendo {winner.get_kills()} giocatori, e vive felice e contento con Guarino' elif winner.player_gender_is_female(): - msg= f'Giorno #{day}: {winner.get_name()} Vince la cruenta battaglia, e vive felice e contenta con Guarino' + msg= f'{winner.get_name()} Vince la cruenta battaglia uccidendo {winner.get_kills()} giocatori, e vive felice e contenta con Guarino' else: - msg= f'Giorno #{day}: {winner.get_name()} Vince la cruenta battaglia, e vive felice e content# con Guarino' + msg= f'{winner.get_name()} Vince la cruenta battaglia uccidendo {winner.get_kills()} giocatori, e vive felice e content# con Guarino' return msg async def simulate_day(context, chat_id): diff --git a/bot_libs/syms.py b/bot_libs/syms.py index a3e54dd..2582d4d 100644 --- a/bot_libs/syms.py +++ b/bot_libs/syms.py @@ -11,3 +11,30 @@ Uccidi o sarai tu ad essere ucciso """ WIP_MSG= "Ehi, mio padre mi sta ancora finendo di creare, abbi pazienza, che fretta hai di entrare in questo mondo per morire?" + +RANDOM_NAMES = [ + "Aeliana", "Thorne", "Kael", "Seraphine", "Jaxon", "Lyra", "Darius", "Elowen", + "Zander", "Nyssa", "Orion", "Vesper", "Kieran", "Isolde", "Riven", "Calista", + "Draven", "Mira", "Zephyr", "Selene", "Ashen", "Talia", "Finnian", "Aria", + "Kaelan", "Liora", "Soren", "Elara", "Thalia", "Jett", "Cressida", "Lucian", + "Freya", "Ronan", "Niamh", "Kellan", "Zara", "Dorian", "Amara", "Jace", + "Elysia", "Caius", "Sable", "Alaric", "Veda", "Quinn", "Thorne", "Lirael", + "Rhea", "Kade", "Isadora", "Ash", "Nyx", "Cassian", "Elowen", "Tamsin", + "Rylan", "Faye", "Jorah", "Sienna", "Kieran", "Astra", "Zane", "Lyric", + "Dax", "Ember", "Orion", "Selah", "Juno", "Kaia", "Thorne", "Vespera", + "Riven", "Caden", "Liora", "Soren", "Elara", "Talia", "Jett", "Freya", + "Ronan", "Niamh", "Kellan", "Zara", "Dorian", "Amara", "Jace", "Elysia", + "Caius", "Sable", "Alaric", "Veda", "Quinn", "Thorne", "Lirael", "Rhea", + "Kade", "Isadora", "Ash", "Nyx", +] + +COLORS_NAMES= [ + "Yellow", "Grey", "Violet", "Black", "Lime", "Ruby", "Avocado", "Crystal", + "Pink", "Maize", "Coral", "Jade", "Platinum", "Emerald", "Carmine", "Nickel", + "Chocolate", "Slate", "Turquoise", "Silver", "Teal", "Jet", "Ivory", "Cobalt", + "Vermillion", "Aero", "Orange", "Rhythm", "Amber", "Olive", "Sepia", "Cyan", + "Green", "Ochre", "Denim", "Erin", "Fuchsia", "Aqua", "Iceberg", "Blue", + "Canary", "Red", "Mint", "Scarlet", "Coffee", "Indigo", "Mystic", "Rose", + "Pearl", "Pumpkin", "Navy", "Ultramarine", "Sapphire", "Desert", "Cherry", + "Tulip", +] diff --git a/entities/player.py b/entities/player.py index fbb3a6c..3454d28 100644 --- a/entities/player.py +++ b/entities/player.py @@ -10,7 +10,7 @@ class BrSimPlayer(): self.inventory= inventory or [] self.damage= 1 # this is the punch damage amount self.max_weight= 5 # this is the max inventory weight - self.agility= 10 # chance to avoid an hit + self.agility= _random.randint(5,30) # chance to avoid an hit self.kills= 0 # track the number of kills self.survived_days= 0 # track the number of the survived days self.equipped_weapon= None @@ -78,6 +78,9 @@ class BrSimPlayer(): def is_alive(self): return self.health > 0 + def get_kills(self): + return self.kills + ### player actions def _equip_weapon(self): @@ -122,7 +125,8 @@ class BrSimPlayer(): msg= f'Ehhhh voleviiii!!! sei lent##! {target.get_name()} schiva il colpo di {self.get_name()}' return 0, msg target.accuses_damage(self.damage) - msg= f'{self.get_name()} Colpisce {target.get_name()} in nome di Guarino' + msg= f'{self.get_name()} Colpisce {target.get_name()}' + self.kills+= 1 return self.damage, msg def get_item(self, item):