Add duel update functionality: implement card and stat selection for duels
This commit is contained in:
parent
c8bc16638e
commit
1a1964f956
2 changed files with 53 additions and 3 deletions
|
@ -294,8 +294,8 @@ def start_duel(duel_id: int, row: dict, player_1_cards: list[int], player_2_card
|
|||
player_2_cards_details = get_cards(player_2_cards)
|
||||
# Send a notification to player 2 with their cards
|
||||
fediverse_service.create_post(
|
||||
text=f'{player_2_name} Your cards for the duel. \
|
||||
Reply with select <1,2 or 3> to select a card for the duel.',
|
||||
text=f'{player_2_name} Your cards for the duel. You are defending!. \
|
||||
Select a card with <1,2 or 3> and a stat with <1,2 or 3> for Power, Charm and Wit. Example: select 2 3 would select the second card and use its Wit stat.',
|
||||
visibility=Visibility.SPECIFIED,
|
||||
file_ids=[card['file_id'] for card in player_2_cards_details],
|
||||
visible_user_ids=[player_2_server_id]
|
||||
|
|
|
@ -257,8 +257,53 @@ def accept_duel(author: str, args: list[str]) -> BotResponse:
|
|||
'attachment_urls': None
|
||||
}
|
||||
|
||||
def update_duel(author: str, args: list[str]) -> BotResponse:
|
||||
'''Updates the duel with the selected card and stat.'''
|
||||
if len(args) != 2:
|
||||
return {
|
||||
'message': f'{author} Please specify a card number and a stat number.',
|
||||
'attachment_urls': None
|
||||
}
|
||||
|
||||
|
||||
if not all(is_float(arg) for arg in args):
|
||||
return {
|
||||
'message': f'{author} Invalid arguments: both card number and stat number must be numbers.',
|
||||
'attachment_urls': None
|
||||
}
|
||||
|
||||
card_number = int(args[0]) - 1 # Convert to zero-based index
|
||||
stat_number = int(args[1]) - 1 # Convert to zero-based index
|
||||
|
||||
duel = db.get_duel_by_player(author)
|
||||
if not duel:
|
||||
return {
|
||||
'message': f'{author} You are not currently in a duel.',
|
||||
'attachment_urls': None
|
||||
}
|
||||
|
||||
player_id = db.get_player(author)
|
||||
player_cards = db.get_player_cards(player_id)
|
||||
|
||||
if card_number < 0 or card_number >= len(player_cards):
|
||||
return {
|
||||
'message': f'{author} Invalid card number: {card_number + 1}.',
|
||||
'attachment_urls': None
|
||||
}
|
||||
|
||||
selected_card = player_cards[card_number]
|
||||
if stat_number < 0 or stat_number >= len(selected_card['stats']):
|
||||
return {
|
||||
'message': f'{author} Invalid stat number: {stat_number + 1}.',
|
||||
'attachment_urls': None
|
||||
}
|
||||
|
||||
db.update_duel_selection(duel['id'], player_id, selected_card['id'], stat_number)
|
||||
|
||||
return {
|
||||
'message': f'{author} You have selected {selected_card["name"]} with \
|
||||
{selected_card["stats"][stat_number]} in {["Power", "Charm", "Wit"][stat_number]} for the duel.',
|
||||
'attachment_urls': None]
|
||||
}
|
||||
|
||||
def delete_account(author: str) -> BotResponse:
|
||||
return {
|
||||
|
@ -413,6 +458,11 @@ def generate_response(notification: ParsedNotification) -> BotResponse | None:
|
|||
author,
|
||||
notification['arguments']
|
||||
)
|
||||
case 'select':
|
||||
res = update_duel(
|
||||
author,
|
||||
notification['arguments']
|
||||
)
|
||||
case _:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue