Activate Cardset-Locked Team Choice packs

This commit is contained in:
Cal Corum 2023-10-24 14:08:37 -05:00
parent e0ef5616bd
commit d6276ec22a
2 changed files with 57 additions and 23 deletions

View File

@ -568,8 +568,10 @@ class Economy(commands.Cog):
'Mario': [],
'Team Choice': []
}
logging.debug(f'Parsing packs...')
for pack in p_query['packs']:
p_group = None
logging.debug(f'pack: {pack}')
if pack['pack_team'] is None and pack['pack_cardset'] is None:
if pack['pack_type']['name'] in p_data:
p_group = pack['pack_type']['name']
@ -587,7 +589,10 @@ class Economy(commands.Cog):
p_group = f'Standard-Cardset-{pack["pack_cardset"]["id"]}-{pack["pack_cardset"]["name"]}'
elif pack['pack_type']['name'] == 'Premium':
p_group = f'Premium-Cardset-{pack["pack_cardset"]["id"]}-{pack["pack_cardset"]["name"]}'
elif pack['pack_type']['name'] == 'Team Choice':
p_group = f'Team Choice-Cardset-{pack["pack_cardset"]["id"]}-{pack["pack_cardset"]["name"]}'
logging.debug(f'p_group: {p_group}')
if p_group is not None:
p_count += 1
if p_group not in p_data:

View File

