1
0

add kills counter random agility for each player and random init players

This commit is contained in:
andrea
2025-07-26 15:20:03 +02:00
parent 67804a394d
commit 4ce19d1a50
5 changed files with 74 additions and 17 deletions

28
bot.py
View File

@@ -17,7 +17,7 @@ async def bot_start(update, context):
keyboard = [ keyboard = [
['Init/Restart'], ['Init/Restart'],
['Add Player'], ['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'],
['Simulate Day', 'Run Periodically'] ['Simulate Day', 'Run Periodically']
] ]
@@ -63,6 +63,24 @@ async def bot_commands(update, context):
del(context.application.bot_data['ask_name']) 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)') 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') waiting_for_seconds= context.application.bot_data.get('ask_seconds')
if waiting_for_seconds: if waiting_for_seconds:
print(f'bot_command: {chat_id} User Wants to auto-run the game every {text} 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) seconds= max(1, text)
return await _bot_repeat.start_loop_game(update, context, seconds) 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}') print(f'bot_command: {chat_id} sent this text: {text}')
await update.message.reply_text(_botsyms.WIP_MSG) await update.message.reply_text(_botsyms.WIP_MSG)

View File

@@ -1,11 +1,27 @@
import random as _rand
from bot_libs import syms as _bot_syms
async def add_player(update, context, name): async def add_player(update, context, name):
#name= " ".join(context.args) #name= " ".join(context.args)
print(f'add_player: {name}') print(f'add_player: {name}')
Arena= context.application.bot_data['arena'] Arena= context.application.bot_data['arena']
Arena.add_player(name) Arena.add_player(name)
players= [p.get_name() for p in Arena.get_players()] #players= [p.get_name() for p in Arena.get_players()]
players_str= '\n'.join(players) #players_str= '\n'.join(players)
await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{players_str}') #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): async def get_players(update, context):
Arena= context.application.bot_data['arena'] Arena= context.application.bot_data['arena']

View File

@@ -8,11 +8,11 @@ def get_winner(Arena):
except: pass except: pass
day= Arena.day day= Arena.day
if winner.player_gender_is_male(): 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(): 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: 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 return msg
async def simulate_day(context, chat_id): async def simulate_day(context, chat_id):

View File

@@ -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?" 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",
]

View File

@@ -10,7 +10,7 @@ class BrSimPlayer():
self.inventory= inventory or [] self.inventory= inventory or []
self.damage= 1 # this is the punch damage amount self.damage= 1 # this is the punch damage amount
self.max_weight= 5 # this is the max inventory weight 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.kills= 0 # track the number of kills
self.survived_days= 0 # track the number of the survived days self.survived_days= 0 # track the number of the survived days
self.equipped_weapon= None self.equipped_weapon= None
@@ -78,6 +78,9 @@ class BrSimPlayer():
def is_alive(self): def is_alive(self):
return self.health > 0 return self.health > 0
def get_kills(self):
return self.kills
### player actions ### player actions
def _equip_weapon(self): 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()}' msg= f'Ehhhh voleviiii!!! sei lent##! {target.get_name()} schiva il colpo di {self.get_name()}'
return 0, msg return 0, msg
target.accuses_damage(self.damage) 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 return self.damage, msg
def get_item(self, item): def get_item(self, item):