diff --git a/cogs/gameplay.py b/cogs/gameplay.py index e3d60a1..f5a5314 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -6,6 +6,8 @@ import os import ai_manager import discord + +import dice import gauntlets from discord import app_commands from discord.app_commands import Choice @@ -2553,6 +2555,34 @@ class Gameplay(commands.Cog): 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): + this_game, owner_team, this_play = await self.checks_log_interaction(interaction) + if False in (this_game, owner_team, this_play): + return + + patch_play(this_play.id, locked=True) + + frame_result = dice.frame_plate_check(owner_team, this_game.id) + logging.info(f'Frame Result:\n{frame_result}') + await interaction.edit_original_response( + content=None, + embed=frame_result['embed'] + ) + + if frame_result['is_walk']: + advance_runners(this_play.id, num_bases=1, only_forced=True) + patch_play(this_play.id, pa=1, walk=1) + else: + patch_play(this_play.id, pa=1, ab=1, outs=1, so=1) + advance_runners(this_play.id, 0) + + complete_play(this_play.id, batter_to_base=1) + + await interaction.channel.send( + content=None, embed=await self.get_game_state_embed(this_game, full_length=False) + ) + @group_log.command(name='double', description='Doubles: **, ***, uncapped') async def log_double(self, interaction: discord.Interaction, double_type: Literal['**', '***', 'uncapped']): this_game, owner_team, this_play = await self.checks_log_interaction(interaction) @@ -2704,9 +2734,15 @@ class Gameplay(commands.Cog): 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 double_type == 'uncapped': + 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='triple', description='Triples: no sub-types') async def log_triple(self, interaction: discord.Interaction): @@ -2746,8 +2782,6 @@ class Gameplay(commands.Cog): if False in (this_game, owner_team, this_play): return - patch_play(this_play.id, locked=True) - patch_play(this_play.id, locked=True) advance_runners(this_play.id, num_bases=1, only_forced=True) diff --git a/dice.py b/dice.py index f5d4dfc..cea97d6 100644 --- a/dice.py +++ b/dice.py @@ -754,3 +754,37 @@ def sa_fielding_roll(pos_code: str, team: dict) -> [discord.Embed]: error2_embed.add_field(name='Error Results', value=error_note2) return [roll_embed, chart_embed, error1_embed, error2_embed] + + +def frame_plate_check(team: dict, game_id: int): + tens_digit = (game_id // 10) % 10 + half_tens = round(tens_digit / 2) + d_twenty = random.randint(1, 20) + roll_message = f'```md\n' \ + f'# {str(d_twenty)}\n' \ + f'Details:[1d20 ({d_twenty})]```' + + umps = [ + {'name': 'Angel Fernando', 'walk_d20': 2 + tens_digit + half_tens}, + {'name': 'Ron Koopa', 'walk_d20': 6 + tens_digit}, + {'name': 'Hunter Enderstedt', 'walk_d20': 2 + half_tens}, + {'name': 'D.C. Bucknor', 'walk_d20': 8 + half_tens}, + {'name': 'Joe East', 'walk_d20': 14 + half_tens}, + {'name': 'Last Diaz', 'walk_d20': 10 + half_tens}, + ] + this_ump = umps[half_tens] + + ump_message = f'```md\n' \ + f' WALK: 1 - {this_ump["walk_d20"]}\n' \ + f'STRIKEOUT: {this_ump["walk_d20"] + 1} - 20\n' \ + f'```' + + result_message = f'**{"WALK" if d_twenty <= this_ump["walk_d20"] else "STRIKEOUT"}**' + + roll_embed = get_dice_embed() + roll_embed.add_field(name=f'Pitch Framing roll for {team["gmname"]}', value=roll_message) + roll_embed.add_field(name=f'Umpire: {this_ump["name"]}', value=ump_message) + roll_embed.add_field(name='Result', value=result_message, inline=False) + roll_embed.set_footer(text="This result will be logged automatically") + + return {'embed': roll_embed, 'is_walk': d_twenty <= this_ump['walk_d20']}