From 7697b91ec83f73c5778832935d2b32a1ff074c2ed3ab1921c6e2cce0f20e5bbc Mon Sep 17 00:00:00 2001 From: Crystal Date: Wed, 23 Jul 2025 23:43:26 +0200 Subject: [PATCH 1/7] Arena and Player start populating more basic methods of the object --- bot.py | 15 ++++++++++----- bot_syms.py | 2 ++ entities/player.py | 21 +++++++++++++++++++++ entities/weapons.py | 2 +- main.py | 35 ++++++++++++++++++++++++++++++----- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/bot.py b/bot.py index 179086b..42c6555 100644 --- a/bot.py +++ b/bot.py @@ -16,18 +16,19 @@ async def loop_game(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text(_botsyms.START_MSG) - print('Sto costruendo il mondo di gioco...') + chat_id = update.effective_chat.id + print(f'{chat_id}: Sto costruendo il mondo di gioco...') Arena= _brsim.init_arena() players= Arena.players weapons= Arena.weapons print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}') print(f'Ecco le armi disponibili nel mondo: {weapons}') + await update.message.reply_text('Ho creato il mondo di gioco') - await update.message.reply_text(f'Ecco la lista degli sfortunati avventurieri: {players}') - await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena: {weapons}') + await update.message.reply_text(f'Ecco la lista degli sfortunati avventurieri:\n{players}') + await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena:\n{weapons}') context.application.bot_data['arena'] = Arena - chat_id = update.effective_chat.id context.job_queue.run_daily( loop_game, time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc), @@ -38,7 +39,9 @@ async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: testo_ricevuto = update.message.text - await update.message.reply_text(f'Ehi, mio padre mi sta ancora finendo di creare, abbi pazienza, che fretta hai di entrare in questo mondo per morire?') + await update.message.reply_text(_botsyms.WIP_MSG) + +async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: def main(): # Crea l'applicazione e passagli il token del tuo bot. @@ -46,6 +49,8 @@ def main(): # Gestisce il comando /start application.add_handler(CommandHandler('start', bot_start)) + # Gestisce il comando /addplayer + application.add_handler(CommandHandler('addplayer', add_player)) # Gestisce tutti gli altri messaggi di testo application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) diff --git a/bot_syms.py b/bot_syms.py index 211c9fe..2562725 100644 --- a/bot_syms.py +++ b/bot_syms.py @@ -7,3 +7,5 @@ Tu e i tuoi compagni, sarete catapultati in questo mondo, ma solo 1 di voi riuscira' a salvarsi. 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?" diff --git a/entities/player.py b/entities/player.py index 9df3c2a..b6ed26c 100644 --- a/entities/player.py +++ b/entities/player.py @@ -29,3 +29,24 @@ class BrSimPlayer(): def get_inventory(self): return self.inventory + + def get_name(self): + return self.name + + def get_health(self): + return self.health + + def get_damage(self): + return self.damage + + def get_agility(self): + return self.agility + + def get_data(self): + return { + 'name': self.get_name(), + 'inventory': self.get_inventory(), + 'health': self.get_health(), + 'damage': self.get_damage(), + 'agility': self.get_agility(), + } diff --git a/entities/weapons.py b/entities/weapons.py index 97496a0..fd54870 100644 --- a/entities/weapons.py +++ b/entities/weapons.py @@ -1,7 +1,7 @@ import random as _random from entities import weapon_syms as _syms -class BrSimPlayer(): +class BrSimWeapon(): def __init__(self, wtype): self.weapon= _syms.WEAPONS[wtype] diff --git a/main.py b/main.py index 161f73d..2a2018f 100644 --- a/main.py +++ b/main.py @@ -9,11 +9,19 @@ class BrSimArena(): def __init__(self, players, weapons): self.day= 1 - self.players= players - self.weapons= weapons + self.players= [_player.BrSimPlayer(p['name'], p.get('inventory')) for p in players] + self.weapons= [] + for weapon in weapons: + for wtype, quantity in weapon.items(): + for i in range(quantity): self.weapons.append(_weapons.BrSimWeapon(wtype)) def next_day(self): self.day+= 1 + print(f'Giorno: {self.day}') + print(f'Giocatori vivi: {self.get_alive_players()}') + death_players= self.get_death_players() + if (death_players): + print(f'Giocatori morti: {death_players}') def get_alive_players(self): res= [] @@ -38,11 +46,28 @@ class BrSimArena(): #TODO maybe in future a player can have charism stats that can influence the chance to get a donation pass + def add_player(self, name, inventory= None): + player= _player.BrSimPlayer(name, inventory) + self.players.append(player) + + def get_players(self): + res= [] + for p in self.players: + res.append(p.get_data()) + return res + + def get_weapons(self): + res= [] + for w in self.weapons: + #XXX implement me + res.append(w) + return res def init_arena(): players= [{'name': 'Crystal'}, {'name': 'Andrea'}] w= _wsyms.KNIFE - weapons= [{_wsyms.WEAPONS[w]['name']: 1}] + #weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}] + weapons= [{w: 1}] return BrSimArena(players, weapons) @@ -51,7 +76,7 @@ def run_event(Arena): def local_debug(): Arena= init_arena() - print(Arena.players) - print(Arena.weapons) + print(f'Players: {Arena.get_players()}') + print(f'Weapons: {Arena.get_weapons()}') run_event(Arena) From 12a413783bd5824c481a2231783cc8f8ef887a6f21485481e444edc19ab96567 Mon Sep 17 00:00:00 2001 From: Crystal Date: Wed, 23 Jul 2025 23:46:22 +0200 Subject: [PATCH 2/7] move telegram bot files --- bot.py => telegram_bot/bot.py | 0 bot_syms.py => telegram_bot/bot_syms.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename bot.py => telegram_bot/bot.py (100%) rename bot_syms.py => telegram_bot/bot_syms.py (100%) diff --git a/bot.py b/telegram_bot/bot.py similarity index 100% rename from bot.py rename to telegram_bot/bot.py diff --git a/bot_syms.py b/telegram_bot/bot_syms.py similarity index 100% rename from bot_syms.py rename to telegram_bot/bot_syms.py From 0bd3194caf1ddf83762a5c4502c5fa8b1af570c7aa75a017e4ab03e930a65f9d Mon Sep 17 00:00:00 2001 From: Crystal Date: Wed, 23 Jul 2025 23:48:02 +0200 Subject: [PATCH 3/7] Revert "move telegram bot files" This reverts commit 12a413783bd5824c481a2231783cc8f8ef887a6f21485481e444edc19ab96567. --- telegram_bot/bot.py => bot.py | 0 telegram_bot/bot_syms.py => bot_syms.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename telegram_bot/bot.py => bot.py (100%) rename telegram_bot/bot_syms.py => bot_syms.py (100%) diff --git a/telegram_bot/bot.py b/bot.py similarity index 100% rename from telegram_bot/bot.py rename to bot.py diff --git a/telegram_bot/bot_syms.py b/bot_syms.py similarity index 100% rename from telegram_bot/bot_syms.py rename to bot_syms.py From a51d0c39a1958e1be29c68cd9e7f124385ac89de0bba85a6b33dc5aa93f28393 Mon Sep 17 00:00:00 2001 From: Crystal Date: Wed, 23 Jul 2025 23:52:24 +0200 Subject: [PATCH 4/7] fixed missing add_player implementation --- bot.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 42c6555..7409048 100644 --- a/bot.py +++ b/bot.py @@ -33,7 +33,7 @@ async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: loop_game, time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc), chat_id=chat_id, - name=str(chat_id) # Usiamo il chat_id come nome univoco per il job + name=str(chat_id) ) print(f'Job giornaliero creato per la chat {chat_id}') @@ -42,16 +42,18 @@ async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text(_botsyms.WIP_MSG) async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + player= 'XXX' #XXX implement me, get from user request + print(f'sto aggiungendo il giocatore {player} all\'arena') + _brsim.BrSimArena + Arena= context.application.bot_data['arena'] + Arena.add_player(player) + def main(): - # Crea l'applicazione e passagli il token del tuo bot. application = Application.builder().token(_botsyms.TOKEN).build() - # Gestisce il comando /start application.add_handler(CommandHandler('start', bot_start)) - # Gestisce il comando /addplayer application.add_handler(CommandHandler('addplayer', add_player)) - # Gestisce tutti gli altri messaggi di testo application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) print('Bot in esecuzione...') From 39fe91afc78beb16287e0180e9c4c3c22d337774d71aa93a637d0119684cd5f8 Mon Sep 17 00:00:00 2001 From: Crystal Date: Wed, 23 Jul 2025 23:54:14 +0200 Subject: [PATCH 5/7] debug --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index 7409048..d41a8fb 100644 --- a/bot.py +++ b/bot.py @@ -47,6 +47,7 @@ async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None _brsim.BrSimArena Arena= context.application.bot_data['arena'] Arena.add_player(player) + print(f'Giocatori: Arena.get_players()') def main(): From 0221d8f9cc2140636838874b754cc6e4a90635069aa0f84c5caf810a73020a31 Mon Sep 17 00:00:00 2001 From: Crystal Date: Wed, 23 Jul 2025 23:55:30 +0200 Subject: [PATCH 6/7] typo --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index d41a8fb..f8fb010 100644 --- a/bot.py +++ b/bot.py @@ -47,7 +47,7 @@ async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None _brsim.BrSimArena Arena= context.application.bot_data['arena'] Arena.add_player(player) - print(f'Giocatori: Arena.get_players()') + print(f'Giocatori: {Arena.get_players()}') def main(): From d67797569b3788272a662beda49fc4a795a23f481bae542ffb32c845e2ec96f0 Mon Sep 17 00:00:00 2001 From: Crystal Date: Thu, 24 Jul 2025 00:01:08 +0200 Subject: [PATCH 7/7] show players detail after add --- bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index f8fb010..825a3e1 100644 --- a/bot.py +++ b/bot.py @@ -19,8 +19,8 @@ async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: chat_id = update.effective_chat.id print(f'{chat_id}: Sto costruendo il mondo di gioco...') Arena= _brsim.init_arena() - players= Arena.players - weapons= Arena.weapons + players= Arena.get_players() + weapons= Arena.get_weapons() print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}') print(f'Ecco le armi disponibili nel mondo: {weapons}') @@ -48,6 +48,7 @@ async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None Arena= context.application.bot_data['arena'] Arena.add_player(player) print(f'Giocatori: {Arena.get_players()}') + print(f'Ecco il mondo di gioco, questi sono i giocatori: {Arena.get_players()}') def main():