Add Team Choice packs
This commit is contained in:
parent
7a0a48c85c
commit
b56fa21bfe
@ -564,7 +564,8 @@ class Economy(commands.Cog):
|
||||
'Daily': [],
|
||||
'MVP': [],
|
||||
'All Star': [],
|
||||
'Mario': []
|
||||
'Mario': [],
|
||||
'Team Choice': []
|
||||
}
|
||||
for pack in p_query['packs']:
|
||||
p_group = None
|
||||
|
||||
175
helpers.py
175
helpers.py
@ -446,6 +446,129 @@ class Pagination(discord.ui.View):
|
||||
self.stop()
|
||||
|
||||
|
||||
class SelectChoicePackTeam(discord.ui.Select):
|
||||
def __init__(self, which: Literal['AL', 'NL'], team):
|
||||
self.which = which
|
||||
self.owner_team = team
|
||||
if which == 'AL':
|
||||
options = [
|
||||
discord.SelectOption(label='Baltimore Orioles'),
|
||||
discord.SelectOption(label='Boston Red Sox'),
|
||||
discord.SelectOption(label='Chicago White Sox'),
|
||||
discord.SelectOption(label='Cleveland Guardians'),
|
||||
discord.SelectOption(label='Detroit Tigers'),
|
||||
discord.SelectOption(label='Houston Astros'),
|
||||
discord.SelectOption(label='Kansas City Royals'),
|
||||
discord.SelectOption(label='Los Angeles Angels'),
|
||||
discord.SelectOption(label='Minnesota Twins'),
|
||||
discord.SelectOption(label='New York Yankees'),
|
||||
discord.SelectOption(label='Oakland Athletics'),
|
||||
discord.SelectOption(label='Seattle Mariners'),
|
||||
discord.SelectOption(label='Tampa Bay Rays'),
|
||||
discord.SelectOption(label='Texas Rangers'),
|
||||
discord.SelectOption(label='Toronto Blue Jays')
|
||||
]
|
||||
else:
|
||||
options = [
|
||||
discord.SelectOption(label='Arizona Diamondbacks'),
|
||||
discord.SelectOption(label='Atlanta Braves'),
|
||||
discord.SelectOption(label='Chicago Cubs'),
|
||||
discord.SelectOption(label='Cincinnati Reds'),
|
||||
discord.SelectOption(label='Colorado Rockies'),
|
||||
discord.SelectOption(label='Los Angeles Dodgers'),
|
||||
discord.SelectOption(label='Miami Marlins'),
|
||||
discord.SelectOption(label='Milwaukee Brewers'),
|
||||
discord.SelectOption(label='New York Mets'),
|
||||
discord.SelectOption(label='Philadelphia Phillies'),
|
||||
discord.SelectOption(label='Pittsburgh Pirates'),
|
||||
discord.SelectOption(label='San Diego Padres'),
|
||||
discord.SelectOption(label='San Francisco Giants'),
|
||||
discord.SelectOption(label='St. Louis Cardinals'),
|
||||
discord.SelectOption(label='Washington Nationals')
|
||||
]
|
||||
super().__init__(placeholder=f'Select an {which} team', options=options)
|
||||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
team_id = None
|
||||
if self.which == 'AL':
|
||||
if self.values[0] == 'Baltimore Orioles':
|
||||
team_id = 3
|
||||
elif self.values[0] == 'Boston Red Sox':
|
||||
team_id = 4
|
||||
elif self.values[0] == 'Chicago White Sox':
|
||||
team_id = 6
|
||||
elif self.values[0] == 'Cleveland Guardians':
|
||||
team_id = 8
|
||||
elif self.values[0] == 'Detroit Tigers':
|
||||
team_id = 10
|
||||
elif self.values[0] == 'Houston Astros':
|
||||
team_id = 11
|
||||
elif self.values[0] == 'Kansas City Royals':
|
||||
team_id = 12
|
||||
elif self.values[0] == 'Los Angeles Angels':
|
||||
team_id = 13
|
||||
elif self.values[0] == 'Minnesota Twins':
|
||||
team_id = 17
|
||||
elif self.values[0] == 'New York Yankees':
|
||||
team_id = 19
|
||||
elif self.values[0] == 'Oakland Athletics':
|
||||
team_id = 20
|
||||
elif self.values[0] == 'Seattle Mariners':
|
||||
team_id = 24
|
||||
elif self.values[0] == 'Tampa Bay Rays':
|
||||
team_id = 27
|
||||
elif self.values[0] == 'Texas Rangers':
|
||||
team_id = 28
|
||||
elif self.values[0] == 'Toronto Blue Jays':
|
||||
team_id = 29
|
||||
else:
|
||||
if self.values[0] == 'Arizona Diamondbacks':
|
||||
team_id = 1
|
||||
elif self.values[0] == 'Atlanta Braves':
|
||||
team_id = 2
|
||||
elif self.values[0] == 'Chicago Cubs':
|
||||
team_id = 5
|
||||
elif self.values[0] == 'Cincinnati Reds':
|
||||
team_id = 7
|
||||
elif self.values[0] == 'Colorado Rockies':
|
||||
team_id = 9
|
||||
elif self.values[0] == 'Los Angeles Dodgers':
|
||||
team_id = 14
|
||||
elif self.values[0] == 'Miami Marlins':
|
||||
team_id = 15
|
||||
elif self.values[0] == 'Milwaukee Brewers':
|
||||
team_id = 16
|
||||
elif self.values[0] == 'New York Mets':
|
||||
team_id = 18
|
||||
elif self.values[0] == 'Philadelphia Phillies':
|
||||
team_id = 21
|
||||
elif self.values[0] == 'Pittsburgh Pirates':
|
||||
team_id = 22
|
||||
elif self.values[0] == 'San Diego Padres':
|
||||
team_id = 23
|
||||
elif self.values[0] == 'San Francisco Giants':
|
||||
team_id = 25
|
||||
elif self.values[0] == 'St. Louis Cardinals':
|
||||
team_id = 26
|
||||
elif self.values[0] == 'Washington Nationals':
|
||||
team_id = 30
|
||||
|
||||
await interaction.response.edit_message(content=f'You selected the **{self.values[0]}**', view=None)
|
||||
# Get the selected packs
|
||||
params = [
|
||||
('pack_type_id', 8), ('team_id', self.owner_team['id']), ('opened', False), ('limit', 1),
|
||||
('exact_match', True)
|
||||
]
|
||||
p_query = db_get('packs', params=params)
|
||||
if p_query['count'] == 0:
|
||||
logging.error(f'open-packs - no packs found with params: {params}')
|
||||
raise ValueError(f'Unable to open packs')
|
||||
|
||||
this_pack = 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)
|
||||
|
||||
|
||||
class SelectOpenPack(discord.ui.Select):
|
||||
def __init__(self, options: list):
|
||||
super().__init__(placeholder='Select a Pack Type', options=options)
|
||||
@ -458,7 +581,7 @@ class SelectOpenPack(discord.ui.Select):
|
||||
owner_team = get_team_by_owner(interaction.user.id)
|
||||
|
||||
# Get the selected packs
|
||||
params = [('team_id', owner_team['id']), ('opened', False), ('limit', 5)]
|
||||
params = [('team_id', owner_team['id']), ('opened', False), ('limit', 5), ('exact_match', True)]
|
||||
|
||||
open_type = 'standard'
|
||||
if 'Standard' in pack_vals:
|
||||
@ -478,11 +601,26 @@ class SelectOpenPack(discord.ui.Select):
|
||||
elif 'Mario' in pack_vals:
|
||||
open_type = 'choice'
|
||||
params.append(('pack_type_id', 7))
|
||||
elif 'Team Choice' in pack_vals:
|
||||
open_type = 'choice'
|
||||
params.append(('pack_type_id', 8))
|
||||
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:
|
||||
await interaction.response.edit_message(view=None)
|
||||
view = SelectView(
|
||||
[SelectChoicePackTeam('AL', owner_team), SelectChoicePackTeam('NL', owner_team)],
|
||||
timeout=30
|
||||
)
|
||||
await interaction.channel.send(
|
||||
content=None,
|
||||
view=view
|
||||
)
|
||||
return
|
||||
elif 'Cardset' in pack_vals:
|
||||
params.append(('pack_cardset_id', pack_vals[2]))
|
||||
|
||||
@ -1393,7 +1531,7 @@ async def get_card_embeds(card) -> list:
|
||||
|
||||
# all_dex = card['player']['paperdex']
|
||||
all_dex = db_get('paperdex', params=[("player_id", card["player"]["player_id"]), ('flat', True)])
|
||||
count = 0 if not all_dex else all_dex['count']
|
||||
count = all_dex['count']
|
||||
if card['team']['lname'] != 'Paper Dynasty':
|
||||
bool_list = [True for elem in all_dex['paperdex'] if elem['team'] == card['team']['id']]
|
||||
if any(bool_list):
|
||||
@ -1401,17 +1539,19 @@ async def get_card_embeds(card) -> list:
|
||||
coll_string = f'Only you'
|
||||
else:
|
||||
coll_string = f'You and {count - 1} other{"s" if count - 1 != 1 else ""}'
|
||||
else:
|
||||
elif count:
|
||||
coll_string = f'{count} other team{"s" if count != 1 else ""}'
|
||||
else:
|
||||
coll_string = f'0 teams'
|
||||
embed.add_field(name='Collected By', value=coll_string)
|
||||
else:
|
||||
embed.add_field(name='Collected By', value=f'{count} team{"s" if count != 1 else ""}')
|
||||
|
||||
# TODO: check for dupes with the included paperdex data
|
||||
if card['team']['lname'] != 'Paper Dynasty':
|
||||
team_dex = db_get('cards', params=[("player_id", card["player"]["player_id"]), ('team_id', card['team']['id'])])
|
||||
count = 1 if not team_dex['count'] else team_dex['count']
|
||||
embed.add_field(name='# Dupes', value=f'{count - 1} dupe{"s" if count - 1 != 1 else ""}')
|
||||
# if card['team']['lname'] != 'Paper Dynasty':
|
||||
# team_dex = db_get('cards', params=[("player_id", card["player"]["player_id"]), ('team_id', card['team']['id'])])
|
||||
# count = 1 if not team_dex['count'] else team_dex['count']
|
||||
# embed.add_field(name='# Dupes', value=f'{count - 1} dupe{"s" if count - 1 != 1 else ""}')
|
||||
|
||||
# embed.add_field(name='Team', value=f'{card["player"]["mlbclub"]}')
|
||||
pos_string = ", ".join(get_all_pos(card['player']))
|
||||
@ -2677,6 +2817,24 @@ async def open_choice_pack(this_pack, team: dict, context):
|
||||
('cardset_id', 8), ('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4)
|
||||
]
|
||||
)
|
||||
elif pack_type == 'Team Choice':
|
||||
if this_pack['pack_team'] is None:
|
||||
raise KeyError(f'Team not listed for Team Choice pack')
|
||||
|
||||
d1000 = random.randint(1, 1000)
|
||||
if d1000 > 800:
|
||||
rarity_id = 5
|
||||
elif d1000 > 550:
|
||||
rarity_id = 3
|
||||
else:
|
||||
rarity_id = 2
|
||||
pl = db_get(
|
||||
'players/random',
|
||||
params=[
|
||||
('min_rarity', rarity_id), ('max_rarity', rarity_id), ('limit', 4), ('in_packs', True),
|
||||
('mlbclub', this_pack['pack_team']['lname'])
|
||||
]
|
||||
)
|
||||
else:
|
||||
# Get 4 MVP cards
|
||||
rarity_id = 5
|
||||
@ -2702,7 +2860,8 @@ async def open_choice_pack(this_pack, team: dict, context):
|
||||
# Display them with pagination, prev/next/select
|
||||
card_embeds = [
|
||||
await get_card_embeds(
|
||||
{'player': x, 'team': {'lname': 'Paper Dynasty', 'season': PD_SEASON, 'logo': IMAGES['logo']}}
|
||||
# {'player': x, 'team': {'lname': 'Paper Dynasty', 'season': PD_SEASON, 'logo': IMAGES['logo']}}
|
||||
{'player': x, 'team': team} # Show team and dupe info
|
||||
) for x in players
|
||||
]
|
||||
logging.info(f'card embeds: {card_embeds}')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user