Compare commits
11 Commits
master_eve
...
master
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
d40c7addfb | ||
|
|
445c51eec7 | ||
|
|
676a38b904 | ||
|
|
054522eaf3 | ||
|
|
f408aee8f8 | ||
|
|
9c2b6b026b | ||
|
|
f80edfff83 | ||
|
|
4c2864634b | ||
|
|
b4c8d94c8c | ||
|
|
a56d931304 | ||
|
|
b001c9312a |
@@ -9,7 +9,7 @@ EVENTS = [
|
||||
'extreme_fail_percentage' : 1,
|
||||
'requirements' : {},
|
||||
'weight' : 1,
|
||||
'affected_players' : 1,
|
||||
'affected_players' : 1, #NOTE, what is it? to why it could be integer or list?
|
||||
},
|
||||
{
|
||||
'id' : 'BOMB_EXPLOSION',
|
||||
|
||||
13
bot.py
13
bot.py
@@ -1,3 +1,5 @@
|
||||
import random as _rand
|
||||
|
||||
from telegram.ext import Application
|
||||
from telegram.ext import CommandHandler
|
||||
from telegram.ext import MessageHandler
|
||||
@@ -8,10 +10,18 @@ from telegram import ReplyKeyboardRemove
|
||||
from utils import logs as _log
|
||||
|
||||
from entities import arena as _arena
|
||||
from entities.items import syms as _isyms
|
||||
from bot_libs import special_commands as _scmd
|
||||
from bot_libs import syms as _botsyms
|
||||
from bot_libs import commands_handling as _cmd
|
||||
|
||||
def bot_get_random_items():
|
||||
items= []
|
||||
nitems= _rand.randint(3,5)
|
||||
for n in range(nitems):
|
||||
itype= _rand.sample(_isyms.ITEMS_LIST, 1)[0]
|
||||
items.append(itype)
|
||||
return items
|
||||
|
||||
async def bot_start(update, context):
|
||||
await update.message.reply_text(_botsyms.START_MSG)
|
||||
@@ -30,7 +40,8 @@ async def bot_start(update, context):
|
||||
|
||||
chat_id = update.effective_chat.id
|
||||
_log.log_debug(f'bot_start: {chat_id} - I\'m building the world\'s game...')
|
||||
Arena= _arena.BrSimArena()
|
||||
items= bot_get_random_items()
|
||||
Arena= _arena.BrSimArena(items= items)
|
||||
|
||||
await update.message.reply_text('Ho creato il mondo di gioco', reply_markup=reply_markup)
|
||||
context.application.bot_data['arena'] = Arena
|
||||
|
||||
49
debug.py
49
debug.py
@@ -3,14 +3,39 @@ import random as _rand
|
||||
import main as _main
|
||||
from utils import logs as _logs
|
||||
from bot_libs import syms as _syms
|
||||
from entities.items import syms as _isyms
|
||||
|
||||
|
||||
def _extract_random_number_of_items(Arena):
|
||||
players= Arena.get_players()
|
||||
nplayers= len(players)
|
||||
min_extraction= max(nplayers - 5, 3)
|
||||
max_extraction= min(nplayers - 1, 8)
|
||||
nitems= _rand.randint(min_extraction, max_extraction)
|
||||
return nitems
|
||||
|
||||
def _get_random_items(Arena):
|
||||
items= []
|
||||
nitems= _extract_random_number_of_items(Arena)
|
||||
for n in range(nitems):
|
||||
itype= _rand.sample(_isyms.ITEMS_LIST, 1)[0]
|
||||
items.append(itype)
|
||||
return items
|
||||
|
||||
def _debug_data():
|
||||
players= _syms.COLORS_NAMES
|
||||
weapons= []
|
||||
nelected_players= _rand.randint(6, 12)
|
||||
elected_players= _rand.sample(players, nelected_players)
|
||||
|
||||
Arena= _main.init_arena()
|
||||
for player in players:
|
||||
for player in elected_players:
|
||||
Arena.add_player(player)
|
||||
_logs.log_debug('Players: {elected_players}')
|
||||
|
||||
items= _get_random_items(Arena)
|
||||
for item in items:
|
||||
Arena.add_item(item)
|
||||
_logs.log_info('Items: {items}')
|
||||
return Arena
|
||||
|
||||
def _end_game_debug(alive_players, day):
|
||||
@@ -89,9 +114,9 @@ def init_debug_simulation():
|
||||
_logs.log_debug('#################')
|
||||
_logs.log_debug('#################')
|
||||
_logs.log_debug('#################')
|
||||
_time.sleep(0.3)
|
||||
_time.sleep(0.7)
|
||||
|
||||
def init_debug_loop():
|
||||
def init_debug_attack_loop():
|
||||
Arena= _debug_data()
|
||||
while (len(Arena.get_alive_players()) > 1):
|
||||
alive_players= Arena.get_alive_players()
|
||||
@@ -104,6 +129,18 @@ def init_debug_loop():
|
||||
Arena.next_day()
|
||||
_time.sleep(0.3)
|
||||
#End of day
|
||||
Map= Arena.get_map()
|
||||
_logs.log_debug(Map.get_renderized_map())
|
||||
|
||||
last_player= Arena.get_alive_players()[0]
|
||||
_logs.log_debug(f'{last_player.get_name()} sopravvive e vince dopo {Arena.day} lunghi Giorni, conquistando l\'amore eterno di Guarino')
|
||||
|
||||
def init_debug_event_loop():
|
||||
Arena= _debug_data()
|
||||
while (len(Arena.get_alive_players()) > 1):
|
||||
Arena.do_random_event()
|
||||
_time.sleep(0.3)
|
||||
#End of day
|
||||
|
||||
last_player= Arena.get_alive_players()[0]
|
||||
_logs.log_debug(f'{last_player.get_name()} sopravvive e vince dopo {Arena.day} lunghi Giorni, conquistando l\'amore eterno di Guarino')
|
||||
@@ -116,4 +153,6 @@ def debug_random_map():
|
||||
_logs.log_debug(res)
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_debug()
|
||||
init_debug_simulation()
|
||||
#init_debug_attack_loop()
|
||||
#init_debug_event_loop()
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
from entities import player as _player
|
||||
from entities import event_picker as _events
|
||||
from entities import gamemap as _map
|
||||
from entities.items import weapons as _weapons
|
||||
from entities.items import item as _items
|
||||
from utils import logs as _logs
|
||||
|
||||
class BrSimArena():
|
||||
|
||||
# players = [{'name': name, 'inventory': default_inventory, other_stats}]
|
||||
# weapons = [{WEAPON.KNIFE: quantity}, etc...] # this is the whole quantity of the items available on the world
|
||||
# items = [{WEAPON.KNIFE: quantity}, etc...] # this is the whole quantity of the items available on the world
|
||||
|
||||
def __init__(self, players= None, weapons= None):
|
||||
def __init__(self, players= None, items= None):
|
||||
self.day= 1
|
||||
self.players= []
|
||||
self.weapons= []
|
||||
self.items= []
|
||||
self.eventClass = _events.ArenaEventPicker(self.players)
|
||||
self.init_players(players)
|
||||
self.init_weapons(weapons)
|
||||
self.Map= _map.BrSimMap(self.players, self.weapons)
|
||||
self.init_items(items)
|
||||
self.Map= _map.BrSimMap(self.players, self.items)
|
||||
|
||||
def init_players(self, players):
|
||||
if not players: return
|
||||
for player in players:
|
||||
self.add_player(player['name'], player.get('inventory'))
|
||||
|
||||
def init_weapons(self, weapons):
|
||||
if not weapons: return
|
||||
for weapon in weapons:
|
||||
for wtype, quantity in weapon.items():
|
||||
for i in range(quantity): self.weapons.append(_weapons.BrSimWeapon(wtype))
|
||||
def init_items(self, items):
|
||||
if not items: return
|
||||
for item_id in items:
|
||||
I= _items.BrSimItem(item_id)
|
||||
self.items.append(I)
|
||||
|
||||
def next_day(self):
|
||||
self.day+= 1
|
||||
@@ -103,7 +103,8 @@ class BrSimArena():
|
||||
|
||||
def do_random_event(self):
|
||||
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
||||
pass
|
||||
self.eventClass.resolve_event()
|
||||
self.next_day()
|
||||
|
||||
def supporter_donation(self):
|
||||
#XXX supporter donate a random item or weapon to a random player
|
||||
@@ -115,19 +116,19 @@ class BrSimArena():
|
||||
self.players.append(player)
|
||||
self.Map.add_player_to_map(player)
|
||||
|
||||
def add_weapon(self, weapon_type):
|
||||
weapon= _weapons.BrSimWeapon(weapon_type)
|
||||
self.weapons.append(weapon)
|
||||
self.Map.add_item_to_map(item)
|
||||
def add_item(self, item_id):
|
||||
Item= _items.BrSimItem(item_id)
|
||||
self.items.append(Item)
|
||||
self.Map.add_item_to_map(Item)
|
||||
|
||||
def get_players(self):
|
||||
return self.players
|
||||
|
||||
def get_weapons(self):
|
||||
def get_items(self):
|
||||
res= []
|
||||
for w in self.weapons:
|
||||
for i in self.items:
|
||||
#XXX implement me
|
||||
res.append(w)
|
||||
res.append(i)
|
||||
return res
|
||||
|
||||
def get_map(self):
|
||||
|
||||
@@ -7,21 +7,21 @@ class ArenaEventPicker():
|
||||
self.event_list = EVENTS
|
||||
self.already_picked_players = []
|
||||
|
||||
def pick_a_player():
|
||||
def pick_a_player(self):
|
||||
the_player = _random.choice(self.players)
|
||||
the_player_id = the_player.get('id')
|
||||
the_player_id = the_player.get_id()
|
||||
|
||||
self.players = list(filter(lambda x : x.get('id') != the_player_id))
|
||||
self.players = list(filter(lambda x : x.get_id() != the_player_id, self.players))
|
||||
|
||||
self.already_picked_players.append(the_player)
|
||||
|
||||
return the_player
|
||||
|
||||
def pick_event(the_player):
|
||||
def pick_event(self, the_player):
|
||||
|
||||
player_inventory = the_player.get('inventory') or []
|
||||
status = the_player['health']
|
||||
reputation = the_player['reputation']
|
||||
player_inventory = the_player.get_inventory()
|
||||
status = the_player.get_health()
|
||||
reputation = the_player.get_reputation()
|
||||
|
||||
elegible_events = []
|
||||
for event in EVENTS:
|
||||
@@ -56,17 +56,23 @@ class ArenaEventPicker():
|
||||
|
||||
if check == 'affected_players':
|
||||
needed_players = event.get('affected_players')
|
||||
if needed_players < len(self.players):
|
||||
elegible_events.append(event)
|
||||
#NOTE: this is only to compensate a double type of needed_players
|
||||
# check NOTE on assets/events.py
|
||||
if isinstance(needed_players, list):
|
||||
if len(needed_players) < len(self.players):
|
||||
elegible_events.append(event)
|
||||
else:
|
||||
if needed_players < len(self.players):
|
||||
elegible_events.append(event)
|
||||
|
||||
the_event = _random.choice(elegible_events)
|
||||
return the_event
|
||||
|
||||
def pick_targets(number_of_targets):
|
||||
random.shuffle(self.players)
|
||||
def pick_targets(self, number_of_targets):
|
||||
_random.shuffle(self.players)
|
||||
return list(self.players[0:number_of_targets])
|
||||
|
||||
def resolve_event():
|
||||
def resolve_event(self):
|
||||
playing_player = self.pick_a_player()
|
||||
assigned_event = self.pick_event(playing_player)
|
||||
|
||||
@@ -75,7 +81,6 @@ class ArenaEventPicker():
|
||||
affected_players = _random.choice(affected_players)
|
||||
|
||||
targeted_players = self.pick_targets(affected_players)
|
||||
|
||||
event_instance = _event.Event(assigned_event, playing_player)
|
||||
|
||||
|
||||
# FIXME this is not implemented
|
||||
#event_instance = _event.Event(assigned_event, playing_player)
|
||||
|
||||
@@ -6,7 +6,6 @@ from PIL import ImageDraw as _ImageDraw
|
||||
from utils import logs as _logs
|
||||
from bot_libs import syms as _bot_syms
|
||||
from entities import resource as _resource
|
||||
from utils import logs as _logs
|
||||
|
||||
|
||||
class BrSimMap():
|
||||
@@ -52,20 +51,17 @@ class BrSimMap():
|
||||
#if i == 0 or i == self.world_height - 1: self.game_map.append(mon)
|
||||
#else: self.game_map.append(_copy.deepcopy(width))
|
||||
self.game_map.append(_copy.deepcopy(width))
|
||||
_logs.log_debug(f'init_map_matrix: {self.game_map}')
|
||||
#_logs.log_debug(f'init_map_matrix: {self.game_map}')
|
||||
_logs.log_debug(f'players: %s'% [(p.get_name(), p.get_coordinates()) for p in self.players])
|
||||
_logs.log_debug(f'items: %s' % [(i.get_name(), i.get_coordinates()) for i in self.items])
|
||||
|
||||
def populate_map(self):
|
||||
for player in self.players:
|
||||
p_coord_x, p_coord_y= player.get_coordinates()
|
||||
self.game_map[p_coord_y][p_coord_x]= player
|
||||
#if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym
|
||||
#elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
|
||||
#elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
|
||||
#else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
|
||||
for item in self.items:
|
||||
i_coord_x, i_coord_y= item.get_coordinates()
|
||||
self.game_map[p_coord_y][p_coord_x]= item
|
||||
#self.game_map[i_coord_y][i_coord_x]= self.item_sym
|
||||
self.game_map[i_coord_y][i_coord_x]= item
|
||||
|
||||
def _put_resource_on_map(self, target):
|
||||
#x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain
|
||||
|
||||
@@ -1,27 +1,36 @@
|
||||
import random as _random
|
||||
from entities import resource as _resource
|
||||
from entities.items import syms as _isyms
|
||||
|
||||
class BrSimItem(_resource.BrSimResource):
|
||||
#XXX i don't know yet if we need to call this clas
|
||||
# or we need to have subclasses that inherit this one
|
||||
# for example class Weapon and class Medikit (or something else)
|
||||
# this decision would change everything from Arena init
|
||||
|
||||
# test
|
||||
def __init__(self):
|
||||
self.coord_x= 0
|
||||
self.coord_y= 0
|
||||
def __init__(self, item_id):
|
||||
super().__init__()
|
||||
self.item= _isyms.ITEMS[item_id]
|
||||
|
||||
def is_item(self):
|
||||
return True
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
def get_data(self):
|
||||
return self.item
|
||||
|
||||
def get_item_type(self):
|
||||
return self.item_type
|
||||
def get_name(self):
|
||||
idata= self.get_data()
|
||||
return idata['name']
|
||||
|
||||
def get_weight(self):
|
||||
return self.weight
|
||||
idata= self.get_data()
|
||||
return idata['weight']
|
||||
|
||||
def is_weapon(self):
|
||||
return False
|
||||
idata= self.get_data()
|
||||
return idata['is_weapon']
|
||||
|
||||
def is_cure(self):
|
||||
return False
|
||||
#XXX not sure about it
|
||||
# maybe we could have more item type, like foods, drink, poison...
|
||||
return not self.is_weapon()
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
KNIFE= 1
|
||||
ARCH= 2
|
||||
MEDIKIT= 1
|
||||
#FOOD= 2 #XXX not yet implemented, how to manage it?
|
||||
#DRINK= 3 #XXX not yet implemented, how to manage it?
|
||||
|
||||
KNIFE= 4
|
||||
ARCH= 5
|
||||
|
||||
SHORT_RANGE= 1
|
||||
FAR_RANGE= 2
|
||||
|
||||
WEAPONS= {
|
||||
ITEMS= {
|
||||
MEDIKIT: {
|
||||
'is_weapon': False,
|
||||
'weight': 0.5,
|
||||
'name': 'medikit',
|
||||
'description': 'useful tool to restore health',
|
||||
'health': 1,
|
||||
},
|
||||
KNIFE: {
|
||||
'is_weapon': True,
|
||||
'weight': 1,
|
||||
'name': 'knife',
|
||||
'damage': 3,
|
||||
@@ -14,6 +26,7 @@ WEAPONS= {
|
||||
'range': SHORT_RANGE,
|
||||
},
|
||||
ARCH: {
|
||||
'is_weapon': True,
|
||||
'weight': 2,
|
||||
'name': 'gun',
|
||||
'damage': 3,
|
||||
@@ -22,3 +35,5 @@ WEAPONS= {
|
||||
'range': FAR_RANGE,
|
||||
},
|
||||
}
|
||||
|
||||
ITEMS_LIST= list(ITEMS.keys())
|
||||
@@ -5,7 +5,7 @@ from entities.items import weapon_syms as _syms
|
||||
class BrSimWeapon(_item.BrSimItem):
|
||||
|
||||
def __init__(self, wtype= None):
|
||||
self.weapon= _syms.WEAPONS[wtype or _random.randint(1,2)]
|
||||
self.weapon= _syms.WEAPONS.get(wtype) or _syms.WEAPONS.get(_random.choice(list(_syms.WEAPONS.keys())))
|
||||
self.name= self.weapon['name']
|
||||
self.damage= self.weapon['damage']
|
||||
self.weight= self.weapon['weight']
|
||||
|
||||
@@ -6,7 +6,7 @@ from utils import logs as _logs
|
||||
class BrSimPlayer(_resource.BrSimResource):
|
||||
|
||||
def __init__(self, name, inventory= None):
|
||||
super()
|
||||
super().__init__()
|
||||
self.id= str(_uuid.uuid4())
|
||||
self.name= name
|
||||
self.stats= ''
|
||||
|
||||
Reference in New Issue
Block a user