Gauntlet evolution fix
This commit is contained in:
parent
149c4f3ab9
commit
479a335373
@ -13,6 +13,7 @@ from helpers import *
|
||||
import in_game
|
||||
from in_game import ai_manager
|
||||
from in_game.gameplay_models import Play, Session, select, engine, Game, Cardset, Lineup, Team, Player
|
||||
from in_game.gameplay_queries import get_team_or_none
|
||||
|
||||
|
||||
logger = logging.getLogger('discord_app')
|
||||
@ -603,8 +604,9 @@ class Admins(commands.Cog):
|
||||
@commands.command(name='test_evo', help='Mod: Test pokemon evolution')
|
||||
@commands.is_owner()
|
||||
async def test_evolution(self, ctx, team_abbrev: str):
|
||||
this_team = await get_team_by_abbrev(team_abbrev)
|
||||
await evolve_pokemon(this_team, ctx.channel, responders=ctx.author)
|
||||
with Session(engine) as session:
|
||||
this_team = await get_team_or_none(session, team_abbrev=team_abbrev)
|
||||
await evolve_pokemon(this_team, ctx.channel, responders=[ctx.author])
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
|
||||
24
gauntlets.py
24
gauntlets.py
@ -312,7 +312,7 @@ async def run_draft(interaction: discord.Interaction, main_team: Team, this_even
|
||||
base_params = [('cardset_id', 20), ('cardset_id', 21), ('cardset_id', 22), ('cardset_id', 16),
|
||||
('cardset_id', 8), ('limit', 8)]
|
||||
elif this_event['id'] == 7:
|
||||
embed_title = f'{main_team['lname']} - {this_event['name']} Draft'
|
||||
embed_title = f'{main_team.lname} - {this_event['name']} Draft'
|
||||
embed_description = f'{this_event["name"]}'
|
||||
base_params = [('cardset_id', 5), ('cardset_id', 1), ('cardset_id', 3), ('cardset_id', 4), ('cardset_id', 23), ('cardset_id', 22), ('limit', 4)]
|
||||
else:
|
||||
@ -1507,7 +1507,7 @@ async def run_draft(interaction: discord.Interaction, main_team: Team, this_even
|
||||
while round_num <= 26 and counter < 50:
|
||||
counter += 1
|
||||
params = copy.deepcopy(base_params)
|
||||
logging.info(f'gauntlets.py - run_draft - event_id {this_event["id"]} / round_num: {round_num} / counter: {counter} / counts: {counts} / max_counts: {max_counts}')
|
||||
logger.info(f'gauntlets.py - run_draft - event_id {this_event["id"]} / round_num: {round_num} / counter: {counter} / counts: {counts} / max_counts: {max_counts}')
|
||||
|
||||
# Set rarity based on remaining counts
|
||||
if counts['Hall of Fame'] < max_counts['Hall of Fame']:
|
||||
@ -1557,7 +1557,7 @@ async def run_draft(interaction: discord.Interaction, main_team: Team, this_even
|
||||
|
||||
# Slot 2 - RP
|
||||
elif x == 'RP':
|
||||
logging.info(f'counts[RP]: {counts["RP"]}')
|
||||
logger.info(f'counts[RP]: {counts["RP"]}')
|
||||
if counts['RP'] > 7:
|
||||
slot_params = [('pos_exc', 'RP')]
|
||||
if counts['SP'] > 5:
|
||||
@ -1594,9 +1594,9 @@ async def run_draft(interaction: discord.Interaction, main_team: Team, this_even
|
||||
# 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}')
|
||||
logger.info(f'this_batch: {this_batch}')
|
||||
logger.info(f'slot_params: {slot_params}')
|
||||
logger.info(f'params: {params}')
|
||||
|
||||
# No position explicitly requested or denied
|
||||
if len(slot_params) == 0:
|
||||
@ -1628,7 +1628,7 @@ async def run_draft(interaction: discord.Interaction, main_team: Team, this_even
|
||||
break
|
||||
|
||||
if len(this_batch) < 4:
|
||||
logging.error(f'Pulled less than 4 players in gauntlet draft')
|
||||
logger.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:
|
||||
@ -1791,9 +1791,11 @@ async def evolve_pokemon(this_team: Team, channel, responders):
|
||||
'cards',
|
||||
params=[('team_id', this_team.id), ('order_by', 'new'), ('limit', 26)]
|
||||
)
|
||||
evolvable_mons = [x for x in c_query['cards'] if x['player']['cardset']['id'] in [23] and x['player']['fangr_id'] is not None and len(x['player']['fangr_id']) > 3]
|
||||
logger.info(f'received {c_query['count']} cards, searching now')
|
||||
|
||||
evolvable_mons = [x for x in c_query['cards'] if x['player']['cardset']['id'] in [23] and x['player']['fangr_id'] is not None and len(x['player']['fangr_id']) > 3]
|
||||
logger.info(f'evolvable_mons: {evolvable_mons}')
|
||||
|
||||
logging.info(f'evolvable_mons: {evolvable_mons}')
|
||||
if len(evolvable_mons) > 0:
|
||||
evo_target_options = [
|
||||
SelectOption(label=f'{x["player"]["rarity"]["name"]} | {x["player"]["p_name"]}', value=x['id']) for x in evolvable_mons
|
||||
@ -1933,9 +1935,9 @@ async def post_result(run_id: int, is_win: bool, this_team: Team, bot, channel,
|
||||
)
|
||||
|
||||
# Evolve a card!
|
||||
logging.info(f'Post-game evolution check: Gauntlet ID {this_run["id"]} / Wins: {this_run["wins"]} / Losses: {this_run["losses"]}')
|
||||
logger.info(f'Post-game evolution check: Gauntlet ID {this_run["id"]} / Wins: {this_run["wins"]} / Losses: {this_run["losses"]}')
|
||||
if this_event['id'] == 7 and this_run['wins'] < 10 and this_run['losses'] < 2:
|
||||
logging.info(f'trying to evolve now')
|
||||
logger.info(f'trying to evolve now')
|
||||
await evolve_pokemon(this_team, channel, responders)
|
||||
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ from in_game.game_helpers import legal_check
|
||||
from in_game.gameplay_models import Game, Lineup, Play, Team
|
||||
from in_game.gameplay_queries import get_one_lineup, get_position, get_card_or_none
|
||||
from utilities.buttons import ask_confirm
|
||||
from utilities.embeds import image_embed
|
||||
|
||||
|
||||
logger = logging.getLogger('discord_app')
|
||||
@ -421,23 +422,27 @@ class SelectBatterSub(discord.ui.Select):
|
||||
|
||||
class SelectPokemonEvolution(discord.ui.Select):
|
||||
def __init__(self, *, placeholder = 'Evolve the selected Pokemon', min_values = 1, max_values = 1, options = List[SelectOption], this_team: Team, responders: list[discord.User] = None):
|
||||
logging.info(f'Inside SelectPokemonEvolution init function')
|
||||
logger.info(f'Inside SelectPokemonEvolution init function')
|
||||
|
||||
self.team = this_team
|
||||
self.responders = responders
|
||||
super().__init__(placeholder=placeholder, min_values=min_values, max_values=max_values, options=options)
|
||||
logger.info(f'init complete')
|
||||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
logger.info(f'entering pokemon evolution callback')
|
||||
if self.responders is not None and interaction.user not in self.responders:
|
||||
await interaction.response.send_message(
|
||||
content=random_insult(),
|
||||
ephemeral=True,
|
||||
delete_after=5
|
||||
)
|
||||
logger.info(f'deferring interaction')
|
||||
await interaction.response.defer()
|
||||
|
||||
try:
|
||||
card_id = self.values[0]
|
||||
logger.info(f'evolving card_id: {card_id}')
|
||||
this_card = await db_get(
|
||||
'cards',
|
||||
object_id=card_id,
|
||||
@ -448,17 +453,20 @@ class SelectPokemonEvolution(discord.ui.Select):
|
||||
object_id=this_card['player']['fangr_id'],
|
||||
none_okay=False
|
||||
)
|
||||
logger.info(f'evo mon: {card_id}')
|
||||
p_query = await db_post(
|
||||
'packs/one',
|
||||
payload={
|
||||
'team_id': self.team['id'],
|
||||
'team_id': self.team.id,
|
||||
'pack_type_id': 4,
|
||||
'open_time': datetime.datetime.timestamp(datetime.datetime.now()) * 1000}
|
||||
)
|
||||
pack_id = p_query['id']
|
||||
logger.info(f'pack_id: {pack_id}')
|
||||
logger.info(f'Posting evolved card')
|
||||
await db_post(
|
||||
'cards',
|
||||
payload={'cards': [ {'player_id': evo_mon['player_id'], 'team_id': self.team['id'], 'pack_id': pack_id}]},
|
||||
payload={'cards': [ {'player_id': evo_mon['player_id'], 'team_id': self.team.id, 'pack_id': pack_id}]},
|
||||
timeout=10
|
||||
)
|
||||
await interaction.edit_original_response(
|
||||
@ -467,11 +475,22 @@ class SelectPokemonEvolution(discord.ui.Select):
|
||||
view=None
|
||||
)
|
||||
await db_delete('cards', object_id=card_id)
|
||||
|
||||
embed = image_embed(
|
||||
image_url=evo_mon['image'],
|
||||
title=evo_mon['p_name'],
|
||||
desc=f'{evo_mon['cardset']['name']} / {evo_mon['mlbclub']}',
|
||||
color=evo_mon['rarity']['color'],
|
||||
thumbnail_url=evo_mon['headshot'],
|
||||
author_name=self.team.lname,
|
||||
author_icon=self.team.logo
|
||||
)
|
||||
|
||||
await asyncio.sleep(3)
|
||||
await interaction.channel.send(
|
||||
content=f'## {this_card["player"]["p_name"].upper()} evolved into {evo_mon["p_name"].upper()}!',
|
||||
embeds=await get_card_embeds({'team': self.team, 'player': evo_mon})
|
||||
embeds=[embed]
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error(f'Failed to evolve a pokemon: {e}', exc_info=True, stack_info=True)
|
||||
logger.error(f'Failed to evolve a pokemon: {e}', exc_info=True, stack_info=True)
|
||||
await interaction.edit_original_response(content=f'Oh no, the evolution failed! Go ping the shit out of Cal so he can evolve it for you!')
|
||||
|
||||
@ -2,7 +2,7 @@ import discord
|
||||
from helpers import IMAGES, PD_SEASON, SBA_COLOR
|
||||
|
||||
|
||||
def image_embed(image_url: str, title: str = None, color: str = None, desc: str = None, author_name: str = None, author_icon: str = None):
|
||||
def image_embed(image_url: str, title: str = None, color: str = None, desc: str = None, author_name: str = None, author_icon: str = None, thumbnail_url: str = None):
|
||||
embed_color = int(SBA_COLOR, 16)
|
||||
if color is not None:
|
||||
embed_color = int(color, 16)
|
||||
@ -16,6 +16,8 @@ def image_embed(image_url: str, title: str = None, color: str = None, desc: str
|
||||
if author_name is not None:
|
||||
icon = author_icon if author_icon is not None else IMAGES['logo']
|
||||
embed.set_author(name=author_name, icon_url=icon)
|
||||
if thumbnail_url is not None:
|
||||
embed.set_thumbnail(url=thumbnail_url)
|
||||
embed.set_footer(text=f'Paper Dynasty Season {PD_SEASON}', icon_url=IMAGES['logo'])
|
||||
embed.set_image(url=image_url)
|
||||
return embed
|
||||
Loading…
Reference in New Issue
Block a user