Win/Loss tracking complete
This commit is contained in:
parent
ae18790279
commit
0915fbfd32
@ -322,6 +322,8 @@ def get_starting_pitcher(team_object: dict, game_id: int, is_home: bool, league_
|
||||
set_params = MINOR_CARDSET_PARAMS
|
||||
elif league_name == 'major-league':
|
||||
set_params = MAJOR_CARDSET_PARAMS
|
||||
elif league_name == 'gauntlet-1':
|
||||
set_params = MINOR_CARDSET_PARAMS
|
||||
|
||||
# Pull starters sorted by current cost
|
||||
try:
|
||||
@ -397,11 +399,14 @@ def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers: list,
|
||||
if attempts > 3:
|
||||
raise ValueError(f'Could not find a reliever for the {ai_team["sname"]}. Cal plz.')
|
||||
|
||||
logging.info(f'TEST GAME - league_name: {league_name}')
|
||||
set_params = [('cardset_id_exclude', 2)]
|
||||
if league_name == 'minor-league':
|
||||
set_params = MINOR_CARDSET_PARAMS
|
||||
elif league_name == 'major-league':
|
||||
set_params = MAJOR_CARDSET_PARAMS
|
||||
elif 'gauntlet-1' in league_name:
|
||||
set_params = MINOR_CARDSET_PARAMS
|
||||
|
||||
# Pull relievers sorted by current cost
|
||||
params = [
|
||||
|
||||
@ -297,7 +297,8 @@ class Gameplay(commands.Cog):
|
||||
embed.description = '***Mercy rule in effect***'
|
||||
|
||||
pitcher_string = f'{player_link(game, game_state["pitcher"])}'
|
||||
batter_string = f'{player_link(game, game_state["batter"])}'
|
||||
batter_string = f'{game_state["curr_play"].batter.batting_order}. {player_link(game, game_state["batter"])} - ' \
|
||||
f'{game_state["curr_play"].batter.position}'
|
||||
|
||||
all_bat_stats = get_batting_stats(game.id, lineup_id=game_state['curr_play'].batter.id)
|
||||
if len(all_bat_stats):
|
||||
@ -1395,7 +1396,7 @@ class Gameplay(commands.Cog):
|
||||
# Get or create Gauntlet run
|
||||
r_query = db_get(
|
||||
'gauntletruns',
|
||||
params=[('team_id', main_team['id']), ('gauntlet_id', this_event['id']), ('is_active', True)]
|
||||
params=[('team_id', team['id']), ('gauntlet_id', this_event['id']), ('is_active', True)]
|
||||
)
|
||||
|
||||
if r_query['count'] == 0:
|
||||
@ -1534,7 +1535,15 @@ class Gameplay(commands.Cog):
|
||||
response = await ctx.send(f'Let\'s see what we\'ve got here...')
|
||||
|
||||
owner_team = await get_game_team(this_game, ctx.author.id)
|
||||
if not owner_team['id'] in [this_game.away_team_id, this_game.home_team_id] and \
|
||||
gauntlet_team = None
|
||||
if 'gauntlet' in this_game.game_type:
|
||||
gauntlet_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{owner_team["abbrev"]}')
|
||||
|
||||
if not {owner_team['id'], gauntlet_team['id']}.intersection(
|
||||
[this_game.away_team_id, this_game.home_team_id]):
|
||||
await ctx.send('Bruh. Only GMs of the active teams can end games.')
|
||||
return
|
||||
elif not owner_team['id'] in [this_game.away_team_id, this_game.home_team_id] and \
|
||||
ctx.author.id != self.bot.owner_id:
|
||||
await ctx.send('Bruh. Only GMs of the active teams can end games.')
|
||||
return
|
||||
@ -1648,6 +1657,13 @@ class Gameplay(commands.Cog):
|
||||
winning_team = away_team if away_stats['score'] > home_stats['score'] else home_team
|
||||
losing_team = away_team if away_stats['score'] < home_stats['score'] else home_team
|
||||
|
||||
# Check for Gauntlet game so rewards go to main team
|
||||
if gauntlet_team is not None:
|
||||
if winning_team['gmid'] == gauntlet_team['gmid']:
|
||||
winning_team = owner_team
|
||||
else:
|
||||
losing_team = owner_team
|
||||
|
||||
logging.debug(f'away_stats (in /endgame function)\n\n{away_stats}')
|
||||
logging.debug(f'home_stats (in /endgame function)\n\n{home_stats}')
|
||||
logging.debug(f'winning_team: {winning_team}\nlosing_team: {losing_team}')
|
||||
@ -1832,6 +1848,8 @@ class Gameplay(commands.Cog):
|
||||
game_des = 'Minor League'
|
||||
elif this_game.ranked:
|
||||
game_des = 'Ranked'
|
||||
elif 'gauntlet' in this_game.game_type:
|
||||
game_des = 'Gauntlet'
|
||||
else:
|
||||
game_des = 'Unlimited'
|
||||
embed.description = f'Score Report - {game_des} ' \
|
||||
@ -1887,6 +1905,16 @@ class Gameplay(commands.Cog):
|
||||
give_packs(winning_team, num_packs=1, pack_type=win_reward['pack_type'])
|
||||
db_post(f'teams/{winning_team["id"]}/money/{win_reward["money"]}')
|
||||
db_post(f'teams/{losing_team["id"]}/money/{loss_reward["money"]}')
|
||||
|
||||
if gauntlet_team is not None:
|
||||
await gauntlets.post_result(
|
||||
int(this_game.game_type.split('-')[3]),
|
||||
is_win=winning_team['gmid'] == gauntlet_team['gmid'],
|
||||
this_team=gauntlet_team,
|
||||
bot=self.bot,
|
||||
ctx=ctx
|
||||
)
|
||||
|
||||
else:
|
||||
logging.debug(f'Time to build statlines and share the scorecard for this SBa game!')
|
||||
# Send stats to sheets
|
||||
@ -1896,7 +1924,8 @@ class Gameplay(commands.Cog):
|
||||
patch_game(this_game.id, active=False)
|
||||
|
||||
logging.info(f'Game {this_game.id} is complete')
|
||||
await ctx.send(f'Good game! Go share the highlights in {get_channel(ctx, "pd-news-ticker").mention}!')
|
||||
if gauntlet_team is None:
|
||||
await ctx.send(f'Good game! Go share the highlights in {get_channel(ctx, "pd-news-ticker").mention}!')
|
||||
|
||||
@app_commands.command(
|
||||
name='setlineup',
|
||||
@ -2250,12 +2279,14 @@ class Gameplay(commands.Cog):
|
||||
return
|
||||
|
||||
owner_team = await get_game_team(this_game, ctx.author.id)
|
||||
lineup_team = await get_game_team(this_game, team_abbrev=team_abbrev)
|
||||
if 'gauntlet' in this_game.game_type:
|
||||
lineup_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{owner_team["abbrev"]}')
|
||||
else:
|
||||
lineup_team = await get_game_team(this_game, team_abbrev=team_abbrev)
|
||||
|
||||
if not owner_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
||||
if owner_team['gmid'] != lineup_team['gmid']:
|
||||
await ctx.send('Bruh. Only GMs of the active teams can set lineups.')
|
||||
return
|
||||
|
||||
if not lineup_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
|
||||
await ctx.send(f'I do not see {lineup_team["sname"]} in this game. Please check the team abbrev and '
|
||||
f'try again')
|
||||
|
||||
@ -2117,9 +2117,11 @@ def get_pitching_decisions(game: StratGame):
|
||||
def get_final_scorebug(away_team, home_team, away_stats, home_stats):
|
||||
return f'```' \
|
||||
f'Team | R | H | E |\n' \
|
||||
f'{away_team["abbrev"]: <4} | {away_stats["score"]: >2} | {away_stats["hits"]: >2} | ' \
|
||||
f'{away_team["abbrev"].replace("Gauntlet-", ""): <4} | {away_stats["score"]: >2} | ' \
|
||||
f'{away_stats["hits"]: >2} | ' \
|
||||
f'{away_stats["f_lines"][0]["tm_error"] if away_stats["f_lines"] else 0: >2} |\n' \
|
||||
f'{home_team["abbrev"]: <4} | {home_stats["score"]: >2} | {home_stats["hits"]: >2} | ' \
|
||||
f'{home_team["abbrev"].replace("Gauntlet-", ""): <4} | {home_stats["score"]: >2} | ' \
|
||||
f'{home_stats["hits"]: >2} | ' \
|
||||
f'{home_stats["f_lines"][0]["tm_error"] if home_stats["f_lines"] else 0: >2} |\n' \
|
||||
f'```'
|
||||
|
||||
|
||||
52
gauntlets.py
52
gauntlets.py
@ -8,11 +8,11 @@ from peewee import DatabaseError
|
||||
|
||||
import ai_manager
|
||||
import helpers
|
||||
from helpers import RARITY, get_cal_user
|
||||
from db_calls import db_get, db_post, db_delete
|
||||
from helpers import RARITY, get_cal_user, get_or_create_role, send_to_channel, get_channel
|
||||
from db_calls import db_get, db_post, db_delete, db_patch
|
||||
|
||||
|
||||
async def wipe_team(this_team, interaction: discord.Interaction):
|
||||
async def wipe_team(this_team, interaction: discord.Interaction, delete_team: bool = False):
|
||||
await interaction.edit_original_response(content=f'Looking for cards...')
|
||||
# Delete cards
|
||||
c_query = db_get('cards', params=[('team_id', this_team['id'])])
|
||||
@ -28,9 +28,10 @@ async def wipe_team(this_team, interaction: discord.Interaction):
|
||||
db_delete('packs', object_id=x['id'])
|
||||
|
||||
# Delete team
|
||||
await interaction.edit_original_response(content=f'Done deleting packs; now deleting team...')
|
||||
db_delete('teams', object_id=this_team['id'])
|
||||
await interaction.edit_original_response(content=f'Team is deleted; now finding the run...')
|
||||
if delete_team:
|
||||
await interaction.edit_original_response(content=f'Done deleting packs; now deleting team...')
|
||||
db_delete('teams', object_id=this_team['id'])
|
||||
await interaction.edit_original_response(content=f'Team is deleted; now finding the run...')
|
||||
|
||||
r_query = db_get('gauntletruns', params=[('team_id', this_team['id']), ('is_active', True)])
|
||||
await interaction.edit_original_response(content=f'Found {r_query["count"]} runs; deleting now...')
|
||||
@ -376,3 +377,42 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event):
|
||||
'gauntlet_id': this_event['id']
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def post_result(run_id: int, is_win: bool, this_team, bot, ctx):
|
||||
this_run = db_get('gauntletruns', object_id=run_id)
|
||||
this_event = db_get('events', object_id=this_run['gauntlet']['id'])
|
||||
|
||||
if is_win:
|
||||
db_patch(
|
||||
'gauntletruns',
|
||||
object_id=this_run['id'],
|
||||
params=[('wins', this_run['wins'] + 1), ('ended', this_run['wins'] + 1 == 10)]
|
||||
)
|
||||
|
||||
if this_run['wins'] + 1 == 10:
|
||||
choas_role = await get_or_create_role(ctx, "CHOAS ALERT", mentionable=True)
|
||||
await send_to_channel(
|
||||
bot,
|
||||
'pd-network-news',
|
||||
content=f'{choas_role.mention}\n\nThe **{this_team["lname"]}** have completed the '
|
||||
f'**{this_event["name"]} Gauntlet** with a record of {this_run["wins"] + 1}-'
|
||||
f'{this_run["losses"]}!'
|
||||
)
|
||||
else:
|
||||
await ctx.send(f'Big win there! Your {this_event["name"]} record is now '
|
||||
f'**{this_run["wins"] + 1}-{this_run["losses"]}**. Go share the highlights in '
|
||||
f'{get_channel(ctx, "pd-news-ticker").mention}!')
|
||||
else:
|
||||
db_patch(
|
||||
'gauntletruns',
|
||||
object_id=this_run['id'],
|
||||
params=[('losses', this_run['losses'] + 1), ('ended', this_run['losses'] + 1 == 2)]
|
||||
)
|
||||
l_message = f'Tough loss. That brings your {this_event["name"]} record to ' \
|
||||
f'**{this_run["wins"]}-{this_run["losses"] + 1}**. '
|
||||
if this_run['losses'] + 1 == 2:
|
||||
l_message += 'That\'s the end of this run - better luck next time!'
|
||||
|
||||
await ctx.send(l_message)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user