player stats review and minor bot improvements
This commit is contained in:
4
bot.py
4
bot.py
@@ -5,7 +5,7 @@ from telegram.ext import filters
|
|||||||
from telegram import ReplyKeyboardMarkup
|
from telegram import ReplyKeyboardMarkup
|
||||||
from telegram import ReplyKeyboardRemove
|
from telegram import ReplyKeyboardRemove
|
||||||
|
|
||||||
import main as _brsim
|
from entities import arena as _arena
|
||||||
from bot_libs import player_handling as _bot_player
|
from bot_libs import player_handling as _bot_player
|
||||||
from bot_libs import simulation as _bot_sim
|
from bot_libs import simulation as _bot_sim
|
||||||
from bot_libs import repeating as _bot_repeat
|
from bot_libs import repeating as _bot_repeat
|
||||||
@@ -25,7 +25,7 @@ async def bot_start(update, context):
|
|||||||
|
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
print(f'{chat_id}: I\'m building the world\'s game...')
|
print(f'{chat_id}: I\'m building the world\'s game...')
|
||||||
Arena= _brsim.init_arena()
|
Arena= _arena.BrSimArena()
|
||||||
|
|
||||||
await update.message.reply_text('Ho creato il mondo di gioco', reply_markup=reply_markup)
|
await update.message.reply_text('Ho creato il mondo di gioco', reply_markup=reply_markup)
|
||||||
context.application.bot_data['arena'] = Arena
|
context.application.bot_data['arena'] = Arena
|
||||||
|
|||||||
@@ -6,13 +6,15 @@ def get_winner(Arena):
|
|||||||
context.job.schedule_removal()
|
context.job.schedule_removal()
|
||||||
print(f'simulate_day: Loop removed')
|
print(f'simulate_day: Loop removed')
|
||||||
except: pass
|
except: pass
|
||||||
day= Arena.day
|
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia '
|
||||||
|
msg+= f'uccidendo {winner.get_kills()} giocatori '
|
||||||
|
msg+= f'e schivando {winner.get_dodges()} colpi nemici, e vive felice e '
|
||||||
if winner.player_gender_is_male():
|
if winner.player_gender_is_male():
|
||||||
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia uccidendo {winner.get_kills()} giocatori, e vive felice e contento con Guarino'
|
msg+= 'contento con Guarino'
|
||||||
elif winner.player_gender_is_female():
|
elif winner.player_gender_is_female():
|
||||||
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia uccidendo {winner.get_kills()} giocatori, e vive felice e contenta con Guarino'
|
msg+= 'contenta con Guarino'
|
||||||
else:
|
else:
|
||||||
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia uccidendo {winner.get_kills()} giocatori, e vive felice e content# con Guarino'
|
msg+= 'content# con Guarino'
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
async def simulate_day(context, chat_id):
|
async def simulate_day(context, chat_id):
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ class BrSimPlayer():
|
|||||||
self.inventory= inventory or []
|
self.inventory= inventory or []
|
||||||
self.damage= _random.randint(1,2) # this is the punch damage amount
|
self.damage= _random.randint(1,2) # 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= _random.randint(5,30) # chance to avoid an hit
|
self.agility= _random.randint(1,3) # chance to avoid an hit
|
||||||
self.kills= 0 # track the number of kills
|
self.kills= 0 # track the number of kills
|
||||||
self.accused_damage= 0
|
self.accused_damage= 0
|
||||||
self.survived_days= 0 # track the number of the survived days
|
self.survived_days= 0 # track the number of the survived days
|
||||||
|
self.dodges= 0
|
||||||
self.equipped_weapon= None
|
self.equipped_weapon= None
|
||||||
self.gender= _random.sample(['m', 'f', '-'], 1)[0] # for now get a random gender
|
self.gender= _random.sample(['m', 'f', '-'], 1)[0] # for now get a random gender
|
||||||
self.reputation= 50 #Like RDR2 the player can be evil(0) or good(100). This should influence the sponsors and internal alliance
|
self.reputation= 50 #Like RDR2 the player can be evil(0) or good(100). This should influence the sponsors and internal alliance
|
||||||
@@ -22,9 +23,9 @@ class BrSimPlayer():
|
|||||||
### control methods
|
### control methods
|
||||||
|
|
||||||
def get_name_and_stats(self):
|
def get_name_and_stats(self):
|
||||||
health= '♥️' * self.health
|
health= '♥️' * self.health or '☠️'
|
||||||
strength= '⚔️' * self.damage
|
strength= '⚔️' * self.damage
|
||||||
agility= f'🚀{self.agility}'
|
agility= '🚀' * self.agility
|
||||||
if self.player_gender_is_male(): gender= '♂'
|
if self.player_gender_is_male(): gender= '♂'
|
||||||
elif self.player_gender_is_female(): gender= '♀'
|
elif self.player_gender_is_female(): gender= '♀'
|
||||||
else: gender= '⚩'
|
else: gender= '⚩'
|
||||||
@@ -54,19 +55,26 @@ class BrSimPlayer():
|
|||||||
|
|
||||||
def get_inventory_weight(self):
|
def get_inventory_weight(self):
|
||||||
weight= 0
|
weight= 0
|
||||||
for inv in self.get_inventory():
|
for item in self.get_inventory():
|
||||||
weight+= inv.get_weight()
|
weight+= item.get_weight()
|
||||||
return weight
|
return weight
|
||||||
|
|
||||||
|
def get_dodges(self):
|
||||||
|
return self.dodges
|
||||||
|
|
||||||
def get_max_weight(self):
|
def get_max_weight(self):
|
||||||
return self.max_weight
|
return self.max_weight
|
||||||
|
|
||||||
def get_health(self):
|
def get_health(self):
|
||||||
return self.health
|
return self.health
|
||||||
|
|
||||||
|
def get_equipped_weapon(self):
|
||||||
|
return self.equipped_weapon
|
||||||
|
|
||||||
def get_damage(self):
|
def get_damage(self):
|
||||||
if not self.equipped_weapon: return self.damage
|
weapon= self.get_equipped_weapon()
|
||||||
return self.equipped_weapon.damage
|
if not weapon: return self.damage
|
||||||
|
return weapon.get_damage()
|
||||||
|
|
||||||
def get_agility(self):
|
def get_agility(self):
|
||||||
return self.agility
|
return self.agility
|
||||||
@@ -100,18 +108,21 @@ class BrSimPlayer():
|
|||||||
if not self.inventory: return
|
if not self.inventory: return
|
||||||
|
|
||||||
available_weapons= []
|
available_weapons= []
|
||||||
for inv in self.get_inventory():
|
for item in self.get_inventory():
|
||||||
# XXX
|
# XXX
|
||||||
# i don't know yet if this is ok,
|
# i don't know yet if this is ok,
|
||||||
# we'll see it when weapon and items are defined
|
# we'll see it when weapon and items are defined
|
||||||
if not inv.damage: continue
|
# maybe we need item.is_weapon() method
|
||||||
available_weapons.append(inv)
|
if not item.damage: continue
|
||||||
|
available_weapons.append(item)
|
||||||
self.equipped_weapon= random.sample(available_weapons, 1)[0]
|
self.equipped_weapon= random.sample(available_weapons, 1)[0]
|
||||||
|
|
||||||
def dodge(self):
|
def dodge(self):
|
||||||
# maybe depend on the attack, if it is a gun shot it's quite impossible to dodge
|
# maybe depend on the attack, if it is a gun shot it's quite impossible to dodge
|
||||||
rnd= _random.randint(0, 100)
|
rnd= _random.randint(0, 10)
|
||||||
if rnd < self.agility: return True
|
if rnd < self.agility:
|
||||||
|
self.dodges+= 1
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def accuses_damage(self, damage):
|
def accuses_damage(self, damage):
|
||||||
@@ -139,7 +150,11 @@ class BrSimPlayer():
|
|||||||
msg= f'Ehhhh voleviiii!!! sei lent##! {target.get_name_and_stats()} schiva il colpo di {self.get_name_and_stats()}'
|
msg= f'Ehhhh voleviiii!!! sei lent##! {target.get_name_and_stats()} schiva il colpo di {self.get_name_and_stats()}'
|
||||||
return 0, msg
|
return 0, msg
|
||||||
target.accuses_damage(self.damage)
|
target.accuses_damage(self.damage)
|
||||||
|
|
||||||
msg= f'{self.get_name_and_stats()} Colpisce {target.get_name_and_stats()}'
|
msg= f'{self.get_name_and_stats()} Colpisce {target.get_name_and_stats()}'
|
||||||
|
weapon= self.get_equipped_weapon()
|
||||||
|
if weapon: msg+= f' con un {weapon.get_name}'
|
||||||
|
else: msg+= f' con un pugno'
|
||||||
self.kills+= 1
|
self.kills+= 1
|
||||||
return self.damage, msg
|
return self.damage, msg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user