forked from Cryz/battle_royale_sim
Merge branch 'master' of https://gitea.rpicloud.ovh/Cryz/battle_royale_sim
This commit is contained in:
31
bot.py
31
bot.py
@@ -16,37 +16,46 @@ async def loop_game(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
async def bot_start(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)
|
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()
|
Arena= _brsim.init_arena()
|
||||||
players= Arena.players
|
players= Arena.get_players()
|
||||||
weapons= Arena.weapons
|
weapons= Arena.get_weapons()
|
||||||
print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}')
|
print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}')
|
||||||
print(f'Ecco le armi disponibili nel mondo: {weapons}')
|
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('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'Ecco la lista degli sfortunati avventurieri:\n{players}')
|
||||||
await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena: {weapons}')
|
await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena:\n{weapons}')
|
||||||
context.application.bot_data['arena'] = Arena
|
context.application.bot_data['arena'] = Arena
|
||||||
|
|
||||||
chat_id = update.effective_chat.id
|
|
||||||
context.job_queue.run_daily(
|
context.job_queue.run_daily(
|
||||||
loop_game,
|
loop_game,
|
||||||
time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc),
|
time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc),
|
||||||
chat_id=chat_id,
|
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}')
|
print(f'Job giornaliero creato per la chat {chat_id}')
|
||||||
|
|
||||||
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
testo_ricevuto = update.message.text
|
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:
|
||||||
|
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)
|
||||||
|
print(f'Giocatori: {Arena.get_players()}')
|
||||||
|
print(f'Ecco il mondo di gioco, questi sono i giocatori: {Arena.get_players()}')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Crea l'applicazione e passagli il token del tuo bot.
|
|
||||||
application = Application.builder().token(_botsyms.TOKEN).build()
|
application = Application.builder().token(_botsyms.TOKEN).build()
|
||||||
|
|
||||||
# Gestisce il comando /start
|
|
||||||
application.add_handler(CommandHandler('start', bot_start))
|
application.add_handler(CommandHandler('start', bot_start))
|
||||||
# Gestisce tutti gli altri messaggi di testo
|
application.add_handler(CommandHandler('addplayer', add_player))
|
||||||
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
|
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
|
||||||
|
|
||||||
print('Bot in esecuzione...')
|
print('Bot in esecuzione...')
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ Tu e i tuoi compagni, sarete catapultati in questo mondo,
|
|||||||
ma solo 1 di voi riuscira' a salvarsi.
|
ma solo 1 di voi riuscira' a salvarsi.
|
||||||
Uccidi o sarai tu ad essere ucciso
|
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?"
|
||||||
|
|||||||
@@ -48,3 +48,24 @@ class BrSimPlayer():
|
|||||||
|
|
||||||
def get_inventory(self):
|
def get_inventory(self):
|
||||||
return self.inventory
|
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(),
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import random as _random
|
import random as _random
|
||||||
from entities import weapon_syms as _syms
|
from entities import weapon_syms as _syms
|
||||||
|
|
||||||
class BrSimPlayer():
|
class BrSimWeapon():
|
||||||
|
|
||||||
def __init__(self, wtype):
|
def __init__(self, wtype):
|
||||||
self.weapon= _syms.WEAPONS[wtype]
|
self.weapon= _syms.WEAPONS[wtype]
|
||||||
|
|||||||
35
main.py
35
main.py
@@ -9,11 +9,19 @@ class BrSimArena():
|
|||||||
|
|
||||||
def __init__(self, players, weapons):
|
def __init__(self, players, weapons):
|
||||||
self.day= 1
|
self.day= 1
|
||||||
self.players= players
|
self.players= [_player.BrSimPlayer(p['name'], p.get('inventory')) for p in players]
|
||||||
self.weapons= weapons
|
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):
|
def next_day(self):
|
||||||
self.day+= 1
|
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):
|
def get_alive_players(self):
|
||||||
res= []
|
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
|
#TODO maybe in future a player can have charism stats that can influence the chance to get a donation
|
||||||
pass
|
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():
|
def init_arena():
|
||||||
players= [{'name': 'Crystal'}, {'name': 'Andrea'}]
|
players= [{'name': 'Crystal'}, {'name': 'Andrea'}]
|
||||||
w= _wsyms.KNIFE
|
w= _wsyms.KNIFE
|
||||||
weapons= [{_wsyms.WEAPONS[w]['name']: 1}]
|
#weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}]
|
||||||
|
weapons= [{w: 1}]
|
||||||
return BrSimArena(players, weapons)
|
return BrSimArena(players, weapons)
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +76,7 @@ def run_event(Arena):
|
|||||||
|
|
||||||
def local_debug():
|
def local_debug():
|
||||||
Arena= init_arena()
|
Arena= init_arena()
|
||||||
print(Arena.players)
|
print(f'Players: {Arena.get_players()}')
|
||||||
print(Arena.weapons)
|
print(f'Weapons: {Arena.get_weapons()}')
|
||||||
run_event(Arena)
|
run_event(Arena)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user