diff --git a/bot.py b/bot.py index 38ebbf1..b075eb3 100644 --- a/bot.py +++ b/bot.py @@ -38,8 +38,18 @@ async def bot_start(update, context): async def bot_commands(update, context): text= update.message.text chat_id = update.effective_chat.id + username= update.effective_chat.username + first_name= update.effective_chat.first_name + last_name= update.effective_chat.last_name + chat_type= update.effective_chat.type.name # PRIVAT|BOT|ETC.. - _log.log_info(f'bot_command: {chat_id} - text received: {text}') + + _log.log_info(f'bot_command: \ +user id="{chat_id}" \ +username="{username}" \ +first_name="{first_name}" \ +last_name="{last_name}" \ +chat_type="{chat_type}"') # init or restart the game if text == 'Init/Restart': diff --git a/bot_libs/syms.py b/bot_libs/syms.py index e301cfb..5b8f15d 100644 --- a/bot_libs/syms.py +++ b/bot_libs/syms.py @@ -103,7 +103,7 @@ MAP_IMAGE_PLAYER_NONBINARY= (255, 255, 0) # yellow MAP_IMAGE_DEATH_PLAYER= (160, 160, 160) # grey MAP_IMAGE_ITEM= (255, 255, 255) # white -MAP_IMAGE_LEGEND= """*Legenda*: +MAP_IMAGE_LEGEND= r"""*Legenda*: \- *Verde*: Cella *libera* per muoversi \- *Nero*: Bordo della mappa, *non raggiungibile* \- *Blue*: Posizione di un *giocatore Maschio* diff --git a/debug.py b/debug.py index 07dd7dd..c7d8572 100644 --- a/debug.py +++ b/debug.py @@ -36,6 +36,33 @@ def _end_game_debug(alive_players, day): print(msg) return msg +def _random_action(Arena, Player_one): + _RANDOM_ACTIONS= { + 1: 'attack', + 2: 'move', + } + action= _rand.randint(1, len(_RANDOM_ACTIONS)) + msg= '' + if action == 1: + # XXX maybe in future this action is available only if you are near to another player + # so Player_two is no more random, but will be a random near player + Player_two= _rand.sample(Arena.get_alive_players(), 1)[0] + while Player_one.get_id() == Player_two.get_id(): + Player_two= _rand.sample(Arena.get_alive_players(), 1)[0] + _dmg, msg= Player_one.attack(Player_two) + elif action == 2: + Map= Arena.get_map() + available_movements= Map.get_player_available_directions(Player_one) + if not available_movements: return f'{Player_one.get_name()} Pensa a Guarino tutto il giorno' # XXX probably should skip this action and look for another action + _rand.shuffle(available_movements) + x, y, direction= available_movements[0] + Player_one.move(x, y) + Map.init_map_matrix() + print(Map.get_renderized_map()) + msg= f'{Player_one.get_name()} Si muove a: {direction}' + + return msg + def play_one_day_debug(Arena): if not Arena.get_players(): return print(f'Giorno #{Arena.day}') @@ -46,12 +73,13 @@ def play_one_day_debug(Arena): daily_events= [] _rand.shuffle(alive_players) - for p_one in alive_players: - if not p_one.is_alive(): continue # he could be dead during this day cycle - p_two= _rand.sample(Arena.get_alive_players(), 1)[0] - while p_one.get_id() == p_two.get_id(): - p_two= _rand.sample(Arena.get_alive_players(), 1)[0] - _dmg, msg= p_one.attack(p_two) + for Player_one in alive_players: + if not Player_one.is_alive(): continue # he could be dead during this day cycle + msg= _random_action(Arena, Player_one) + #p_two= _rand.sample(Arena.get_alive_players(), 1)[0] + #while Player_one.get_id() == p_two.get_id(): + #p_two= _rand.sample(Arena.get_alive_players(), 1)[0] + #_dmg, msg= Player_one.attack(p_two) daily_events.append(msg) Arena.next_day() diff --git a/entities/gamemap.py b/entities/gamemap.py index 2693670..74c7ad8 100644 --- a/entities/gamemap.py +++ b/entities/gamemap.py @@ -36,6 +36,7 @@ class BrSimMap(): # 📦 this is an item (weapon or another item) # 💀 this is icon when the player is dead # ⛰️ this is icon for the mountain (We can prevent players from passing through the mountains and thus use them for map boundaries.) + self.game_map= [] width= [] #mon = [] @@ -94,6 +95,19 @@ class BrSimMap(): def get_map_matrix(self): return self.game_map + + def get_player_available_directions(self, Player): + coord_x, coord_y= Player.get_player_coordinates() + avail_directions= [] + if self.get_map_matrix()[coord_x - 1][coord_y] not in [self.mountain_sym]: + avail_directions.append((-1, 0, 'left')) + if self.get_map_matrix()[coord_x + 1][coord_y] not in [self.mountain_sym]: + avail_directions.append((1, 0, 'right')) + if self.get_map_matrix()[coord_x][coord_y - 1] not in [self.mountain_sym]: + avail_directions.append((0, -1, 'up')) + if self.get_map_matrix()[coord_x][coord_y + 1] not in [self.mountain_sym]: + avail_directions.append((0, 1, 'bottom')) + return avail_directions def get_renderized_map(self): res= '' diff --git a/entities/items/item.py b/entities/items/item.py index 723125a..31f0c47 100644 --- a/entities/items/item.py +++ b/entities/items/item.py @@ -3,6 +3,11 @@ from entities import resource as _resource class BrSimItem(_resource.BrSimResource): + # test + def __init__(self): + self.coord_x= 0 + self.coord_y= 0 + def is_item(self): return True diff --git a/entities/player.py b/entities/player.py index f9c1dcd..2e63c4d 100644 --- a/entities/player.py +++ b/entities/player.py @@ -174,6 +174,28 @@ class BrSimPlayer(_resource.BrSimResource): return False self.inventory.append(item) + def move(self, delta_x, delta_y): + # XXX maps limits: + # probably this isn't player's business + # game orchestror should manage it + # to avoid that the player can go out from the map + # or can reach unaccessible points + # also because the player doens't know the Map (entities/gamemap.py) + self.coord_x += delta_x + self.coord_y += delta_y + + def move_right(self): + self._move(1, 0) + + def move_left(self): + self._move(-1, 0) + + def move_top(self): + self._move(0, -1) + + def move_bottom(self): + self._move(0, 1) + def escape(self): # TODO It can run away from the fighting return