Bunts are done
This commit is contained in:
parent
3d333dabc3
commit
baffabfe4c
@ -12,7 +12,7 @@ from exceptions import *
|
||||
from helpers import DEFENSE_LITERAL, get_channel
|
||||
from in_game.game_helpers import legal_check
|
||||
from in_game.gameplay_models import Game, Lineup, Team, Play
|
||||
from in_game.gameplay_queries import get_card_or_none, get_channel_game_or_none, get_db_ready_decisions, get_db_ready_plays, 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.gameplay_queries import get_and_cache_position, get_card_or_none, get_channel_game_or_none, get_db_ready_decisions, get_db_ready_plays, 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 utilities.buttons import ButtonOptions, Confirm, ask_confirm
|
||||
from utilities.dropdown import DropdownOptions, DropdownView, SelectViewDefense
|
||||
from utilities.embeds import image_embed
|
||||
@ -1071,7 +1071,7 @@ async def hit_by_pitch(session: Session, interaction: discord.Interaction, this_
|
||||
|
||||
async def bunts(session: Session, interaction: discord.Interaction, this_play: Play, bunt_type: Literal['sacrifice', 'bad', 'popout', 'double-play', 'defense']):
|
||||
this_play.ab = 1 if bunt_type != 'sacrifice' else 0
|
||||
this_play.sac = 1 if bunt_type != 'sacrifice' else 0
|
||||
this_play.sac = 1 if bunt_type == 'sacrifice' else 0
|
||||
this_play.outs = 1
|
||||
|
||||
if bunt_type == 'sacrifice':
|
||||
@ -1102,7 +1102,87 @@ async def bunts(session: Session, interaction: discord.Interaction, this_play: P
|
||||
|
||||
elif this_play.on_first is not None:
|
||||
this_play.on_first_final = None
|
||||
|
||||
|
||||
elif bunt_type == 'defense':
|
||||
if this_play.on_third is not None:
|
||||
runner = this_play.on_third
|
||||
lead_base = 4
|
||||
|
||||
elif this_play.on_second is not None:
|
||||
runner = this_play.on_second
|
||||
lead_base = 3
|
||||
|
||||
elif this_play.on_first is not None:
|
||||
runner = this_play.on_first
|
||||
lead_base = 2
|
||||
|
||||
take_sure_out = await ask_confirm(
|
||||
interaction=interaction,
|
||||
question=f'Will you take the sure out at first or throw {TO_BASE[lead_base]} for **{runner.player.name}**?',
|
||||
custom_confirm_label='Out at first',
|
||||
custom_cancel_label=f'Throw {TO_BASE[lead_base]}'
|
||||
)
|
||||
|
||||
if take_sure_out:
|
||||
this_play.ab = 0
|
||||
this_play.sac = 1
|
||||
this_play = advance_runners(session, this_play, num_bases=1)
|
||||
|
||||
else:
|
||||
view = ButtonOptions(
|
||||
responders=[interaction.user],
|
||||
timeout=30,
|
||||
labels=['Pitcher', 'Catcher', 'First Base', 'Third Base', None]
|
||||
)
|
||||
question = await interaction.channel.send(
|
||||
content='Which defender is fielding the bunt? This is determined by the first d6 in your AB roll.',
|
||||
view=view
|
||||
)
|
||||
|
||||
await view.wait()
|
||||
|
||||
if view.value:
|
||||
await question.delete()
|
||||
if view.value == 'Pitcher':
|
||||
defender = this_play.pitcher
|
||||
elif view.value == 'Catcher':
|
||||
defender = this_play.catcher
|
||||
elif view.value == 'First Base':
|
||||
defender = get_one_lineup(session, this_play.game, this_play.batter.team, position='1B')
|
||||
elif view.value == 'Third Base':
|
||||
defender = get_one_lineup(session, this_play.game, this_play.batter.team, position='3B')
|
||||
else:
|
||||
log_exception(NoPlayerResponseException, f'I do not know which defender fielded that ball.')
|
||||
|
||||
else:
|
||||
await question.edit(content='You keep thinking on it and try again.', view=None)
|
||||
log_exception(NoPlayerResponseException, f'{interaction.user.name} did not know who was fielding the bunt.')
|
||||
|
||||
def_pos = await get_and_cache_position(session, defender.card, defender.position)
|
||||
|
||||
lead_runner_out = await ask_confirm(
|
||||
interaction=interaction,
|
||||
question=f'{runner.player.name}\'s safe range is **1 -> {runner.card.batterscouting.battingcard.running - 4 + def_pos.range}**. Is the runner out {AT_BASE[lead_base]}?',
|
||||
custom_confirm_label=f'Out {AT_BASE[lead_base]}',
|
||||
custom_cancel_label=f'Safe {AT_BASE[lead_base]}'
|
||||
)
|
||||
|
||||
if lead_runner_out:
|
||||
this_play = advance_runners(session, this_play, 1)
|
||||
this_play.batter_final = 1
|
||||
|
||||
if this_play.on_third is not None:
|
||||
this_play.on_third_final = None
|
||||
elif this_play.on_second is not None:
|
||||
this_play.on_second_final = None
|
||||
elif this_play.on_first is not None:
|
||||
this_play.on_first_final = None
|
||||
|
||||
else:
|
||||
this_play.outs = 0
|
||||
this_play.batter_final = 1
|
||||
this_play = advance_runners(session, this_play, 1)
|
||||
|
||||
else:
|
||||
log_exception(KeyError, f'Bunt type {bunt_type} is not yet implemented')
|
||||
|
||||
|
||||
@ -50,5 +50,10 @@ class PlayInitException(GameException):
|
||||
class DatabaseError(GameException):
|
||||
pass
|
||||
|
||||
|
||||
class PositionNotFoundException(GameException):
|
||||
pass
|
||||
|
||||
|
||||
class NoPlayerResponseException(GameException):
|
||||
pass
|
||||
|
||||
@ -342,7 +342,7 @@ async def get_and_cache_position(session: Session, this_card: Card, position: Li
|
||||
session.commit()
|
||||
session.refresh(this_pos)
|
||||
|
||||
return this_card
|
||||
return this_pos
|
||||
|
||||
log_exception(PositionNotFoundException, f'{position} ratings not found for {this_card.player.name_with_desc}')
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user