From 16225aea13cecb365f03e4f5989ce70a7d0130af Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sun, 5 Nov 2023 20:02:43 -0600 Subject: [PATCH] Major League Campaign update Prepping for Flashback campaign --- ai_manager.py | 6 ++- cogs/economy.py | 32 +++++++++++++ cogs/gameplay.py | 109 ++++++++++++++++++++++++++++++-------------- gameplay_helpers.py | 7 +-- 4 files changed, 114 insertions(+), 40 deletions(-) diff --git a/ai_manager.py b/ai_manager.py index 392833d..34f01c7 100644 --- a/ai_manager.py +++ b/ai_manager.py @@ -317,8 +317,10 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, sp_nam # sorted_players = sorted(players.items(), key=lambda x: x[1]['cost'], reverse=True) 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}') + l_query = await db_get( + f'teams/{team_object["id"]}/lineup/{league_name}?pitcher_name={sp_name}&build_type={build_type}', + timeout=6 + ) sorted_players = l_query['array'] logging.info(f'sorted_players: {sorted_players}') diff --git a/cogs/economy.py b/cogs/economy.py index a7e71c7..d74923c 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -350,6 +350,38 @@ class Economy(commands.Cog): ) await ctx.send(content=None, embed=embed) + @pd_help_command.command(name='cardsets', help='Show Cardset Requirements') + @commands.check(legal_channel) + async def help_cardsets(self, ctx: commands.Context): + embed = get_team_embed(f'Paper Dynasty Help') + embed.description = 'Cardset Requirements' + embed.add_field( + name='Ranked Legal', + value='2018 Season, 2023 Season, 2023 Promos', + inline=False + ) + embed.add_field( + name='Minor League', + value='Humans: Unlimited\nAI: 2018 Season / 2023 & 2022 Seasons as backup', + inline=False + ) + embed.add_field( + name='Major League', + value='Humans: Ranked Legal\nAI: 2023, 2018, 2013, 2008 Seasons / 2022 & 2019 as backup', + inline=False + ) + embed.add_field( + name='Flashback', + value='2016, 2013, 2012, 2008 Seasons', + inline=False + ) + embed.add_field( + name='Hall of Fame', + value='Humans: Ranked Legal\nAI: Unlimited', + inline=False + ) + await ctx.send(content=None, embed=embed) + @commands.hybrid_group(name='donation', help='Mod: Give packs for PD donations') @commands.has_any_role(PD_PLAYERS_ROLE_NAME) async def donation(self, ctx: commands.Context): diff --git a/cogs/gameplay.py b/cogs/gameplay.py index 403d5d5..8dda6c9 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -914,7 +914,7 @@ class Gameplay(commands.Cog): logging.debug(f'calling of embed') await show_outfield_cards(interaction, this_play) logging.debug(f'done with of embed') - + ai_hint = '' 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)}*' @@ -959,7 +959,8 @@ class Gameplay(commands.Cog): sp_card_id='Light gray number to the left of the pitcher\'s name on your depth chart') @commands.has_any_role(PD_PLAYERS_ROLE_NAME) async def new_game_campaign_command( - self, interaction: discord.Interaction, league: Literal['Minor League', 'Major League', 'Hall of Fame'], + self, interaction: discord.Interaction, + league: Literal['Minor League', 'Flashback', 'Major League', 'Hall of Fame'], away_team_abbrev: str, home_team_abbrev: str, num_innings: Literal[9, 3], sp_card_id: int): await interaction.response.defer() @@ -1036,38 +1037,47 @@ class Gameplay(commands.Cog): if 'Minor' in league: league_name = 'minor-league' + elif 'Flashback' in league: + await interaction.edit_original_response( + content='The **Flashback Campaign** will pit you against all 30 MLB clubs with both you and the AI ' + 'being limited to the 2008, 2012, 2013, and 2016 cardsets. This campaign will open up in ' + 'mid-November!' + ) + return + elif 'Major' in league: + can_play = False + for x in interaction.user.roles: + if x.name == 'PD - Major League': + can_play = True + + if not can_play: + await interaction.edit_original_response( + content=f'Ope. Looks like you haven\'t received the **PD - Major League** role, yet!\n\n' + f'To play **Major League** games, you need to defeat all 30 MLB teams in the Minor League ' + f'campaign. You can see your progress with `/record`.\n\n' + f'If you have completed the Minor League campaign, go ping Cal to get your new role!') + return + league_name = 'major-league' else: await interaction.edit_original_response( - content=f'Gold star for speed running the Minor Leagues! The Major League campaign will release soon!') + content='The **Hall of Fame Campaign** will pit you against all 30 MLB clubs with you ' + 'being limited to ranked-legal cardsets (2023 & 2018) and the AI having no limits. ' + 'This campaign will open up in December!' + ) return - # elif 'Major' in league: - # can_play = False - # for x in interaction.user.roles: - # if x.name == 'PD - Major League': - # can_play = True - # - # if not can_play: - # await interaction.edit_original_response( - # content=f'Ope. Looks like you haven\'t received the **PD - Major League** role, yet!\n\n' - # f'To play **Major League** games, you need to defeat all 30 MLB teams in the Minor League ' - # f'campaign. You can see your progress with `/record`.\n\n' - # f'If you have completed the Minor League campaign, go ping Cal to get your new role!') - # return - # league_name = 'major-league' - # else: - # can_play = False - # for x in interaction.user.roles: - # if x.name == 'PD - Hall of Fame': - # can_play = True - # - # if not can_play: - # await interaction.edit_original_response( - # content=f'Ope. Looks like you haven\'t received the **PD - Hall of Fame** role, yet!\n\n' - # f'To play **Hall of Fame** games, you need to defeat all 30 MLB teams in the Minor League ' - # f'and Major League campaign. You can see your progress with `/record`.\n\n' - # f'If you have completed the Major League campaign, go ping Cal to get your new role!') - # return - # league_name = 'hall-of-fame' + can_play = False + for x in interaction.user.roles: + if x.name == 'PD - Hall of Fame': + can_play = True + + if not can_play: + await interaction.edit_original_response( + content=f'Ope. Looks like you haven\'t received the **PD - Hall of Fame** role, yet!\n\n' + f'To play **Hall of Fame** games, you need to defeat all 30 MLB teams in the Minor League ' + f'and Major League campaign. You can see your progress with `/record`.\n\n' + f'If you have completed the Major League campaign, go ping Cal to get your new role!') + return + league_name = 'hall-of-fame' this_game = post_game({ 'away_team_id': away_team['id'], @@ -1082,7 +1092,8 @@ class Gameplay(commands.Cog): 'game_type': league_name }) logging.info( - f'Game {this_game.id} between {away_team_abbrev.upper()} and {home_team_abbrev.upper()} is posted!' + f'Game {this_game.id} ({league_name}) between {away_team_abbrev.upper()} and ' + f'{home_team_abbrev.upper()} is posted!' ) away_role = await team_role(interaction, away_team) home_role = await team_role(interaction, home_team) @@ -1095,17 +1106,29 @@ class Gameplay(commands.Cog): logging.error( f'Card_id {sp_card_id} does not belong to {human_team["abbrev"]} in Game {this_game.id}' ) + patch_game(this_game.id, active=False) await interaction.channel.send( f'Uh oh. Card ID {sp_card_id} is {human_team["player"]["p_name"]} and belongs to ' f'{human_sp_card["team"]["sname"]}. Will you double check that before we get started?') return if this_game.game_type in ['major-league', 'hall-of-fame']: - l_check = await legal_check([human_sp_card['id']]) + l_check = await legal_check([human_sp_card['id']], 'ranked') if not l_check['legal']: + patch_game(this_game.id, active=False) await interaction.edit_original_response( content=f'It looks like this is a Ranked Legal game and {player_desc(human_sp_card["player"])} is ' - f'not legal in Ranked. You can start a new game once you get a new SP.' + f'not legal in Ranked. You can start a new game once you pick a new SP.' + ) + return + + if this_game.game_type == 'flashback': + l_check = await legal_check([human_sp_card['id']], 'flashback') + if not l_check['legal']: + patch_game(this_game.id, active=False) + await interaction.edit_original_response( + content=f'It looks like this is a Flashback game and {player_desc(human_sp_card["player"])} is ' + f'not legal in Flashback. You can start a new game once you pick a new SP.' ) return @@ -2447,6 +2470,11 @@ class Gameplay(commands.Cog): f'update and set the lineup again.') this_card = await db_get(f'cards', object_id=int(row[1])) + if this_card is None: + raise LookupError( + f'Your {row[0].upper()} has a Card ID or {int(row[1])} and I cannot find that card. Did you sell ' + f'that card by chance? Or did you sell a duplicate and the bot sold the one you were using?' + ) if this_card['team']['id'] != lineup_team['id']: raise SyntaxError(f'Easy there, champ. Looks like card ID {row[1]} belongs to the ' f'{this_card["team"]["sname"]}. Try again with only cards you own.') @@ -2473,7 +2501,7 @@ class Gameplay(commands.Cog): # Check roster legality if this_game.game_type in ['major-league', 'hall-of-fame']: - l_check = await legal_check(card_ids) + l_check = await legal_check(card_ids, 'ranked') if not l_check['legal']: await interaction.edit_original_response( content=f'It looks like this is a Ranked Legal game and I see the following cards as illegal. ' @@ -2482,6 +2510,17 @@ class Gameplay(commands.Cog): ) return + if this_game.game_type == 'flashback': + l_check = await legal_check(card_ids, 'flashback') + if not l_check['legal']: + patch_game(this_game.id, active=False) + await interaction.edit_original_response( + content=f'It looks like this is a Flashback game and I see the following cards as illegal. ' + f'Please adjust your lineup and re-submit!\n\n' + f'- {l_check["error_string"]}' + ) + return + logging.debug(f'Setting lineup for {lineup_team["sname"]} in PD game') post_lineups(all_lineups) diff --git a/gameplay_helpers.py b/gameplay_helpers.py index c43b15a..327a8c0 100644 --- a/gameplay_helpers.py +++ b/gameplay_helpers.py @@ -169,9 +169,10 @@ def get_pitcher(this_game: StratGame, this_play: StratPlay): return db_calls_gameplay.get_one_lineup(this_game.id, team_id=p_team_id, position='P', active=True) -async def legal_check(card_ids: list): - l_string = "&card_id=".join(card_ids) - legality = await db_post(f'cards/legal-check/ranked?card_id={l_string}') +async def legal_check(card_ids: list, difficulty_name: str): + all_ids = [str(x) for x in card_ids] + l_string = "&card_id=".join(all_ids) + legality = await db_post(f'cards/legal-check/{difficulty_name}?card_id={l_string}') r_val = {'legal': True, 'error_string': None} if legality['count'] > 0: