From 67da23cc17b8ecb1ac9ee1b7bef2f4a4fb87ff07 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 24 Feb 2024 20:47:06 -0600 Subject: [PATCH] Add rare play support --- cogs/gameplay.py | 100 +++++++++++++++++++++++++++++++++++++++++++---- helpers.py | 6 +-- 2 files changed, 96 insertions(+), 10 deletions(-) diff --git a/cogs/gameplay.py b/cogs/gameplay.py index 4e3e030..aff8611 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -859,7 +859,7 @@ class Gameplay(commands.Cog): if this_play.starting_outs == 2 or this_play.on_base_code == 0: patch_play(this_play.id, pa=1, ab=1, outs=1) - elif this_play.starting_outs == 1 and groundball_type == 'a' and runner_on_first(this_play): + elif this_play.starting_outs == 1 and groundball_type == 'a' and this_play.on_base_code == 1: patch_play(this_play.id, pa=1, ab=1, outs=2, on_first_final=False) else: @@ -3896,9 +3896,9 @@ class Gameplay(commands.Cog): await question.delete() view = ButtonOptions( responders=[interaction.user], - labels=['1 base', '2 bases', '3 bases', None, None] + labels=['1 base', '2 bases', '3 bases', 'Rare Play', None] ) - question = await interaction.channel.send(f'How many bases did {defender["p_name"]} allow?', view=view) + question = await interaction.channel.send(f'What kind of error did {defender["p_name"]} allow?', view=view) await view.wait() if not view.value: @@ -4055,7 +4055,7 @@ class Gameplay(commands.Cog): complete_play(this_play.id, batter_to_base) else: - view = ButtonOptions(responders=[interaction.user], labels=['fly A', 'fly B', 'fly C', None, None]) + view = ButtonOptions(responders=[interaction.user], labels=['F1', 'F2', 'F3', None, None]) question = await interaction.channel.send(f'What was the result of the play?', view=view) await view.wait() @@ -4088,7 +4088,10 @@ class Gameplay(commands.Cog): batter_to_base = 4 elif 'double' in hit_allowed: double_threestar(this_play, comp_play=False) - if error_allowed == '1 base': + if error_allowed == 'Rare Play': + patch_play(this_play.id, outs=1) + batter_to_base = None + elif error_allowed == '1 base': batter_to_base = 3 elif error_allowed == '3 bases': batter_to_base = 4 @@ -4100,7 +4103,10 @@ class Gameplay(commands.Cog): # Both singles are handled the same else: single_wellhit(this_play, comp_play=False) - if error_allowed == '1 base': + if error_allowed == 'Rare Play': + patch_play(this_play.id, outs=1) + batter_to_base = None + elif error_allowed == '1 base': batter_to_base = 2 else: advance_runners(this_play.id, 3) @@ -4122,11 +4128,91 @@ class Gameplay(commands.Cog): double_threestar(this_play) elif hit_allowed == 'triple': triple(this_play) + elif error_allowed == 'Rare Play': + if position.value not in ['LF', 'CF', 'RF']: + view = ButtonOptions( + responders=[interaction.user], + labels=['G1', 'G2', 'G3', None if position.value != 'C' else 'FO', + None if position.value != 'C' else 'PO'] + ) + question = await interaction.channel.send(f'What was the result of the play?', view=view) + logging.info(f'obc: {this_play.on_base_code}') + await view.wait() + + logging.info(f'gameplay - view: {view} / view.value: {view.value}') + gb_type = view.value + logging.info(f'gameplay - gb_type: {gb_type}') + if not view.value: + await question.edit('Okay, we can try this again later.') + else: + await question.delete() + if gb_type == 'G1': + if runner_on_first(this_play): + await self.groundballs(interaction, this_game, this_play, 'b') + else: + await self.groundballs(interaction, this_game, this_play, 'a') + elif gb_type == 'G2': + if this_play.on_base_code != 0: + await self.groundballs(interaction, this_game, this_play, 'c') + else: + await self.groundballs(interaction, this_game, this_play, 'b') + elif gb_type == 'G3': + if this_play.on_base_code != 0: + await single_onestar(this_play) + else: + await self.groundballs(interaction, this_game, this_play, 'c') + else: + view = ButtonOptions(responders=[interaction.user], labels=['F1', 'F2', 'F3', None, None]) + question = await interaction.channel.send(f'What was the result of the play?', view=view) + await view.wait() + + if not view.value: + await question.delete() + await interaction.channel.send( + content=f'Just logged the x-check! Please log the resulting play to continue (e.g. ' + f'\'flyball-b\' or \'flyball-c\')' + ) + patch_play(this_play.id, locked=False) + return + + else: + await question.delete() + if view.value == 'F1': + fly_code = 'a' + elif view.value == 'F2': + fly_code = 'b' + else: + fly_code = 'c' + + if this_play.starting_outs == 2 or this_play.on_base_code == 0: + await self.flyballs(interaction, this_game, this_play, fly_code) + else: + if fly_code == 'a': + patch_play(this_play.id, pa=1, ab=1, outs=1) + advance_runners(this_play.id, 2) + if this_play.on_third or this_play.on_second: + patch_play(this_play.id, ab=0) + elif fly_code == 'b': + if runner_on_third(this_play): + patch_play(this_play.id, pa=1, ab=1, outs=2, on_third_final=False) + else: + await self.flyballs(interaction, this_game, this_play, fly_code, comp_play=False) + elif fly_code == 'c': + patch_play(this_play.id, pa=1, ab=1, outs=2) + if runner_on_third(this_play): + patch_play(this_play.id, on_third_final=False) + elif runner_on_second(this_play): + patch_play(this_play.id, on_second_final=False) + else: + patch_play(this_play.id, on_first_final=False) + + complete_play(this_play.id) + else: if position.value == 'C': view = ButtonOptions( responders=[interaction.user], - labels=['gb A', 'gb B', 'gb C', 'FO', 'PO'] + labels=['G1/G2/G3/SPD', 'FO', 'PO'] ) question = await interaction.channel.send(f'What was the result of the play?', view=view) await view.wait() diff --git a/helpers.py b/helpers.py index 1623b25..d454158 100644 --- a/helpers.py +++ b/helpers.py @@ -163,10 +163,10 @@ OUTFIELD_X_CHART = { 'no': 'Single, all runners advance 2 bases.' }, 'do2': { - 'rp': 'Batter doubles, runners advance 2 bases. The outfielder throws the ball to the shortstop who executes ' - 'a hidden ball trick! Runner on second is tagged out!', + 'rp': 'Batter doubles and runners advance three bases, but batter-runner is caught between second and third! ' + 'He is tagged out in the rundown.', 'e1': 'Double and error, batter to third, all runners score.', - 'e2': 'Double and error, batter to third, and all runners score.', + 'e2': 'Double and error, batter to third, all runners score.', 'e3': 'Double and error, batter and all runners score. Little league home run!', 'no': 'Double, all runners advance 2 bases.' },