diff --git a/app/routers/games/defense_functions.py b/app/routers/games/defense_functions.py index 834b08a..3ba2ac4 100644 --- a/app/routers/games/defense_functions.py +++ b/app/routers/games/defense_functions.py @@ -1,14 +1,14 @@ from pony.orm import * from app.database.models import Player -from ..cards.schemas import CardActionName, CardDefenseName +from ..cards.schemas import CardDefenseName from enum import Enum class ActionType(str, Enum): - EXCHANGE_OFFER = "Ofrecimiento de intercambio" - CHANGE_PLACES = CardActionName.CHANGE_PLACES.value - BETTER_RUN = CardActionName.BETTER_RUN.value - FLAMETHROWER = CardActionName.FLAMETHROWER.value + EXCHANGE_OFFER = "exchange_offer" + CHANGE_PLACES = "change_places" + BETTER_RUN = "better_run" + FLAMETHROWER = "flamethrower" response_to_action_type = { diff --git a/app/routers/games/games.py b/app/routers/games/games.py index 7200d76..3790e6e 100644 --- a/app/routers/games/games.py +++ b/app/routers/games/games.py @@ -336,11 +336,16 @@ async def play_defense_card(game_name: str, defense_info: PlayDefenseInformation if defense_info.card_id: services.play_defense_card(game_name, defense_info) + intention: Intention = get_intention_in_game(game_name) json_msg = { - "event": get_intention_in_game(game_name).action_type, - "player_id": defense_info.player_id, - "card_id": defense_info.card_id + "event": utils.Events.DEFENSE_CARD_PLAYED, + "card_id": defense_info.card_id, + "player_id": intention.player.id, + "player_name": intention.player.name, + "objective_player_id": intention.objective_player.id, + "objective_player_name": intention.objective_player.name, + "action_type": intention.action_type } await player_connections.send_event_to_all_players_in_game(game_name, json_msg) else: diff --git a/app/routers/games/intention.py b/app/routers/games/intention.py index 38ed066..17ec2d1 100644 --- a/app/routers/games/intention.py +++ b/app/routers/games/intention.py @@ -38,6 +38,11 @@ def create_intention_in_game(game: Game, action_type: ActionType, player: Player return intention +@db_session +def set_objective_card_in_exchange_payload(game: Game, objective_card_id: int): + game.intention.exchange_payload['objective_card_id'] = objective_card_id + + @db_session def process_intention_in_game(game_name) -> Intention: game: Game = find_game_by_name(game_name) @@ -49,9 +54,9 @@ def process_intention_in_game(game_name) -> Intention: case ActionType.EXCHANGE_OFFER: exchange_info = intention.exchange_payload - player_card = find_card_by_id(exchange_info.card_id) + player_card = find_card_by_id(exchange_info['card_id']) objective_player_card = find_card_by_id( - exchange_info.objective_card_id) + exchange_info['objective_card_id']) process_card_exchange(player, objective_player, player_card, objective_player_card) diff --git a/app/routers/games/utils.py b/app/routers/games/utils.py index 71aa06d..aafd32f 100644 --- a/app/routers/games/utils.py +++ b/app/routers/games/utils.py @@ -49,6 +49,7 @@ class Events(str, Enum): SEDUCTION_DONE = 'seduction_done' INTERCHANGE_INTENTION = 'interchange_intention' INTERCHANGE_INTENTION_DONE = 'interchange_intention_done' + DEFENSE_CARD_PLAYED = "defense_card_played" async def send_played_card_event(game_name: str, player_id: int, card_id: int):