@ -442,9 +442,10 @@ class Pagination(discord.ui.View):
class SelectChoicePackTeam(discord.ui.Select):
def __init__(self, which: Literal['AL', 'NL'], team):
def __init__(self, which: Literal['AL', 'NL'], team, cardset_id: Optional[int] = None):
self.which = which
self.owner_team = team
self.cardset_id = cardset_id
if which == 'AL':
options = [
discord.SelectOption(label='Baltimore Orioles'),
@ -554,6 +555,8 @@ class SelectChoicePackTeam(discord.ui.Select):
('pack_type_id', 8), ('team_id', self.owner_team['id']), ('opened', False), ('limit', 1),
('exact_match', True)
]
if self.cardset_id is not None:
params.append(('pack_cardset_id', self.cardset_id))
p_query = await db_get('packs', params=params)
if p_query['count'] == 0:
logging.error(f'open-packs - no packs found with params: {params}')
@ -561,7 +564,7 @@ class SelectChoicePackTeam(discord.ui.Select):
this_pack = await db_patch('packs', object_id=p_query['packs'][0]['id'], params=[('pack_team_id', team_id)])
await open_choice_pack(this_pack, self.owner_team, interaction)
await open_choice_pack(this_pack, self.owner_team, interaction, self.cardset_id)
class SelectOpenPack(discord.ui.Select):
@ -571,6 +574,7 @@ class SelectOpenPack(discord.ui.Select):
async def callback(self, interaction: discord.Interaction):
logging.info(f'SelectPackChoice - selection: {self.values[0]}')
pack_vals = self.values[0].split('-')
logging.debug(f'pack_vals: {pack_vals}')
# Get the owner's team
owner_team = await get_team_by_owner(interaction.user.id)
@ -602,13 +606,16 @@ class SelectOpenPack(discord.ui.Select):
else:
raise KeyError(f'Cannot identify pack details: {pack_vals}')
if 'Team' in pack_vals:
params.append(('pack_team_id', pack_vals[2]))
# If team isn't already set on team choice pack, make team pack selection now
elif 'Team Choice' in pack_vals:
if 'Team Choice' in pack_vals:
if 'Cardset' in pack_vals:
cardset_id = pack_vals[2]
else:
cardset_id = None
await interaction.response.edit_message(view=None)
view = SelectView(
[SelectChoicePackTeam('AL', owner_team), SelectChoicePackTeam('NL', owner_team)],
[SelectChoicePackTeam('AL', owner_team, cardset_id),
SelectChoicePackTeam('NL', owner_team, cardset_id)],
timeout=30
)
await interaction.channel.send(
@ -616,6 +623,8 @@ class SelectOpenPack(discord.ui.Select):
view=view
)
return
elif 'Team' in pack_vals:
params.append(('pack_team_id', pack_vals[2]))
elif 'Cardset' in pack_vals:
params.append(('pack_cardset_id', pack_vals[2]))
@ -2369,11 +2378,11 @@ def get_rosters(team, bot, roster_num: Optional[int] = None) -> list:
def get_roster_lineups(team, bot, roster_num, lineup_num) -> list:
sheets = get_sheets(bot)
logging.info(f'sheets: {sheets}')
logging.debug(f'sheets: {sheets}')
this_sheet = sheets.open_by_key(team['gsheet'])
logging.info(f'this_sheet: {this_sheet}')
logging.debug(f'this_sheet: {this_sheet}')
r_sheet = this_sheet.worksheet_by_title('My Rosters')
logging.info(f'r_sheet: {r_sheet}')
logging.debug(f'r_sheet: {r_sheet}')
if lineup_num == 1:
row_start = 9
@ -2843,7 +2852,7 @@ async def get_choice_from_cards(
{'player': x, 'team': {'lname': 'Paper Dynasty', 'season': PD_SEASON, 'logo': IMAGES['logo']}}
) for x in all_players
]
logging.info(f'card embeds: {card_embeds}')
logging.debug(f'card embeds: {card_embeds}')
if cover_title is not None and cover_image_url is not None:
page_num = 0
@ -2929,11 +2938,13 @@ async def get_choice_from_cards(
return all_players[page_num - 1]
async def open_choice_pack(this_pack, team: dict, context):
async def open_choice_pack(this_pack, team: dict, context, cardset_id: Optional[int] = None):
pack_channel = get_channel(context, 'pack-openings')
pack_cover = get_pack_cover(this_pack)
pack_type = this_pack['pack_type']['name']
players = []
if pack_type == 'Mario':
d1000 = random.randint(1, 1000)
if d1000 > 800:
@ -2948,6 +2959,7 @@ async def open_choice_pack(this_pack, team: dict, context):
('cardset_id', 8), ('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4)
]
)
players = pl['players']
elif pack_type == 'Team Choice':
if this_pack['pack_team'] is None:
raise KeyError(f'Team not listed for Team Choice pack')
@ -2961,13 +2973,22 @@ async def open_choice_pack(this_pack, team: dict, context):
rarity_id = 3
else:
rarity_id = 2
pl = await db_get(
'players/random',
params=[
('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4), ('in_packs', True),
min_rarity = rarity_id
while len(players) < 4 and rarity_id < 10:
params = [
('min_rarity', min_rarity), ('max_rarity', rarity_id), ('limit', 4 - len(players)), ('in_packs', True),
('mlbclub', this_pack['pack_team']['lname'])
]
)
if cardset_id is not None:
params.append(('cardset_id', cardset_id))
pl = await db_get(
'players/random',
params=params
)
if pl['count'] >= 0:
players.extend(pl['players'])
rarity_id += 3
else:
# Get 4 MVP cards
rarity_id = 5
@ -2976,13 +2997,21 @@ async def open_choice_pack(this_pack, team: dict, context):
elif pack_type == 'All Star':
rarity_id = 3
pl = await db_get('players/random', params=[
('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4), ('in_packs', True)
])
min_rarity = rarity_id
while len(players) < 4 and rarity_id < 10:
params = [
('min_rarity', min_rarity), ('max_rarity', rarity_id), ('limit', 4), ('in_packs', True)
]
if cardset_id is not None:
params.append(('cardset_id', cardset_id))
pl = await db_get('players/random', params=params)
if pl['count']:
players = pl['players']
else:
if pl['count'] > 0:
players.extend(pl['players'])
rarity_id += 3
if len(players) == 0:
logging.error(f'Could not create choice pack')
raise ConnectionError(f'Could not create choice pack')
if type(context) == commands.Context:
@ -2997,7 +3026,7 @@ async def open_choice_pack(this_pack, team: dict, context):
{'player': x, 'team': team} # Show team and dupe info
) for x in players
]
logging.info(f'card embeds: {card_embeds}')
logging.debug(f'card embeds: {card_embeds}')
page_num = 0
view = Pagination([author], timeout=30)