diff --git a/cogs/gameplay.py b/cogs/gameplay.py index 5cf53fa..7cc1798 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -1531,7 +1531,7 @@ class Gameplay(commands.Cog): @group_new_game.command(name='gauntlet', description='Start a new Gauntlet game against an AI') @commands.has_any_role(PD_PLAYERS_ROLE_NAME) async def new_game_gauntlet_command( - self, interaction: discord.Interaction, event_name: Literal['Taste of 2018', 'Super Ultra Championship'], + self, interaction: discord.Interaction, event_name: Literal['2024 Live', 'Super Ultra Championship'], sp_card_id: int): await interaction.response.defer() diff --git a/cogs/players.py b/cogs/players.py index 5af45e0..9b395fe 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -895,7 +895,7 @@ class Players(commands.Cog): ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_run_command( - self, interaction: discord.Interaction, event_name: Literal['Taste of 2018', 'Super Ultra Championship'], + self, interaction: discord.Interaction, event_name: Literal['2024 Live', 'Super Ultra Championship'], team_abbrev: str = None): await interaction.response.defer() @@ -936,7 +936,7 @@ class Players(commands.Cog): @group_gauntlet.command(name='start', description='Start a new Gauntlet run') @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_start_command( - self, interaction: discord.Interaction, event_name: Literal['Taste of 2018', 'Super Ultra Championship']): + self, interaction: discord.Interaction, event_name: Literal['2024 Live', 'Super Ultra Championship']): if 'hello' not in interaction.channel.name: await interaction.response.send_message( content='The draft will probably take you about 15 minutes. Why don\'t you head to your private ' diff --git a/gauntlets.py b/gauntlets.py index 904710e..ccffbd4 100644 --- a/gauntlets.py +++ b/gauntlets.py @@ -161,6 +161,32 @@ async def get_opponent(this_team, this_event, this_run): else: raise KeyError(f'Hmm...I do not know who you should be playing right now.') return await db_get('teams', object_id=t_id, none_okay=False) + elif this_event['id'] == 5: + if gp == 0: + t_id = 6 + elif gp == 1: + t_id = 15 + elif gp == 2: + t_id = 12 + elif gp == 3: + t_id = 25 + elif gp == 4: + t_id = 26 + elif gp == 5: + t_id = 21 + elif gp == 6: + t_id = 9 + elif gp == 7: + t_id = 30 + elif gp == 8: + t_id = 8 + elif gp == 9: + t_id = 7 + elif gp == 10: + t_id = 19 + else: + raise KeyError(f'Hmm...I do not know who you should be playing right now.') + return await db_get('teams', object_id=t_id, none_okay=False) else: return None @@ -271,6 +297,11 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra embed_description = f'{this_event["name"]}' base_params = [('cardset_id', 3), ('cardset_id', 4), ('cardset_id', 6), ('cardset_id', 16), ('cardset_id', 15), ('limit', 8)] + elif this_event['id'] == 5: + embed_title = f'{main_team["lname"]} - {this_event["name"]} Draft' + embed_description = f'{this_event["name"]}' + base_params = [('cardset_id', 17), ('cardset_id', 18), ('cardset_id', 19), ('cardset_id', 16), + ('cardset_id', 8), ('limit', 8)] else: logging.error(f'run_draft - Event ID {this_event["id"]} not recognized') raise KeyError(f'Draft data not found for Gauntlet {this_event["id"]}') @@ -315,6 +346,150 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra 'Reserve': 0, 'Replacement': 0, } + max_counts = { + 'Hall of Fame': 1, + 'MVP': 1, + 'All-Star': 3, + 'Starter': 9, + 'Reserve': 7, + 'Replacement': 5 + } + if this_event['id'] in [1, 2]: + max_counts['MVP'] = 2 + elif this_event['id'] == 5: + g_query = await db_get( + 'games', + params=[('season', draft_team['season']), ('team1_id', draft_team['id']), ('gauntlet_id', 5)] + ) + if g_query['count'] > 4: + game_count = g_query['count'] + if game_count <= 14: + max_counts = { + 'Hall of Fame': 1, + 'MVP': 1, + 'All-Star': 3, + 'Starter': 10, + 'Reserve': 7, + 'Replacement': 4 + } + elif game_count <= 24: + max_counts = { + 'Hall of Fame': 1, + 'MVP': 1, + 'All-Star': 4, + 'Starter': 10, + 'Reserve': 7, + 'Replacement': 3 + } + elif game_count <= 34: + max_counts = { + 'Hall of Fame': 1, + 'MVP': 2, + 'All-Star': 4, + 'Starter': 10, + 'Reserve': 7, + 'Replacement': 2 + } + elif game_count <= 49: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 2, + 'All-Star': 4, + 'Starter': 10, + 'Reserve': 7, + 'Replacement': 1 + } + elif game_count <= 64: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 2, + 'All-Star': 4, + 'Starter': 11, + 'Reserve': 7, + 'Replacement': 0 + } + elif game_count <= 79: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 2, + 'All-Star': 5, + 'Starter': 11, + 'Reserve': 6, + 'Replacement': 0 + } + elif game_count <= 99: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 3, + 'All-Star': 5, + 'Starter': 11, + 'Reserve': 5, + 'Replacement': 0 + } + elif game_count <= 119: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 3, + 'All-Star': 5, + 'Starter': 12, + 'Reserve': 4, + 'Replacement': 0 + } + elif game_count <= 139: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 3, + 'All-Star': 6, + 'Starter': 12, + 'Reserve': 3, + 'Replacement': 0 + } + elif game_count <= 164: + max_counts = { + 'Hall of Fame': 2, + 'MVP': 4, + 'All-Star': 6, + 'Starter': 12, + 'Reserve': 2, + 'Replacement': 0 + } + elif game_count <= 189: + max_counts = { + 'Hall of Fame': 3, + 'MVP': 4, + 'All-Star': 6, + 'Starter': 12, + 'Reserve': 1, + 'Replacement': 0 + } + elif game_count <= 219: + max_counts = { + 'Hall of Fame': 3, + 'MVP': 4, + 'All-Star': 6, + 'Starter': 13, + 'Reserve': 0, + 'Replacement': 0 + } + elif game_count <= 249: + max_counts = { + 'Hall of Fame': 3, + 'MVP': 4, + 'All-Star': 7, + 'Starter': 12, + 'Reserve': 0, + 'Replacement': 0 + } + else: + max_counts = { + 'Hall of Fame': 3, + 'MVP': 5, + 'All-Star': 7, + 'Starter': 11, + 'Reserve': 0, + 'Replacement': 0 + } + logging.info(f'gauntlets.py - run_draft / max_counts: {max_counts}') round_num = 1 counter = 0 @@ -381,16 +556,18 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra for z in helpers.get_all_pos(y): all_str[z] += f'{name_string}\n' - if this_event['id'] in [3, 4]: - top_embed.add_field(name=f'HoFs ({counts["Hall of Fame"]}/1)', value=all_str['Hall of Fame'], inline=False) - top_embed.add_field(name=f'MVPs ({counts["MVP"]}/1)', value=all_str['MVP'], inline=False) - else: - top_embed.add_field(name=f'MVPs ({counts["MVP"]}/2)', value=all_str['MVP'], inline=False) - top_embed.add_field(name=f'All-Stars ({counts["All-Star"]}/3)', value=all_str['All-Star'], inline=False) - top_embed.add_field(name=f'Starters ({counts["Starter"]}/9)', value=all_str['Starter'], inline=False) - top_embed.add_field(name=f'Reserves ({counts["Reserve"]}/7)', value=all_str['Reserve'], inline=False) + top_embed.add_field(name=f'HoFs ({counts["Hall of Fame"]}/{max_counts["Hall of Fame"]})', value=all_str['Hall of Fame'], inline=False) + top_embed.add_field(name=f'MVPs ({counts["MVP"]}/{max_counts["MVP"]})', value=all_str['MVP'], inline=False) top_embed.add_field( - name=f'Replacements ({counts["Replacement"]}/5)', value=all_str['Replacement'], inline=False + name=f'All-Stars ({counts["All-Star"]}/{max_counts["All-Star"]})', value=all_str['All-Star'], inline=False) + top_embed.add_field( + name=f'Starters ({counts["Starter"]}/{max_counts["Starter"]})', value=all_str['Starter'], inline=False) + top_embed.add_field( + name=f'Reserves ({counts["Reserve"]}/{max_counts["Reserve"]})', value=all_str['Reserve'], inline=False) + top_embed.add_field( + name=f'Replacements ({counts["Replacement"]}/{max_counts["Replacement"]})', + value=all_str['Replacement'], + inline=False ) bot_embed.add_field(name=f'Catcher', value=all_str['C'], inline=False) @@ -1025,9 +1202,9 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra # Slot 1 - SP if x == 'SP': if counts['SP'] > 5: - slot_params = [('pos_exc', 'RP')] + slot_params = [('pos_exc', 'SP')] if counts['RP'] > 7: - slot_params = [('pos_exc', 'SP')] + slot_params = [('pos_exc', 'RP')] else: slot_params = [('pos_inc', 'SP')] # if counts['SP'] > 5: @@ -1141,6 +1318,162 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra # Update roster embed round_num += 1 await last_message.edit(content=None, embeds=get_embeds(include_links=False)) + elif this_event['id'] == 5: + while round_num <= 26 and counter < 50: + counter += 1 + params = copy.deepcopy(base_params) + logging.info(f'gauntlets.py - run_draft - event_id 5 / round_num: {round_num} / counter: {counter} ' + f'/ counts: {counts} / max_counts: {max_counts}') + + # Set rarity based on remaining counts + if counts['Hall of Fame'] < max_counts['Hall of Fame']: + params.extend([ + ('min_rarity', RARITY['HoF']), ('max_rarity', RARITY['HoF']) + ]) + elif counts['MVP'] < max_counts['MVP']: + params.extend([ + ('min_rarity', RARITY['MVP']), ('max_rarity', RARITY['MVP']) + ]) + elif counts['All-Star'] < max_counts['All-Star']: + params.extend([ + ('min_rarity', RARITY['All-Star']), ('max_rarity', RARITY['All-Star']) + ]) + elif counts['Starter'] < max_counts['Starter']: + params.extend([ + ('min_rarity', RARITY['Starter']), ('max_rarity', RARITY['Starter']) + ]) + elif counts['Reserve'] < max_counts['Reserve']: + params.extend([ + ('min_rarity', RARITY['Reserve']), ('max_rarity', RARITY['Reserve']) + ]) + else: + params.extend([ + ('min_rarity', RARITY['Replacement']), ('max_rarity', RARITY['Replacement']) + ]) + + this_batch = [] + for x in ['SP', 'RP', 'IF', 'OF']: + # Slot 1 - SP + if x == 'SP': + if counts['SP'] > 5: + slot_params = [('pos_exc', 'SP')] + if counts['RP'] > 7: + slot_params = [('pos_exc', 'RP')] + else: + slot_params = [('pos_inc', 'SP')] + # if counts['SP'] > 5: + # slot_params = [('pos_exc', 'SP')] + # elif counts['RP'] < 6: + # slot_params = [('pos_inc', 'RP')] + # else: + # slot_params = [('pos_exc', 'SP'), ('pos_exc', 'RP')] + + # Slot 2 - RP + elif x == 'RP': + logging.info(f'counts[RP]: {counts["RP"]}') + if counts['RP'] > 7: + slot_params = [('pos_exc', 'RP')] + if counts['SP'] > 5: + slot_params = [('pos_exc', 'SP')] + else: + slot_params = [('pos_inc', 'RP')] + + # Slot 3 - IF + elif x == 'IF': + slot_params = [] + for y in ['1B', '2B', '3B', 'SS', 'C']: + if (counts[y] > 1) and 0 in [ + counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'] + ]: + slot_params.append(('pos_exc', y)) + elif (y == 'C' and counts['C'] < 3) or (y != 'C' and counts[y] < 4): + slot_params.append(('pos_inc', y)) + # if counts['C'] < 2: + # slot_params.append(('pos_inc', 'C')) + # if len(slot_params) == 0: + # slot_params = [('pos_exc', 'C'), ('pos_exc', '1B'), ('pos_exc', '2B'), ('pos_exc', '3B'), + # ('pos_exc', 'SS')] + + # Slot 4 - OF + else: + slot_params = [] + for y in ['LF', 'CF', 'RF']: + if counts[y] > 4: + slot_params.append(('pos_exc', y)) + elif counts[y] > 1 and 0 in [counts['LF'], counts['CF'], counts['RF']]: + slot_params.append(('pos_exc', y)) + elif counts[y] < 5: + slot_params.append(('pos_inc', y)) + # if len(slot_params) == 0: + # slot_params = [('pos_exc', 'LF'), ('pos_exc', 'CF'), ('pos_exc', 'RF')] + + logging.info(f'this_batch: {this_batch}') + logging.info(f'slot_params: {slot_params}') + logging.info(f'params: {params}') + + # No position explicitly requested or denied + if len(slot_params) == 0: + if (counts['SP'] + counts['RP']) > ( + counts['C'] + counts['1B'] + counts['2B'] + counts['SS'] + counts['LF'] + counts['CF'] + + counts['RF']): + pos_counts = [ + ('C', counts['C']), ('1B', counts['1B']), ('2B', counts['2B']), ('3B', counts['3B']), + ('SS', counts['SS']), ('LF', counts['LF']), ('CF', counts['CF']), ('RF', counts['RF']) + ] + pos_counts.sort(key=lambda z: z[1]) + slot_params = [('pos_inc', pos_counts[0][0])] + else: + if counts['SP'] >= counts['RP']: + slot_params = [('pos_inc', 'RP')] + else: + slot_params = [('pos_inc', 'SP')] + + slot_params.extend(params) + p_query = await db_get('players/random', params=slot_params) + + if p_query['count'] > 0: + # test_player_list = '' + # for z in p_query['players']: + # test_player_list += f'{z["rarity"]["name"]} - {z["description"]} - {helpers.get_all_pos(x)}\n' + + # Collect 1 cards with no repeat player names + for i in p_query['players']: + if i['p_name'] not in p_names and i not in this_batch: + this_batch.append(i) + break + + if len(this_batch) < 4: + logging.error(f'Pulled less than 4 players in gauntlet draft') + p_query = await db_get('players/random', params=params) + for i in p_query['players']: + if i['p_name'] not in p_names and i not in this_batch: + this_batch.append(i) + if len(this_batch) >= 4: + break + + if len(this_batch) < 4: + raise KeyError(f'This is embarassing, but I couldn\'t find enough players for you to draft from.') + + # Present choices and capture selection + p_choice = await helpers.get_choice_from_cards(interaction, this_batch, delete_message=True) + + # Add player to list and update counts + p_names.append(p_choice['p_name']) + counts[p_choice['rarity']['name']] += 1 + + all_players.append(p_choice) + + if p_choice['pos_1'] in ['SP', 'RP']: + counts[p_choice['pos_1']] += 1 + else: + for x in helpers.get_all_pos(p_choice): + if x in counts: + counts[x] += 1 + + # Update roster embed + round_num += 1 + await last_message.edit(content=None, embeds=get_embeds(include_links=False)) + else: logging.error(f'run_draft - No draft logic for Event ID {this_event["id"]}') raise KeyError(f'Draft data not found for Gauntlet {this_event["id"]}') @@ -1283,15 +1616,20 @@ async def post_result(run_id: int, is_win: bool, this_team, bot, channel): 'open_time': datetime.datetime.timestamp(datetime.datetime.now()) * 1000} ) await helpers.give_cards_to_team( - main_team, player_ids=x['reward']['player']['player_id'], pack_id=this_pack['id']) + main_team, player_ids=[x['reward']['player']['player_id']], pack_id=this_pack['id']) reward_string += f'- {helpers.player_desc(x["reward"]["player"])}\n' - elif x['reward']['pack_type'] and this_event['id'] in [3, 4]: + elif x['reward']['pack_type'] and this_event['id'] in [3, 4, 5]: if this_event['id'] == 3: cardset_id = 13 team_id = 58 - else: + elif this_event['id'] == 4: cardset_id = 16 team_id = 79 + else: + cardset_id = 17 + team_id = None + if x['reward']['pack_type']['id'] == 9: + cardset_id = 18 await db_post( 'packs', payload={'packs': [{ 'team_id': main_team['id'],