Refactor /substitution to /substitute pitcher and batter
This commit is contained in:
parent
c10fc7c22f
commit
b941f1641e
173
cogs/gameplay.py
173
cogs/gameplay.py
@ -944,82 +944,8 @@ class Gameplay(commands.Cog):
|
||||
if comp_play:
|
||||
complete_play(this_play.id)
|
||||
|
||||
# @commands.command(name='tl')
|
||||
# @commands.is_owner()
|
||||
# async def test_lineup_command(self, ctx, team_abbrev: str):
|
||||
# t_query = await db_get('teams', params=[('abbrev', team_abbrev)])
|
||||
# if t_query['count'] > 0:
|
||||
# team = t_query['teams'][0]
|
||||
# await ctx.send(f'Pulling a lineup for the {team["lname"]}...')
|
||||
# lineups = ai_manager.build_lineup(team, 69420, 'l', 'minor-league')
|
||||
# l_output = ''
|
||||
# for line in lineups:
|
||||
# l_output += f'{line["batting_order"]} - {line["player_name"]} - {line["position"]}\n'
|
||||
# await ctx.send(f'Lineups:\n\n{l_output}')
|
||||
# else:
|
||||
# await ctx.send(f'No team found with abbrev {team_abbrev}')
|
||||
#
|
||||
# @commands.command(name='tr')
|
||||
# @commands.is_owner()
|
||||
# async def test_reliever_command(self, ctx, game_id: int):
|
||||
# this_game = get_one_game(game_id=game_id)
|
||||
# ai_id = this_game.away_team_id if this_game.ai_team == 'away' else this_game.home_team_id
|
||||
# ai_team = await db_get('teams', object_id=ai_id)
|
||||
# used_pitchers = await get_team_lineups(
|
||||
# game_id=game_id, team_id=ai_team['id'], inc_inactive=True, pitchers_only=True, as_string=False
|
||||
# )
|
||||
# reliever = ai_manager.get_relief_pitcher(get_current_play(game_id), ai_team, used_pitchers)
|
||||
# await ctx.send(f'Reliever selected:\n\n{reliever}')
|
||||
|
||||
group_new_game = app_commands.Group(name='new-game', description='Start a new baseball game')
|
||||
|
||||
# @group_new_game.command(name='sba', description='Start a new SBa league game')
|
||||
# @commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
# async def new_game_command(
|
||||
# self, interaction: discord.Interaction, away_team_abbrev: str, home_team_abbrev: str, week_num: int,
|
||||
# game_num: int):
|
||||
# await interaction.response.defer()
|
||||
#
|
||||
# conflict = get_one_game(channel_id=interaction.channel.id, active=True)
|
||||
# if conflict:
|
||||
# await interaction.edit_original_response(
|
||||
# content=f'Ope. There is already a game going on in this channel. Please wait for it to complete '
|
||||
# f'before starting a new one.')
|
||||
# return
|
||||
#
|
||||
# away_team = get_sba_team(away_team_abbrev)
|
||||
# home_team = get_sba_team(home_team_abbrev)
|
||||
# for x in [away_team, home_team]:
|
||||
# conflict = count_team_games(x['id'])
|
||||
# if conflict['count']:
|
||||
# await interaction.edit_original_response(
|
||||
# content=f'Ope. The {x["sname"]} are already playing over in '
|
||||
# f'{interaction.guild.get_channel(conflict["games"][0]["channel_id"]).mention}'
|
||||
# )
|
||||
# return
|
||||
#
|
||||
# if interaction.user.id not in [away_team['gmid'], away_team['gmid2'], home_team['gmid'], home_team['gmid2']]:
|
||||
# await interaction.edit_original_response(
|
||||
# content='You can only start a new game if you GM one of the teams.'
|
||||
# )
|
||||
# return
|
||||
#
|
||||
# post_game({
|
||||
# 'away_team_id': away_team['id'],
|
||||
# 'home_team_id': home_team['id'],
|
||||
# 'season': SBA_SEASON,
|
||||
# 'week_num': week_num,
|
||||
# 'game_num': game_num,
|
||||
# 'channel_id': interaction.channel.id,
|
||||
# 'active': True,
|
||||
# 'is_pd': False,
|
||||
# })
|
||||
# logging.info(f'game is posted!')
|
||||
#
|
||||
# await interaction.edit_original_response(
|
||||
# content=f'The game is set! Go ahead and set lineups with `/setlineup`'
|
||||
# )
|
||||
|
||||
@group_new_game.command(name='mlb-campaign', description='Start a new MLB Campaign game against an AI')
|
||||
@app_commands.describe(
|
||||
sp_card_id='Light gray number to the left of the pitcher\'s name on your depth chart')
|
||||
@ -2571,69 +2497,46 @@ class Gameplay(commands.Cog):
|
||||
|
||||
await ctx.send(f'Got it!')
|
||||
|
||||
@app_commands.command(
|
||||
name='substitution',
|
||||
description='Make a lineup substitution; Player Name for SBa games / Card ID for PD games'
|
||||
)
|
||||
group_substitution = app_commands.Group(name='substitute', description='Make a substitution in active game')
|
||||
|
||||
@group_substitution.command(name='batter', description='Make a batter substitution')
|
||||
@app_commands.describe(
|
||||
order_number='Batting order of new player; 10 for pitchers if there is a DH',
|
||||
new_player='For PD game: enter the Card ID (a number); or SBa game: enter the Player Name')
|
||||
batting_order='Batting order of new player',
|
||||
new_player='Enter the Card ID (a number)')
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
|
||||
async def substitution_command(
|
||||
self, interaction: discord.Interaction, new_player: str, order_number: Literal[
|
||||
'this-spot', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
|
||||
async def sub_batter_command(
|
||||
self, interaction: discord.Interaction, new_player: int, batting_order: Literal[
|
||||
'this-spot', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
||||
new_pos: Literal['P', 'C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH', 'PH', 'PR']):
|
||||
this_game, owner_team, this_play = await self.checks_log_interaction(interaction)
|
||||
if False in (this_game, owner_team, this_play):
|
||||
return
|
||||
|
||||
try:
|
||||
if this_game.is_pd:
|
||||
this_card = await db_get(f'cards', object_id=int(new_player))
|
||||
if this_card["team"]["id"] != owner_team['id']:
|
||||
raise SyntaxError(f'Easy there, champ. Looks like card ID {new_player} belongs to the '
|
||||
f'{this_card["team"]["sname"]}. Try again with only cards you own.')
|
||||
player_id = this_card['player']['player_id']
|
||||
card_id = new_player
|
||||
else:
|
||||
this_player = get_sba_player(new_player, season=SBA_SEASON)
|
||||
if this_player['team']['id'] != owner_team['id']:
|
||||
raise SyntaxError(f'Easy there, champ. Looks like {new_player} is on '
|
||||
f'{this_player["team"]["sname"]}. Try again with only your own players.')
|
||||
player_id = this_player['id']
|
||||
card_id = None
|
||||
except Exception as e:
|
||||
logging.error(f'Game {this_game} - Could not find player {new_player}')
|
||||
if this_game.is_pd:
|
||||
await interaction.edit_original_response(
|
||||
content=f'I could not find card_id {new_player}.'
|
||||
)
|
||||
else:
|
||||
await interaction.edit_original_response(
|
||||
content=f'I could not find {new_player.title()}.'
|
||||
)
|
||||
return
|
||||
|
||||
if this_game.game_type in ['major-league', 'hall-of-fame']:
|
||||
legality = await db_post(f'cards/legal-check/ranked?card_id={new_player}')
|
||||
if this_game.game_type in ['major-league', 'hall-of-fame', 'tens']:
|
||||
legality = await db_post(f'cards/legal-check/{this_game.game_type}?card_id={new_player}')
|
||||
if legality['count'] > 0:
|
||||
il_string = "\n- ".join(legality['bad_cards'])
|
||||
await interaction.edit_original_response(
|
||||
content=f'It looks like this is a Ranked Legal game and I see the following cards as illegal. '
|
||||
f'Please adjust your lineup and re-submit!\n\n'
|
||||
content=f'It looks like this is a {this_game.game_type.replace("-", " ").title} game and I see '
|
||||
f'the following cards as illegal. Please take another look and re-submit!\n\n'
|
||||
f'- {il_string}'
|
||||
)
|
||||
return
|
||||
|
||||
this_play = get_current_play(this_game.id)
|
||||
batting_order = int(order_number) if order_number != 'this-spot' else this_play.batting_order
|
||||
batting_order = int(batting_order) if batting_order != 'this-spot' else this_play.batting_order
|
||||
|
||||
# Check for simple position change
|
||||
in_lineup = get_one_lineup(this_game.id, team_id=owner_team['id'], active=True, batting_order=batting_order)
|
||||
if in_lineup.card_id == int(card_id):
|
||||
post_pos = patch_lineup(in_lineup.id, position=new_pos)
|
||||
else:
|
||||
curr_play = get_current_play(this_game.id)
|
||||
this_lineup = {
|
||||
'game_id': this_game.id,
|
||||
'team_id': owner_team['id'],
|
||||
@ -2641,7 +2544,7 @@ class Gameplay(commands.Cog):
|
||||
'card_id': card_id,
|
||||
'position': new_pos.upper(),
|
||||
'batting_order': batting_order,
|
||||
'after_play': curr_play.play_num - 1 if curr_play else 0
|
||||
'after_play': this_play.play_num - 1 if this_play else 0
|
||||
}
|
||||
|
||||
make_sub(this_lineup)
|
||||
@ -2651,6 +2554,54 @@ class Gameplay(commands.Cog):
|
||||
embed=await self.get_game_state_embed(this_game)
|
||||
)
|
||||
|
||||
@group_substitution.command(name='pitcher', description='Make a pitching change')
|
||||
@app_commands.describe(
|
||||
new_player='Enter the Card ID (a number)',
|
||||
batting_order='Only enter this if you are forfeiting the DH')
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||
async def sub_pitcher_command(
|
||||
self, interaction: discord.Interaction, new_player: int,
|
||||
batting_order: Literal['this-spot', '1', '2', '3', '4', '5', '6', '7', '8', '9'] = None):
|
||||
this_game, owner_team, this_play = await self.checks_log_interaction(interaction)
|
||||
if False in (this_game, owner_team, this_play):
|
||||
return
|
||||
|
||||
if this_play.pitcher.team_id != owner_team['id']:
|
||||
await interaction.edit_original_response(
|
||||
content='It looks like your team is batting right now - please make this sub once you take the field.')
|
||||
return
|
||||
this_card = await db_get(f'cards', object_id=int(new_player))
|
||||
if this_card["team"]["id"] != owner_team['id']:
|
||||
raise SyntaxError(f'Easy there, champ. Looks like card ID {new_player} belongs to the '
|
||||
f'{this_card["team"]["sname"]}. Try again with only cards you own.')
|
||||
player_id = this_card['player']['player_id']
|
||||
card_id = new_player
|
||||
|
||||
old_pit_order = this_play.pitcher.batting_order
|
||||
if batting_order is None:
|
||||
batting_order = old_pit_order
|
||||
else:
|
||||
batting_order = int(batting_order)
|
||||
|
||||
this_lineup = {
|
||||
'game_id': this_game.id,
|
||||
'team_id': owner_team['id'],
|
||||
'player_id': player_id,
|
||||
'card_id': card_id,
|
||||
'position': 'P',
|
||||
'batting_order': batting_order,
|
||||
'after_play': this_play.play_num - 1 if this_play else 0
|
||||
}
|
||||
|
||||
make_sub(this_lineup)
|
||||
if old_pit_order != batting_order:
|
||||
patch_lineup(this_play.pitcher.id, active=False)
|
||||
|
||||
await interaction.edit_original_response(
|
||||
content=None,
|
||||
embed=await self.get_game_state_embed(this_game)
|
||||
)
|
||||
|
||||
@commands.hybrid_command(name='gamestate', help='Post the current game state', aliases=['gs'])
|
||||
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
|
||||
async def game_state_command(self, ctx: commands.Context, include_lineups: bool = True):
|
||||
|
||||
@ -745,7 +745,7 @@ def make_sub(lineup_dict: dict):
|
||||
|
||||
# Check current play for updates
|
||||
if curr_play:
|
||||
if not curr_play.pitcher and curr_play.batter.team_id != return_value.team_id:
|
||||
if (not curr_play.pitcher and curr_play.batter.team_id != return_value.team_id) or return_value.position == 'P':
|
||||
patch_play(curr_play.id, pitcher_id=return_value.id)
|
||||
|
||||
if subbed_player:
|
||||
|
||||
@ -3145,5 +3145,7 @@ def player_bcard(this_player):
|
||||
return this_player['image']
|
||||
elif this_player['image2'] is not None and 'batting' in this_player['image2']:
|
||||
return this_player['image2']
|
||||
# elif this_player['image'] is not None and 'pitching' in this_player['image']:
|
||||
# return PITCHER_BATTING_CARD
|
||||
else:
|
||||
return this_player['image']
|
||||
|
||||
Loading…
Reference in New Issue
Block a user