Skip to content

Commit

Permalink
refactorizacion intercambio de cartas con defensa
Browse files Browse the repository at this point in the history
  • Loading branch information
anelioalvarez committed Nov 11, 2023
1 parent 0e00476 commit e4d4dc4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
33 changes: 18 additions & 15 deletions app/routers/games/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,20 @@ async def intention_to_interchange_card(game_name: str, interchange_info: Intent
utils.verify_if_interchange_can_be_done(game_name, interchange_info)
objective_player_id = utils.get_id_of_next_player_in_turn(game_name)

'''exchange_intention = services.register_card_exchange_intention(
game_name, interchange_info)'''

with db_session:
objective_player = find_player_by_id(objective_player_id)

json_msg = {
"event": "exchange_intention",
"player_id": interchange_info.player_id,
"player_name": get_player_name_by_id(interchange_info.player_id),
"card_to_exchange": interchange_info.card_id,
"defense_cards": player_cards_to_defend_himself(ActionType.EXCHANGE_OFFER, objective_player)
}
await player_connections.send_event_to(objective_player_id, json_msg)
services.register_card_exchange_intention(
game_name, interchange_info.player_id, interchange_info.card_id, objective_player_id)

# with db_session:
# objective_player = find_player_by_id(objective_player_id)

# json_msg = {
# "event": "exchange_intention",
# "player_id": interchange_info.player_id,
# "player_name": get_player_name_by_id(interchange_info.player_id),
# "card_to_exchange": interchange_info.card_id,
# "defense_cards": player_cards_to_defend_himself(ActionType.EXCHANGE_OFFER, objective_player)
# }
# await player_connections.send_event_to(objective_player_id, json_msg)
return {"message": "Card interchange intention terminated."}


Expand All @@ -245,7 +245,10 @@ async def card_interchange_response(game_name: str, game_data: InterchangeInform
utils.verify_if_interchange_response_can_be_done(game_name, game_data)
services.card_interchange_response(game_name, game_data)

# clean_intention_in_game(game_name)
game: Game = find_game_by_name(game_name)
set_objective_card_in_exchange_payload(game, game_data.card_id)

clean_intention_in_game(game_name)

json_msg = {
"event": utils.Events.EXCHANGE_DONE,
Expand Down
14 changes: 8 additions & 6 deletions app/routers/games/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@ def play_action_card(game_name: str, play_info: PlayInformation):
detail="The card to exchange cannot be The Thing"
)
verify_card_in_hand(player, card_to_exchange)
process_seduction_card(
game, player, objective_player, card_to_exchange)

exchange_payload = {"card_id": card_to_exchange.id}
create_intention_in_game(
game, ActionType.EXCHANGE_OFFER, player, objective_player, exchange_payload)

player.hand.remove(card)
game.discard_deck.add(card)
Expand Down Expand Up @@ -538,11 +540,11 @@ def pass_card(play_info: PlayInformation):


@db_session
def register_card_exchange_intention(game_name: str, exchange_info: IntentionExchangeInformationIn) -> Intention:
def register_card_exchange_intention(game_name: str, player_id: int, card_id: int, objective_player_id: int) -> Intention:
game: Game = find_game_by_name(game_name)
player: Player = find_player_by_id(exchange_info.player_id)
objective_player = utils.get_next_player_in_turn(game)
exchange_payload = {"card_id": exchange_info.card_id}
player: Player = find_player_by_id(player_id)
objective_player = find_player_by_id(objective_player_id)
exchange_payload = {"card_id": card_id}

exchange_intention = create_intention_in_game(
game, ActionType.EXCHANGE_OFFER, player, objective_player, exchange_payload)
Expand Down

0 comments on commit e4d4dc4

Please sign in to comment.