From 92c349e7f25d9aa318f76d69c0a1955875ea94a8 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sat, 8 Mar 2025 03:25:26 -0600 Subject: [PATCH] fixed card recoivery from peice aftrer game --- Systems/Game/ChessGame.gd | 25 +++++++++++++++++++++++++ Systems/Game/WinConditionManager.gd | 24 ++---------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Systems/Game/ChessGame.gd b/Systems/Game/ChessGame.gd index c5d1077..05f3e10 100644 --- a/Systems/Game/ChessGame.gd +++ b/Systems/Game/ChessGame.gd @@ -770,6 +770,7 @@ func updatePointsAndCapture(capturedPiece: Pawn, animate: bool = true) -> void: func _on_win_condition_met(condition_data): print("Win condition met: ", condition_data) + recover_cards_from_player_pieces() emit_signal("node_completed", { "node": currentNode, "completed": true, @@ -780,6 +781,7 @@ func _on_win_condition_met(condition_data): func _on_loss_condition_met(condition_data): print("Loss condition met: ", condition_data) + recover_cards_from_player_pieces() emit_signal("node_completed", { "node": currentNode, "completed": true, @@ -794,6 +796,29 @@ func animatePieceCapture(capturedPiece: Pawn) -> void: await capturedPiece.animate_capture() container.remove_piece() +func recover_cards_from_player_pieces(): + for y in range(boardYSize): + for x in range(boardXSize): + var piece = (boardContainer.get_node(str(x) + "-" + str(y)) as PieceContainer).get_piece() + + if piece != null and piece.Item_Color == 0: + var piece_id = piece.get_instance_id() + + if deckManager.attached_cards.has(piece_id): + var card = deckManager.attached_cards[piece_id] + card.reset() + + match card.rank: + Card.Rank.RANK_2: + deckManager.deck.append(card) + print("Recovered Rank 2 card pile: ", card.cardName) + Card.Rank.RANK_3: + deckManager.deck.append(card) + print("Recovered Rank 3 card to deck: ", card.cardName) + + # Remove from attached_cards + deckManager.attached_cards.erase(piece_id) + # =========================================================================== # FEN NOTATION AND POSITION TRACKING # =========================================================================== diff --git a/Systems/Game/WinConditionManager.gd b/Systems/Game/WinConditionManager.gd index 7395a2e..ba74198 100644 --- a/Systems/Game/WinConditionManager.gd +++ b/Systems/Game/WinConditionManager.gd @@ -109,17 +109,14 @@ func _on_turn_changed(): "message": "Turn limit exceeded!" }) - # Check all conditions after turn change check_conditions() func on_piece_captured(piece): - # First verify this is an enemy piece (with opposite color to current player) var is_enemy_piece = piece.Item_Color == (1 if chess_game.Turn == 0 else 0) print("on_piece_captured ISEnemy ", is_enemy_piece) if is_enemy_piece: captured_pieces.append(piece) - # Update progress for board-cleared condition if win_condition == Utils.WinConditionType.BOARD_CLEARED: condition_progress["remaining_enemy_pieces"] -= 1 emit_signal("condition_progress_updated", condition_progress) @@ -130,7 +127,6 @@ func on_piece_captured(piece): "message": "Board cleared of enemy pieces!" }) - # Check for specific unit capture (default: King) if win_condition == Utils.WinConditionType.CAPTURE_UNIT: var target_unit = win_condition_data.get("unit", "King") if piece.name == target_unit: @@ -139,16 +135,13 @@ func on_piece_captured(piece): "message": "Enemy " + target_unit + " captured!" }) - # Check all conditions after capture check_conditions() func on_piece_lost(piece): - # First verify this is a player piece (same color as current player) var is_player_piece = piece.Item_Color == (0 if chess_game.Turn == 0 else 1) print("on_piece_lost isPlayer ", is_player_piece) if is_player_piece: - # Check for unit loss (default: King) if loss_condition == Utils.LossConditionType.UNIT_LOST: var target_unit = loss_condition_data.get("unit", "King") if piece.name == target_unit: @@ -157,17 +150,13 @@ func on_piece_lost(piece): "message": "Your " + target_unit + " was captured!" }) - # Check all conditions after loss check_conditions() func on_piece_moved(piece, from_location, to_location): - # Check for tile reached condition if win_condition == Utils.WinConditionType.TILE_REACHED: - # Verify this is a player's piece (white if Turn==0, black if Turn==1) var is_player_piece = piece.Item_Color == (0 if chess_game.Turn == 0 else 1) if is_player_piece and target_tiles.has(to_location): - # If specific unit is required if "unit" in win_condition_data and win_condition_data["unit"] != "": if piece.name == win_condition_data["unit"]: if not condition_progress.has("tiles_reached"): @@ -199,11 +188,9 @@ func on_piece_moved(piece, from_location, to_location): "message": "Target tile reached!" }) - # Check all conditions after move check_conditions() func check_conditions(): - # This allows for custom condition checking beyond the standard events # Check board cleared condition if win_condition == Utils.WinConditionType.BOARD_CLEARED: @@ -214,23 +201,16 @@ func check_conditions(): "message": "Board cleared of enemy pieces!" }) - # Update the UI with current progress emit_signal("condition_progress_updated", condition_progress) func count_enemy_pieces() -> int: var count = 0 - - # Determine enemy color based on current turn - # In your system: - # - White pieces have Item_Color == 0 - # - Black pieces have Item_Color == 1 - # - Turn == 0 means white's turn, Turn == 1 means black's turn + var enemy_color = 1 if chess_game.Turn == 0 else 0 - # Iterate through the board to count enemy pieces for y in range(chess_game.boardYSize): for x in range(chess_game.boardXSize): - var piece = chess_game.board[y][x] + var piece = (chess_game.get_node(str(x) + "-" + str(y)) as PieceContainer).get_piece() if piece != null and piece.Item_Color == enemy_color: count += 1