Add show_outfield_cards

This commit is contained in:
Cal Corum 2023-11-01 23:26:58 -05:00
parent b941f1641e
commit eb22960f2c
5 changed files with 114 additions and 12 deletions

View File

@ -316,7 +316,9 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, sp_nam
# # [ (<pos>, <player_obj>), (<pos>, <player_obj>), etc. ] # # [ (<pos>, <player_obj>), (<pos>, <player_obj>), etc. ]
# sorted_players = sorted(players.items(), key=lambda x: x[1]['cost'], reverse=True) # 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'] sorted_players = l_query['array']
logging.info(f'sorted_players: {sorted_players}') logging.info(f'sorted_players: {sorted_players}')

View File

@ -372,7 +372,7 @@ class Gameplay(commands.Cog):
logging.debug(f'got embed') logging.debug(f'got embed')
if game.is_pd: if game.is_pd:
footer_text = f'PD Season {PD_SEASON}' footer_text = f'Paper Dynasty Season {PD_SEASON}'
if game.short_game: if game.short_game:
footer_text += f' - Reminder: all pitchers have POW(1) in 3-inning games' footer_text += f' - Reminder: all pitchers have POW(1) in 3-inning games'
embed.set_footer(text=footer_text, icon_url=IMAGES['logo']) 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) advance_one_runner(this_play.id, from_base=3, num_bases=1)
if this_play.starting_outs < 2 and this_play.on_second: 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 = '' ai_hint = ''
if this_game.ai_team and ai_batting(this_game, this_play): 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)}*' 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) patch_play(this_play.id, locked=True, pa=1, ab=1, outs=1)
advance_runners(this_play.id, num_bases=0) advance_runners(this_play.id, num_bases=0)
if this_play.starting_outs < 2 and this_play.on_third: 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 = '' ai_hint = ''
if ai_batting(this_game, this_play): 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)}*' 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]: if this_play.on_base_code in [1, 2, 4, 5, 6, 7]:
ai_manager = get_manager(this_game) ai_manager = get_manager(this_game)
ai_is_batting = ai_batting(this_game, this_play) 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'] to_bases = [None, None, 'to second', 'to third', 'home']
at_bases = [None, None, 'at second', 'at third', 'at 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 ' \ ai_hint = f'*The runner will ' \
f'{ai_manager.uncapped_advance(lead_base, this_play.starting_outs)}*' 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') view = Confirm(responders=[interaction.user], timeout=60, label_type='yes')
question = await interaction.channel.send( question = await interaction.channel.send(
f'Is {lead_runner["p_name"]} being sent {to_bases[lead_base]}?\n\n{ai_hint}', view=view 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}') 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) complete_play(this_play.id, batter_to_base=batter_to_base)
await interaction.edit_original_response( if single_type == 'uncapped':
content=None, embed=await self.get_game_state_embed(this_game, full_length=False) 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') @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): async def log_frame_check(self, interaction: discord.Interaction):
@ -2981,6 +3000,10 @@ class Gameplay(commands.Cog):
ai_hint = f'*The runner will ' \ ai_hint = f'*The runner will ' \
f'{ai_manager.uncapped_advance(4, this_play.starting_outs)}*' 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) runner_to_home = await get_player(this_game, this_play.on_first)
view = Confirm(responders=[interaction.user], timeout=60, label_type='yes') view = Confirm(responders=[interaction.user], timeout=60, label_type='yes')
question = await interaction.channel.send( question = await interaction.channel.send(
@ -3105,6 +3128,7 @@ class Gameplay(commands.Cog):
complete_play(this_play.id, batter_to_base=batter_to_base) complete_play(this_play.id, batter_to_base=batter_to_base)
if double_type == 'uncapped': if double_type == 'uncapped':
await interaction.edit_original_response(content=f'Uncapped double has been logged')
await interaction.channel.send( await interaction.channel.send(
content=None, content=None,
embed=await self.get_game_state_embed(this_game, full_length=False) 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.description = f'{defender["p_name"]}'
embed.set_image(url=defender['image']) embed.set_image(url=defender['image'])
if this_game.is_pd: 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) await interaction.edit_original_response(content=None, embed=embed)
@ -3944,7 +3968,7 @@ class Gameplay(commands.Cog):
embed.description = f'{this_player["name"]}' embed.description = f'{this_player["name"]}'
embed.set_image(url=this_player['image']) embed.set_image(url=this_player['image'])
if this_game.is_pd: 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) await interaction.edit_original_response(content=None, embed=embed)

View File

@ -252,7 +252,7 @@ async def get_pd_player(player_id, as_dict: Optional[bool] = True):
if player_id in PLAYER_CACHE: if player_id in PLAYER_CACHE:
tdelta = datetime.datetime.now() - PLAYER_CACHE[player_id].created tdelta = datetime.datetime.now() - PLAYER_CACHE[player_id].created
if tdelta.total_seconds() < 1209600: 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: if as_dict:
return PLAYER_CACHE[player_id].to_dict() return PLAYER_CACHE[player_id].to_dict()
else: else:

View File

@ -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() 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) # 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 isinstance(game, Game):
if game.is_pd: if game.is_pd:

View File

@ -1,10 +1,15 @@
import asyncio
import copy
import logging import logging
import random import random
import discord
import db_calls_gameplay import db_calls_gameplay
from db_calls_gameplay import StratGame, StratPlay, StratLineup, StratManagerAi, patch_play, advance_runners, \ 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 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 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): def single_onestar(this_play: StratPlay, comp_play: bool = True):
@ -175,3 +180,74 @@ async def legal_check(card_ids: list):
return r_val 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]