2008, 2016, Flashback Gauntlet Live!

This commit is contained in:
Cal Corum 2023-05-29 19:48:48 -05:00
parent d1f82eb58e
commit 87a44d03f0
4 changed files with 274 additions and 30 deletions

View File

@ -18,16 +18,25 @@ db = SqliteDatabase(
}
)
# 2022, 2023
# 2022, 2023, Mario
MINOR_CARDSET_PARAMS = [('cardset_id', 8), ('cardset_id', 9), ('cardset_id', 3)]
# 2013, 2019, 2022, 2023
# 2013, 2019, 2022, 2023, Mario
MAJOR_CARDSET_PARAMS = [
('cardset_id', 8), ('cardset_id', 6), ('cardset_id', 5),
('cardset_id', 3), ('cardset_id', 4),
('cardset_id', 9), ('cardset_id', 10)
]
# 2008, 2012, 2013, 2016, 2019, 2021, 2022, 2023, Mario
HOF_CARDSET_PARAMS = [
('cardset_id', 1), ('cardset_id', 3), ('cardset_id', 4), ('cardset_id', 5), ('cardset_id', 6), ('cardset_id', 7),
('cardset_id', 8), ('cardset_id', 9), ('cardset_id', 10), ('cardset_id', 11), ('cardset_id', 12)
]
# 2008, 2012, 2013, 2016
GAUNTLET2_PARAMS = [('cardset_id', 8), ('cardset_id', 12), ('cardset_id', 6), ('cardset_id', 7), ('cardset_id', 11)]
class BaseModel(Model):
class Meta:
@ -225,6 +234,7 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, vs_han
'DH': None
}
p_names = []
rest_name = None
set_params = [('cardset_id_exclude', 2)]
if team_object['id'] == 58:
@ -233,8 +243,12 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, vs_han
set_params = MINOR_CARDSET_PARAMS
elif league_name == 'major-league':
set_params = MAJOR_CARDSET_PARAMS
elif league_name == 'gauntlet-1':
elif league_name == 'hall-of-fame':
set_params = HOF_CARDSET_PARAMS
elif 'gauntlet-1' in league_name:
set_params = MINOR_CARDSET_PARAMS
elif 'gauntlet-2' in league_name:
set_params = GAUNTLET2_PARAMS
# Pull players sorted by current cost
try:
@ -263,20 +277,24 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, vs_han
# If not possible, pass player and continue
for guy in all_players:
placed = False
if guy['p_name'] not in p_names:
if guy['p_name'] not in p_names and guy['p_name'] != rest_name:
for pos in [
guy['pos_1'], guy['pos_2'], guy['pos_3'], guy['pos_4'], guy['pos_5'], guy['pos_6'], guy['pos_7'],
guy['pos_8']
]:
if pos is None or pos in ['SP', 'RP', 'CP']:
break
if random.randint(1, 10) == 10 and rest_name is None:
logging.info(f'Resting {guy["p_name"]} in game {game_id}')
rest_name = guy['p_name']
elif players[pos] is None:
players[pos] = guy
p_names.append(guy["p_name"])
placed = True
break
if not placed:
if not placed and rest_name != guy['p_name']:
if players['DH'] is None:
players['DH'] = guy
p_names.append(guy["p_name"])
@ -333,8 +351,12 @@ async def get_starting_pitcher(team_object: dict, game_id: int, is_home: bool, l
set_params = MINOR_CARDSET_PARAMS
elif league_name == 'major-league':
set_params = MAJOR_CARDSET_PARAMS
elif league_name == 'hall-of-fame':
set_params = HOF_CARDSET_PARAMS
elif league_name == 'gauntlet-1':
set_params = MINOR_CARDSET_PARAMS
elif 'gauntlet-2' in league_name:
set_params = GAUNTLET2_PARAMS
params = [
('mlbclub', team_object['lname']), ('pos_include', 'SP'), ('pos_exclude', 'RP'),
@ -438,9 +460,12 @@ async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, league_name: s
set_params = MINOR_CARDSET_PARAMS
elif league_name == 'major-league':
set_params = MAJOR_CARDSET_PARAMS
elif league_name == 'hall-of-fame':
set_params = HOF_CARDSET_PARAMS
elif 'gauntlet-1' in league_name:
set_params = MINOR_CARDSET_PARAMS
set_params.append(('cardset_id', 8))
elif 'gauntlet-2' in league_name:
set_params = GAUNTLET2_PARAMS
# Pull relievers sorted by current cost
params = [

View File

@ -1079,11 +1079,18 @@ class Gameplay(commands.Cog):
return
league_name = 'major-league'
else:
await interaction.edit_original_response(
content='Hall of Fame games are coming next season! For now, you can play an Unlimited Minor League '
'game or against other humans!'
)
return
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({
@ -1353,7 +1360,8 @@ 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['Paper Sluggers']):
async def new_game_gauntlet_command(
self, interaction: discord.Interaction, event_name: Literal['Paper Sluggers', 'Flashback Gauntlet']):
await interaction.response.defer()
conflict = get_one_game(channel_id=interaction.channel.id, active=True)

View File

@ -763,12 +763,13 @@ 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['Paper Sluggers'], team_abbrev: str = None):
self, interaction: discord.Interaction, event_name: Literal['Paper Sluggers', 'Flashback Gauntlet'],
team_abbrev: str = None):
await interaction.response.defer()
e_query = await db_get('events', params=[("name", event_name), ("active", True)])
if e_query['count'] == 0:
await interaction.response.send_message(f'Hmm...looks like that event has ended already.')
await interaction.edit_original_response(content=f'Hmm...looks like that event is inactive.')
return
else:
this_event = e_query['events'][0]
@ -780,7 +781,9 @@ class Players(commands.Cog):
t_query = await db_get('teams', params=[('abbrev', team_abbrev)])
if t_query['count'] != 0:
this_team = t_query['teams'][0]
r_query = await db_get('gauntletruns', params=[('team_id', this_team['id']), ('is_active', True)])
r_query = await db_get('gauntletruns', params=[
('team_id', this_team['id']), ('is_active', True), ('gauntlet_id', this_event['id'])
])
if r_query['count'] != 0:
this_run = r_query['runs'][0]
@ -800,7 +803,8 @@ 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['Paper Sluggers']):
async def gauntlet_start_command(
self, interaction: discord.Interaction, event_name: Literal['Paper Sluggers', 'Flashback Gauntlet']):
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 '
@ -815,7 +819,7 @@ class Players(commands.Cog):
e_query = await db_get('events', params=[("name", event_name), ("active", True)])
if e_query['count'] == 0:
await interaction.response.send_message(f'Hmm...looks like that event has ended already.')
await interaction.edit_original_response(content='Hmm...looks like that event is inactive.')
return
else:
this_event = e_query['events'][0]
@ -829,8 +833,8 @@ class Players(commands.Cog):
if r_query['count'] != 0:
await interaction.edit_original_response(
content=f'Looks like you already have a {event_name} run active! You can check it out with the '
f'`/gauntlets status` command.'
content=f'Looks like you already have a {r_query["runs"][0]["gauntlet"]["name"]} run active! '
f'You can check it out with the `/gauntlets status` command.'
)
return

View File

@ -56,33 +56,59 @@ def is_home_team(this_team, this_event, this_run):
async def get_opponent(this_team, this_event, this_run):
gp = games_played(this_run)
if this_event['id'] == 1:
gp = games_played(this_run)
if gp == 0:
t_id = 20
t_id = 30
elif gp == 1:
t_id = 9
t_id = 12
elif gp == 2:
t_id = 5
t_id = 15
elif gp == 3:
t_id = 17
t_id = 13
elif gp == 4:
t_id = 3
t_id = 6
elif gp == 5:
t_id = 21
t_id = 4
elif gp == 6:
t_id = 24
elif gp == 7:
t_id = 23
elif gp == 7:
t_id = 16
elif gp == 8:
t_id = 18
t_id = 2
elif gp == 9:
t_id = 11
t_id = 14
elif gp == 10:
t_id = 58
else:
raise KeyError(f'Huh...I have no idea who you should be playing right now.')
return await db_get('teams', object_id=t_id, none_okay=False)
elif this_event['id'] == 2:
if gp == 0:
t_id = 11
elif gp == 1:
t_id = 17
elif gp == 2:
t_id = 12
elif gp == 3:
t_id = 21
elif gp == 4:
t_id = 22
elif gp == 5:
t_id = 7
elif gp == 6:
t_id = 8
elif gp == 7:
t_id = 30
elif gp == 8:
t_id = 10
elif gp == 9:
t_id = 26
elif gp == 10:
t_id = 28
else:
raise KeyError(f'Huh...I have no idea who you should be playing right now.')
return await db_get('teams', object_id=t_id, none_okay=False)
else:
return None
@ -159,6 +185,11 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
embed_description = f'{this_event["name"]}'
base_params = ai_manager.MAJOR_CARDSET_PARAMS
base_params.extend([('limit', 8), ('cardset_id', 8)])
elif this_event['id'] == 2:
embed_title = f'{main_team["lname"]} - {this_event["name"]} Draft'
embed_description = f'{this_event["name"]}'
base_params = ai_manager.GAUNTLET2_PARAMS
base_params.extend([('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"]}')
@ -457,6 +488,182 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
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))
elif this_event['id'] == 2:
while round_num <= 26 and counter < 50:
counter += 1
params = copy.deepcopy(base_params)
# Set rarity param based on round number
if round_num == 1:
params.extend([
('min_rarity', RARITY['MVP']), ('max_rarity', RARITY['MVP'])
])
elif round_num == 2:
params.extend([
('min_rarity', RARITY['All-Star']), ('max_rarity', RARITY['All-Star'])
])
elif round_num <= 5:
params.extend([
('min_rarity', RARITY['Starter']), ('max_rarity', RARITY['Starter'])
])
elif round_num == 6:
params.extend([
('min_rarity', RARITY['MVP']), ('max_rarity', RARITY['MVP']), ('pos_exc', 'RP')
])
elif round_num == 7:
params.extend([
('min_rarity', RARITY['All-Star']), ('max_rarity', RARITY['All-Star'])
])
elif round_num <= 11:
params.extend([
('min_rarity', RARITY['Starter']), ('max_rarity', RARITY['Starter'])
])
elif round_num <= 15:
params.extend([
('min_rarity', RARITY['Reserve']), ('max_rarity', RARITY['Reserve'])
])
elif round_num <= 18:
params.extend([
('min_rarity', RARITY['Replacement']), ('max_rarity', RARITY['Replacement'])
])
elif round_num == 19:
params.extend([
('min_rarity', RARITY['All-Star']), ('max_rarity', RARITY['All-Star'])
])
elif round_num <= 21:
params.extend([
('min_rarity', RARITY['Starter']), ('max_rarity', RARITY['Starter'])
])
elif round_num <= 24:
params.extend([
('min_rarity', RARITY['Reserve']), ('max_rarity', RARITY['Reserve'])
])
elif round_num <= 26:
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', 'RP')]
if counts['RP'] > 7:
slot_params = [('pos_exc', 'SP')]
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: