Skip to content

Commit

Permalink
correccion en el json_msg al jugar la carta de defensa
Browse files Browse the repository at this point in the history
  • Loading branch information
anelioalvarez committed Nov 9, 2023
1 parent 6ba453b commit 4101222
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/routers/games/defense_functions.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
11 changes: 8 additions & 3 deletions app/routers/games/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions app/routers/games/intention.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/routers/games/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4101222

Please sign in to comment.