Allow manual override of xcheck

This commit is contained in:
Cal Corum 2025-01-26 11:50:33 -06:00
parent 4a76d59481
commit e850ee5519
2 changed files with 72 additions and 4 deletions

View File

@ -19,7 +19,7 @@ from in_game.game_helpers import PUBLIC_FIELDS_CATEGORY_NAME, legal_check
from in_game.gameplay_models import BattingCard, Card, Game, Lineup, PositionRating, RosterLink, Team, Play
from in_game.gameplay_queries import get_active_games_by_team, get_available_batters, get_batter_card, get_batting_statline, get_game_cardset_links, get_or_create_ai_card, get_pitcher_runs_by_innings, get_pitching_statline, get_plays_by_pitcher, get_position, get_available_pitchers, get_card_or_none, get_channel_game_or_none, get_db_ready_decisions, get_db_ready_plays, get_game_lineups, get_last_team_play, get_one_lineup, get_player_id_from_dict, get_player_name_from_dict, get_player_or_none, get_sorted_lineups, get_team_or_none, get_players_last_pa, post_game_rewards
from in_game.managerai_responses import DefenseResponse
from utilities.buttons import ButtonOptions, Confirm, ask_confirm
from utilities.buttons import ButtonOptions, Confirm, ask_confirm, ask_with_buttons
from utilities.dropdown import DropdownView, SelectBatterSub, SelectStartingPitcher, SelectViewDefense
from utilities.embeds import image_embed
from utilities.pages import Pagination
@ -2443,8 +2443,76 @@ async def xchecks(session: Session, interaction: discord.Interaction, this_play:
logger.info(f'X-Check in Game #{this_play.game_id} at {this_play.check_pos} for {this_play.defender.card.player.name_with_desc} of the {this_play.pitcher.team.sname} / hit_result: {hit_result} / error_result: {error_result} / is_correct: {is_correct}')
if not is_correct:
# TODO: Full questionnaire
pass
logger.error(f'{interaction.user.name} says the result was wrong.')
logger.info(f'Asking if there was a hit')
allow_hit = await ask_confirm(
interaction,
f'Did **{this_defender.player.name}** allow a hit?',
label_type='yes'
)
if allow_hit:
if position in ['1B', '2B', '3B', 'SS', 'P']:
hit_options = ['SI1', 'SI2']
elif position in ['LF', 'CF', 'RF']:
hit_options = ['SI2', 'DO2', 'DO3', 'TR']
else:
hit_options = ['SI1', 'SPD']
logger.info(f'Setting hit options to {hit_options}')
else:
if position in ['1B', '2B', '3B', 'SS', 'P']:
hit_options = ['G3#', 'G3', 'G2#', 'G2', 'G1']
elif position in ['LF', 'CF', 'RF']:
hit_options = ['F1', 'F2', 'F3']
else:
hit_options = ['G3', 'G2', 'G1', 'PO', 'FO']
logger.info(f'Setting hit options to {hit_options}')
new_hit_result = await ask_with_buttons(
interaction,
button_options=hit_options,
question=f'Which result did **{this_defender.player.name}** allow?'
)
if new_hit_result is None:
logger.error(f'No hit result was returned')
return
logger.info(f'new hit result: {new_hit_result}')
logger.info(f'Asking if there was an error')
allow_error = await ask_confirm(
interaction,
f'Did **{this_defender.player.name}** commit an error?',
label_type='yes'
)
if allow_error:
if position in ['1B', '2B', '3B', 'SS', 'P', 'C']:
error_options = ['1 base', '2 bases']
else:
error_options = ['1 base', '2 bases', '3 bases']
logger.info(f'Setting error options to {error_options}')
new_error_result = await ask_with_buttons(
interaction,
button_options=error_options,
question=f'How many bases was **{this_defender.player.name}**\'s error?'
)
if new_error_result is None:
logger.error(f'No error result was returned')
return
else:
if '1' in new_error_result:
new_error_result = 1
elif '2' in new_error_result:
new_error_result = 2
else:
new_error_result = 3
else:
new_error_result = None
logger.info(f'new_error_result: {new_error_result}')
logger.info(f'Setting hit and error results and continuing with processing.')
hit_result = new_hit_result
error_result = new_error_result
if hit_result == 'SPD' and not is_rare_play:
is_out = ask_confirm(

View File

@ -599,7 +599,7 @@ def batting_ai_note(this_play: StratPlay, this_batter: dict):
}
async def check_pitching_sub(this_play: StratPlay, ai_team: dict):
async def check_pitching_sub(this_play: Play, ai_team: Team):
used_pitchers = await get_team_lineups(
game_id=this_play.game.id,
team_id=this_play.pitcher.team_id,