AbRoll and JumpRoll objects
Add handedness to pitcher/batter
This commit is contained in:
parent
f7685ff0e3
commit
7a718d45f0
@ -79,15 +79,15 @@ class Gameplay(commands.Cog):
|
||||
await interaction.channel.send(content=f'I let Cal know his bot is stupid')
|
||||
|
||||
scorebug_buttons, this_ab_roll = None, None
|
||||
scorebug_embed = await get_scorebug_embed(session, this_play.game, full_length=False, classic=CLASSIC_EMBED)
|
||||
|
||||
if this_play.game.roll_buttons and interaction.user.id in [this_play.game.away_team.gmid, this_play.game.home_team.gmid]:
|
||||
scorebug_buttons = ScorebugButtons(this_play)
|
||||
scorebug_buttons = ScorebugButtons(this_play, scorebug_embed)
|
||||
|
||||
if this_play.on_base_code == 0 and this_play.game.auto_roll and not this_play.batter.team.is_ai:
|
||||
this_ab_roll = ab_roll(this_play.batter.team, this_play.game, allow_chaos=False)
|
||||
scorebug_buttons = None
|
||||
|
||||
scorebug_embed = await get_scorebug_embed(session, this_play.game, full_length=False, classic=CLASSIC_EMBED)
|
||||
if this_ab_roll is not None and this_ab_roll.d_six_one > 3:
|
||||
scorebug_embed.set_image(url=this_play.pitcher.player.pitcher_card_url)
|
||||
|
||||
@ -270,7 +270,7 @@ class Gameplay(commands.Cog):
|
||||
league.value
|
||||
)
|
||||
await interaction.edit_original_response(
|
||||
content=f'The {ai_team.sname} are starting **{ai_sp_lineup.player.name_with_desc}**:\n\n{ai_sp_lineup.player.p_card_url}'
|
||||
content=f'The {ai_team.sname} are starting **{ai_sp_lineup.player.name_with_desc}**:\n\n{ai_sp_lineup.player.pitcher_card_url}'
|
||||
)
|
||||
|
||||
# Get AI Lineup
|
||||
|
||||
@ -161,8 +161,11 @@ async def get_scorebug_embed(session: Session, this_game: Game, full_length: boo
|
||||
baserunner_string += f'On Third: {curr_play.on_third.player.name_card_link('batting')}\nSteal: {steal_string(runcard)}, Run: {runcard.running}\n'
|
||||
logger.info(f'gameplay_models - Game.get_scorebug_embed - baserunner_string: {baserunner_string}')
|
||||
|
||||
pit_string = f'{curr_play.pitcher.player.name_card_link('pitching')}'
|
||||
bat_string = f'{curr_play.batter.player.name_card_link('batting')}'
|
||||
pitchingcard = curr_play.pitcher.card.pitcherscouting.pitchingcard
|
||||
battingcard = curr_play.batter.card.batterscouting.battingcard
|
||||
|
||||
pit_string = f'{pitchingcard.hand.upper()}HP | {curr_play.pitcher.player.name_card_link('pitching')}'
|
||||
bat_string = f'{curr_play.batter.batting_order}. {battingcard.hand.upper()} | {curr_play.batter.player.name_card_link('batting')}'
|
||||
if len(baserunner_string) > 0:
|
||||
pitchingcard = curr_play.pitcher.card.pitcherscouting.pitchingcard
|
||||
pit_string += f'\nHold: {pitchingcard.hold}, WP: {pitchingcard.wild_pitch}, Bk: {pitchingcard.balk}'
|
||||
|
||||
51
dice.py
51
dice.py
@ -15,15 +15,20 @@ class DiceRoll(pydantic.BaseModel):
|
||||
roll_message: str | None = None
|
||||
embeds: list[discord.Embed] | None = None
|
||||
|
||||
|
||||
class AbRoll(DiceRoll):
|
||||
is_chaos: bool = False
|
||||
d_six_one: int | None = None
|
||||
d_six_two: int | None = None
|
||||
d_six_three: int | None = None
|
||||
d_twenty: int | None = None
|
||||
|
||||
|
||||
class AbRoll(DiceRoll):
|
||||
d_six_three: int | None = None
|
||||
|
||||
|
||||
class JumpRoll(DiceRoll):
|
||||
pass
|
||||
|
||||
|
||||
def get_dice_embed(team: Team = None, embed_title: str = None):
|
||||
if team:
|
||||
embed = discord.Embed(
|
||||
@ -854,14 +859,12 @@ def ab_roll(this_team: Team, this_game: Game, allow_chaos: bool = True) -> AbRol
|
||||
embeds=[embed]
|
||||
)
|
||||
|
||||
logger.info(f'Pre-AB roll')
|
||||
this_roll = AbRoll(
|
||||
d_six_one=random.randint(1, 6),
|
||||
d_six_two=random.randint(1, 6),
|
||||
d_six_three=random.randint(1, 6),
|
||||
d_twenty=random.randint(1, 20)
|
||||
)
|
||||
logger.info(f'AB roll base: {this_roll}')
|
||||
|
||||
this_roll.roll_message = f'```md\n# {this_roll.d_six_one},{this_roll.d_six_two + this_roll.d_six_three},{this_roll.d_twenty}\nDetails:[1d6;2d6;1d20 ({this_roll.d_six_one} - {this_roll.d_six_two} {this_roll.d_six_three} - {this_roll.d_twenty})]```'
|
||||
|
||||
@ -875,23 +878,15 @@ def ab_roll(this_team: Team, this_game: Game, allow_chaos: bool = True) -> AbRol
|
||||
|
||||
this_roll.embeds = [embed]
|
||||
|
||||
# if d_six_one == 6 and d_six_two + d_six_three > 6:
|
||||
# roll_message += f'\n**Check injury for pitcher injury rating {13 - d_six_two - d_six_three}**\n' \
|
||||
# f'Oops! All injuries!'
|
||||
|
||||
|
||||
logger.info(f'Game {this_game.id} | Team {this_team.id} ({this_team.abbrev}): {this_roll.roll_message}')
|
||||
return this_roll
|
||||
|
||||
|
||||
def jump_roll(this_team: Team, this_game: Game) -> list[discord.Embed]:
|
||||
def jump_roll(this_team: Team, this_game: Game) -> JumpRoll:
|
||||
"""
|
||||
Check for a baserunner's jump before stealing
|
||||
"""
|
||||
d_six_one = random.randint(1, 6)
|
||||
d_six_two = random.randint(1, 6)
|
||||
d_twenty = random.randint(1, 20)
|
||||
d_twenty_two = random.randint(1, 20)
|
||||
flag = None
|
||||
|
||||
if d_twenty == 1:
|
||||
@ -899,21 +894,31 @@ def jump_roll(this_team: Team, this_game: Game) -> list[discord.Embed]:
|
||||
elif d_twenty == 2:
|
||||
flag = 'balk'
|
||||
|
||||
if not flag:
|
||||
roll_message = f'```md\n# {d_six_one + d_six_two}\n'\
|
||||
f'Details:[2d6 ({d_six_one} {d_six_two})]```'
|
||||
else:
|
||||
roll_message = f'```md\nCheck {flag}```\n' \
|
||||
f'{flag.title()} roll```md\n# {d_twenty_two}\nDetails: [1d20 ({d_twenty_two})]```'
|
||||
this_roll = JumpRoll(
|
||||
is_chaos=flag != None,
|
||||
d_six_one=random.randint(1, 6),
|
||||
d_six_two=random.randint(1, 6),
|
||||
d_twenty=random.randint(1, 20)
|
||||
)
|
||||
|
||||
if not flag:
|
||||
this_roll.roll_message = f'```md\n# {this_roll.d_six_one + this_roll.d_six_two}\n'\
|
||||
f'Details:[2d6 ({this_roll.d_six_one} {this_roll.d_six_two})]```'
|
||||
else:
|
||||
this_roll.roll_message = f'```md\nCheck {flag}```\n' \
|
||||
f'{flag.title()} roll```md\n# {this_roll.d_twenty_two}\nDetails: [1d20 ({this_roll.d_twenty_two})]```'
|
||||
|
||||
logger.info(f'AB roll with message: {this_roll}')
|
||||
|
||||
embed = get_dice_embed(this_team)
|
||||
embed.add_field(
|
||||
name=f'Jump check for the {this_team.sname}',
|
||||
value=roll_message
|
||||
value=this_roll.roll_message
|
||||
)
|
||||
|
||||
this_roll.embeds = [embed]
|
||||
|
||||
logger.info(f'Game {this_game.id} | Team {this_team.id} ({this_team.abbrev}): {roll_message}')
|
||||
return [embed]
|
||||
logger.info(f'Game {this_game.id} | Team {this_team.id} ({this_team.abbrev}): {this_roll.roll_message}')
|
||||
return this_roll
|
||||
|
||||
|
||||
|
||||
@ -717,43 +717,6 @@ class PlayerBase(SQLModel):
|
||||
else:
|
||||
return value
|
||||
|
||||
@property
|
||||
def p_card_url(self):
|
||||
if 'pitching' in self.image:
|
||||
return self.image
|
||||
elif self.image2 is not None and 'pitching' in self.image2:
|
||||
return self.image2
|
||||
else:
|
||||
logger.error(f'gameplay_models - PlayerBase - pitching card url not found for {self.id}. {self.description} {self.name}')
|
||||
return self.image
|
||||
|
||||
@property
|
||||
def b_card_url(self):
|
||||
if 'batting' in self.image:
|
||||
return self.image
|
||||
elif self.image2 is not None and 'batting' in self.image2:
|
||||
return self.image2
|
||||
else:
|
||||
logger.error(f'gameplay_models - PlayerBase - batting card url not found for {self.id}. {self.description} {self.name}')
|
||||
return self.image
|
||||
|
||||
def name_card_link(self, which: Literal['pitching', 'batting']):
|
||||
if which == 'pitching':
|
||||
return f'[{self.name}]({self.p_card_url})'
|
||||
else:
|
||||
return f'[{self.name}]({self.b_card_url})'
|
||||
|
||||
|
||||
class Player(PlayerBase, table=True):
|
||||
cardset: Cardset = Relationship(back_populates='players')
|
||||
cards: list['Card'] = Relationship(back_populates='player', cascade_delete=True)
|
||||
lineups: list['Lineup'] = Relationship(back_populates='player', cascade_delete=True)
|
||||
positions: list['PositionRating'] = Relationship(back_populates='player', cascade_delete=True)
|
||||
|
||||
@property
|
||||
def name_with_desc(self):
|
||||
return f'{self.description} {self.name}'
|
||||
|
||||
@property
|
||||
def batter_card_url(self):
|
||||
if 'batting' in self.image:
|
||||
@ -772,6 +735,23 @@ class Player(PlayerBase, table=True):
|
||||
else:
|
||||
return None
|
||||
|
||||
def name_card_link(self, which: Literal['pitching', 'batting']):
|
||||
if which == 'pitching':
|
||||
return f'[{self.name}]({self.pitcher_card_url})'
|
||||
else:
|
||||
return f'[{self.name}]({self.batter_card_url})'
|
||||
|
||||
|
||||
class Player(PlayerBase, table=True):
|
||||
cardset: Cardset = Relationship(back_populates='players')
|
||||
cards: list['Card'] = Relationship(back_populates='player', cascade_delete=True)
|
||||
lineups: list['Lineup'] = Relationship(back_populates='player', cascade_delete=True)
|
||||
positions: list['PositionRating'] = Relationship(back_populates='player', cascade_delete=True)
|
||||
|
||||
@property
|
||||
def name_with_desc(self):
|
||||
return f'{self.description} {self.name}'
|
||||
|
||||
|
||||
def player_description(player: Player = None, player_dict: dict = None) -> str:
|
||||
if player is None and player_dict is None:
|
||||
|
||||
@ -63,7 +63,7 @@ def test_player_id_from_dict(session: Session):
|
||||
def test_player_card_link(session: Session):
|
||||
player_1 = session.get(Player, 70)
|
||||
|
||||
assert player_1.b_card_url == 'player_69_battingcard'
|
||||
assert player_1.p_card_url == 'player_69_pitchingcard'
|
||||
assert player_1.batter_card_url == 'player_69_battingcard'
|
||||
assert player_1.pitcher_card_url == 'player_69_pitchingcard'
|
||||
assert player_1.name_card_link('pitching') == '[Player 69](player_69_pitchingcard)'
|
||||
assert player_1.name_card_link('batting') == '[Player 69](player_69_battingcard)'
|
||||
|
||||
@ -178,14 +178,17 @@ async def ask_confirm(interaction: discord.Interaction, question: str, label_typ
|
||||
|
||||
|
||||
class ScorebugButtons(discord.ui.View):
|
||||
def __init__(self, play: Play, timeout: float = 30):
|
||||
def __init__(self, play: Play, embed: discord.Embed, timeout: float = 30):
|
||||
super().__init__(timeout=timeout)
|
||||
self.value = None
|
||||
self.batting_team = play.batter.team
|
||||
self.pitching_team = play.pitcher.team
|
||||
self.pitcher_card_url = play.pitcher.player.pitcher_card_url
|
||||
self.batter_card_url = play.batter.player.batter_card_url
|
||||
self.team = play.batter.team
|
||||
self.play = play
|
||||
self.had_chaos = False
|
||||
self.embed = embed
|
||||
|
||||
if play.on_base_code == 0:
|
||||
self.remove_item(self.button_jump)
|
||||
@ -221,7 +224,14 @@ class ScorebugButtons(discord.ui.View):
|
||||
button.disabled = True
|
||||
|
||||
await interaction.channel.send(content=None, embeds=this_roll.embeds)
|
||||
await interaction.response.edit_message(view=self)
|
||||
|
||||
if this_roll.d_six_one > 3:
|
||||
logger.info(f'ScorebugButton - updating embed card to pitcher')
|
||||
self.embed.set_image(url=self.pitcher_card_url)
|
||||
logger.debug(f'embed image url: {self.embed.image}')
|
||||
|
||||
logger.debug(f'new embed: {self.embed}')
|
||||
await interaction.response.edit_message(view=self, embed=self.embed)
|
||||
|
||||
@discord.ui.button(label='Check Jump', style=discord.ButtonStyle.secondary)
|
||||
async def button_jump(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
@ -230,6 +240,6 @@ class ScorebugButtons(discord.ui.View):
|
||||
this_roll = jump_roll(self.team, self.play.game)
|
||||
button.disabled = True
|
||||
|
||||
await interaction.channel.send(content=None, embeds=this_roll)
|
||||
await interaction.channel.send(content=None, embeds=this_roll.embeds)
|
||||
await interaction.response.edit_message(view=self)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user