diff --git a/ai_manager.py b/ai_manager.py index 1c48a54..392833d 100644 --- a/ai_manager.py +++ b/ai_manager.py @@ -316,7 +316,9 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, sp_nam # # [ (, ), (, ), etc. ] # sorted_players = sorted(players.items(), key=lambda x: x[1]['cost'], reverse=True) - l_query = await db_get(f'teams/{team_object["id"]}/lineup/{league_name}?pitcher_name={sp_name}') + build_type = 'fun' + l_query = await db_get(f'teams/{team_object["id"]}/lineup/{league_name}?pitcher_name={sp_name}' + f'&build_type={build_type}') sorted_players = l_query['array'] logging.info(f'sorted_players: {sorted_players}') diff --git a/cogs/gameplay.py b/cogs/gameplay.py index cce7310..403d5d5 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -372,7 +372,7 @@ class Gameplay(commands.Cog): logging.debug(f'got embed') if game.is_pd: - footer_text = f'PD Season {PD_SEASON}' + footer_text = f'Paper Dynasty Season {PD_SEASON}' if game.short_game: footer_text += f' - Reminder: all pitchers have POW(1) in 3-inning games' embed.set_footer(text=footer_text, icon_url=IMAGES['logo']) @@ -869,6 +869,10 @@ class Gameplay(commands.Cog): advance_one_runner(this_play.id, from_base=3, num_bases=1) if this_play.starting_outs < 2 and this_play.on_second: + logging.debug(f'calling of embed') + await show_outfield_cards(interaction, this_play) + logging.debug(f'done with of embed') + ai_hint = '' if this_game.ai_team and ai_batting(this_game, this_play): ai_hint = f'*The runner will {get_manager(this_game).tag_from_second(this_play.starting_outs + 1)}*' @@ -907,6 +911,10 @@ class Gameplay(commands.Cog): patch_play(this_play.id, locked=True, pa=1, ab=1, outs=1) advance_runners(this_play.id, num_bases=0) if this_play.starting_outs < 2 and this_play.on_third: + logging.debug(f'calling of embed') + await show_outfield_cards(interaction, this_play) + logging.debug(f'done with of embed') + ai_hint = '' if ai_batting(this_game, this_play): ai_hint = f'*The runner will {get_manager(this_game).tag_from_third(this_play.starting_outs + 1)}*' @@ -2771,6 +2779,7 @@ class Gameplay(commands.Cog): if this_play.on_base_code in [1, 2, 4, 5, 6, 7]: ai_manager = get_manager(this_game) ai_is_batting = ai_batting(this_game, this_play) + def_team = await db_get('teams', object_id=this_play.pitcher.team_id) to_bases = [None, None, 'to second', 'to third', 'home'] at_bases = [None, None, 'at second', 'at third', 'at home'] @@ -2794,6 +2803,9 @@ class Gameplay(commands.Cog): ai_hint = f'*The runner will ' \ f'{ai_manager.uncapped_advance(lead_base, this_play.starting_outs)}*' + logging.debug(f'calling of embed') + await show_outfield_cards(interaction, this_play) + logging.debug(f'done with of embed') view = Confirm(responders=[interaction.user], timeout=60, label_type='yes') question = await interaction.channel.send( f'Is {lead_runner["p_name"]} being sent {to_bases[lead_base]}?\n\n{ai_hint}', view=view @@ -2918,9 +2930,16 @@ class Gameplay(commands.Cog): logging.debug(f'post process batter runner on_second_final: {this_play.on_second_final}') complete_play(this_play.id, batter_to_base=batter_to_base) - await interaction.edit_original_response( - content=None, embed=await self.get_game_state_embed(this_game, full_length=False) - ) + if single_type == 'uncapped': + await interaction.edit_original_response(content=f'Uncapped single has been logged') + await interaction.channel.send( + content=None, + embed=await self.get_game_state_embed(this_game, full_length=False) + ) + else: + await interaction.edit_original_response( + content=None, embed=await self.get_game_state_embed(this_game, full_length=False) + ) @group_log.command(name='frame-pitch', description=f'Walk/strikeout split; determined by home plate umpire') async def log_frame_check(self, interaction: discord.Interaction): @@ -2981,6 +3000,10 @@ class Gameplay(commands.Cog): ai_hint = f'*The runner will ' \ f'{ai_manager.uncapped_advance(4, this_play.starting_outs)}*' + logging.debug(f'calling of embed') + await show_outfield_cards(interaction, this_play) + logging.debug(f'done with of embed') + runner_to_home = await get_player(this_game, this_play.on_first) view = Confirm(responders=[interaction.user], timeout=60, label_type='yes') question = await interaction.channel.send( @@ -3105,6 +3128,7 @@ class Gameplay(commands.Cog): complete_play(this_play.id, batter_to_base=batter_to_base) if double_type == 'uncapped': + await interaction.edit_original_response(content=f'Uncapped double has been logged') await interaction.channel.send( content=None, embed=await self.get_game_state_embed(this_game, full_length=False) @@ -3904,7 +3928,7 @@ class Gameplay(commands.Cog): embed.description = f'{defender["p_name"]}' embed.set_image(url=defender['image']) if this_game.is_pd: - embed.set_footer(text=f'PD Season {PD_SEASON}', icon_url=IMAGES['logo']) + embed.set_footer(text=f'Paper Dynasty Season {PD_SEASON}', icon_url=IMAGES['logo']) await interaction.edit_original_response(content=None, embed=embed) @@ -3944,7 +3968,7 @@ class Gameplay(commands.Cog): embed.description = f'{this_player["name"]}' embed.set_image(url=this_player['image']) if this_game.is_pd: - embed.set_footer(text=f'PD Season {PD_SEASON}', icon_url=IMAGES['logo']) + embed.set_footer(text=f'Paper Dynasty Season {PD_SEASON}', icon_url=IMAGES['logo']) await interaction.edit_original_response(content=None, embed=embed) diff --git a/db_calls.py b/db_calls.py index 1501022..eb73f6a 100644 --- a/db_calls.py +++ b/db_calls.py @@ -252,7 +252,7 @@ async def get_pd_player(player_id, as_dict: Optional[bool] = True): if player_id in PLAYER_CACHE: tdelta = datetime.datetime.now() - PLAYER_CACHE[player_id].created if tdelta.total_seconds() < 1209600: - logging.info(f'this_player: {PLAYER_CACHE[player_id]}') + logging.debug(f'this_player: {PLAYER_CACHE[player_id]}') if as_dict: return PLAYER_CACHE[player_id].to_dict() else: diff --git a/db_calls_gameplay.py b/db_calls_gameplay.py index aabcc75..a0a8179 100644 --- a/db_calls_gameplay.py +++ b/db_calls_gameplay.py @@ -784,9 +784,9 @@ def undo_subs(game: StratGame, new_play_num: int): Lineup.delete().where((Lineup.game_id == game.id) & (Lineup.after_play > new_play_num)).execute() -async def get_player(game, lineup_member) -> dict: +async def get_player(game, lineup_member, as_dict: bool = True): # await asyncio.sleep(0.1) - return await get_pd_player(lineup_member.player_id) + return await get_pd_player(lineup_member.player_id, as_dict=as_dict) if isinstance(game, Game): if game.is_pd: diff --git a/gameplay_helpers.py b/gameplay_helpers.py index 138e6ae..c43b15a 100644 --- a/gameplay_helpers.py +++ b/gameplay_helpers.py @@ -1,10 +1,15 @@ +import asyncio +import copy import logging import random +import discord + import db_calls_gameplay from db_calls_gameplay import StratGame, StratPlay, StratLineup, StratManagerAi, patch_play, advance_runners, \ - complete_play, get_team_lineups, get_or_create_bullpen, get_player, get_sheets, make_sub -from db_calls import db_get, db_post + complete_play, get_team_lineups, get_or_create_bullpen, get_player, get_sheets, make_sub, get_one_lineup +from db_calls import db_get, db_post, Player +from helpers import Pagination, get_team_embed, image_embed def single_onestar(this_play: StratPlay, comp_play: bool = True): @@ -175,3 +180,74 @@ async def legal_check(card_ids: list): return r_val + +async def show_outfield_cards(interaction: discord.Interaction, this_play: StratPlay): + lf_player = await get_player(this_play.game, as_dict=False, lineup_member=get_one_lineup( + this_play.game.id, team_id=this_play.pitcher.team_id, position='LF', active=True + )) + cf_player = await get_player(this_play.game, as_dict=False, lineup_member=get_one_lineup( + this_play.game.id, team_id=this_play.pitcher.team_id, position='CF', active=True + )) + rf_player = await get_player(this_play.game, as_dict=False, lineup_member=get_one_lineup( + this_play.game.id, team_id=this_play.pitcher.team_id, position='RF', active=True + )) + this_team = await db_get('teams', object_id=this_play.pitcher.team_id) + logging.debug(f'lf: {lf_player}\n\ncf: {cf_player}\n\nrf: {rf_player}\n\nteam: {this_team["lname"]}') + + view = Pagination([interaction.user], timeout=6) + view.left_button.label = f'Left Fielder' + view.left_button.style = discord.ButtonStyle.secondary + lf_embed = image_embed( + lf_player.image, f'{this_team["sname"]} LF', this_team['color'], lf_player.p_name, this_team['lname'], + this_team['logo']) + + view.cancel_button.label = f'Center Fielder' + view.cancel_button.style = discord.ButtonStyle.blurple + cf_embed = image_embed( + cf_player.image, f'{this_team["sname"]} CF', this_team['color'], cf_player.p_name, this_team['lname'], + this_team['logo']) + + view.right_button.label = f'Right Fielder' + view.right_button.style = discord.ButtonStyle.secondary + rf_embed = image_embed( + rf_player.image, f'{this_team["sname"]} RF', this_team['color'], rf_player.p_name, this_team['lname'], + this_team['logo']) + + page_num = 1 + embeds = [lf_embed, cf_embed, rf_embed] + + msg = await interaction.channel.send(embed=embeds[page_num], view=view) + + await view.wait() + + if view.value: + if view.value == 'left': + page_num = 0 + if view.value == 'cancel': + page_num = 1 + if view.value == 'right': + page_num = 2 + else: + await msg.edit(content=None, embed=embeds[page_num], view=None) + + view.value = None + + if page_num == 0: + view.left_button.style = discord.ButtonStyle.blurple + view.cancel_button.style = discord.ButtonStyle.secondary + view.right_button.style = discord.ButtonStyle.secondary + if page_num == 1: + view.left_button.style = discord.ButtonStyle.secondary + view.cancel_button.style = discord.ButtonStyle.blurple + view.right_button.style = discord.ButtonStyle.secondary + if page_num == 2: + view.left_button.style = discord.ButtonStyle.secondary + view.cancel_button.style = discord.ButtonStyle.secondary + view.right_button.style = discord.ButtonStyle.blurple + + view.left_button.disabled = True + view.cancel_button.disabled = True + view.right_button.disabled = True + + await msg.edit(content=None, embed=embeds[page_num], view=view) + return [lf_player, cf_player, rf_player][page_num]