fixed card recoivery from peice aftrer game
This commit is contained in:
parent
c09ddcb1a2
commit
92c349e7f2
2 changed files with 27 additions and 22 deletions
|
|
@ -770,6 +770,7 @@ func updatePointsAndCapture(capturedPiece: Pawn, animate: bool = true) -> void:
|
||||||
|
|
||||||
func _on_win_condition_met(condition_data):
|
func _on_win_condition_met(condition_data):
|
||||||
print("Win condition met: ", condition_data)
|
print("Win condition met: ", condition_data)
|
||||||
|
recover_cards_from_player_pieces()
|
||||||
emit_signal("node_completed", {
|
emit_signal("node_completed", {
|
||||||
"node": currentNode,
|
"node": currentNode,
|
||||||
"completed": true,
|
"completed": true,
|
||||||
|
|
@ -780,6 +781,7 @@ func _on_win_condition_met(condition_data):
|
||||||
|
|
||||||
func _on_loss_condition_met(condition_data):
|
func _on_loss_condition_met(condition_data):
|
||||||
print("Loss condition met: ", condition_data)
|
print("Loss condition met: ", condition_data)
|
||||||
|
recover_cards_from_player_pieces()
|
||||||
emit_signal("node_completed", {
|
emit_signal("node_completed", {
|
||||||
"node": currentNode,
|
"node": currentNode,
|
||||||
"completed": true,
|
"completed": true,
|
||||||
|
|
@ -794,6 +796,29 @@ func animatePieceCapture(capturedPiece: Pawn) -> void:
|
||||||
await capturedPiece.animate_capture()
|
await capturedPiece.animate_capture()
|
||||||
container.remove_piece()
|
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
|
# FEN NOTATION AND POSITION TRACKING
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
|
|
||||||
|
|
@ -109,17 +109,14 @@ func _on_turn_changed():
|
||||||
"message": "Turn limit exceeded!"
|
"message": "Turn limit exceeded!"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check all conditions after turn change
|
|
||||||
check_conditions()
|
check_conditions()
|
||||||
|
|
||||||
func on_piece_captured(piece):
|
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)
|
var is_enemy_piece = piece.Item_Color == (1 if chess_game.Turn == 0 else 0)
|
||||||
print("on_piece_captured ISEnemy ", is_enemy_piece)
|
print("on_piece_captured ISEnemy ", is_enemy_piece)
|
||||||
if is_enemy_piece:
|
if is_enemy_piece:
|
||||||
captured_pieces.append(piece)
|
captured_pieces.append(piece)
|
||||||
|
|
||||||
# Update progress for board-cleared condition
|
|
||||||
if win_condition == Utils.WinConditionType.BOARD_CLEARED:
|
if win_condition == Utils.WinConditionType.BOARD_CLEARED:
|
||||||
condition_progress["remaining_enemy_pieces"] -= 1
|
condition_progress["remaining_enemy_pieces"] -= 1
|
||||||
emit_signal("condition_progress_updated", condition_progress)
|
emit_signal("condition_progress_updated", condition_progress)
|
||||||
|
|
@ -130,7 +127,6 @@ func on_piece_captured(piece):
|
||||||
"message": "Board cleared of enemy pieces!"
|
"message": "Board cleared of enemy pieces!"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check for specific unit capture (default: King)
|
|
||||||
if win_condition == Utils.WinConditionType.CAPTURE_UNIT:
|
if win_condition == Utils.WinConditionType.CAPTURE_UNIT:
|
||||||
var target_unit = win_condition_data.get("unit", "King")
|
var target_unit = win_condition_data.get("unit", "King")
|
||||||
if piece.name == target_unit:
|
if piece.name == target_unit:
|
||||||
|
|
@ -139,16 +135,13 @@ func on_piece_captured(piece):
|
||||||
"message": "Enemy " + target_unit + " captured!"
|
"message": "Enemy " + target_unit + " captured!"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check all conditions after capture
|
|
||||||
check_conditions()
|
check_conditions()
|
||||||
|
|
||||||
func on_piece_lost(piece):
|
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)
|
var is_player_piece = piece.Item_Color == (0 if chess_game.Turn == 0 else 1)
|
||||||
print("on_piece_lost isPlayer ", is_player_piece)
|
print("on_piece_lost isPlayer ", is_player_piece)
|
||||||
|
|
||||||
if is_player_piece:
|
if is_player_piece:
|
||||||
# Check for unit loss (default: King)
|
|
||||||
if loss_condition == Utils.LossConditionType.UNIT_LOST:
|
if loss_condition == Utils.LossConditionType.UNIT_LOST:
|
||||||
var target_unit = loss_condition_data.get("unit", "King")
|
var target_unit = loss_condition_data.get("unit", "King")
|
||||||
if piece.name == target_unit:
|
if piece.name == target_unit:
|
||||||
|
|
@ -157,17 +150,13 @@ func on_piece_lost(piece):
|
||||||
"message": "Your " + target_unit + " was captured!"
|
"message": "Your " + target_unit + " was captured!"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check all conditions after loss
|
|
||||||
check_conditions()
|
check_conditions()
|
||||||
|
|
||||||
func on_piece_moved(piece, from_location, to_location):
|
func on_piece_moved(piece, from_location, to_location):
|
||||||
# Check for tile reached condition
|
|
||||||
if win_condition == Utils.WinConditionType.TILE_REACHED:
|
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)
|
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 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 "unit" in win_condition_data and win_condition_data["unit"] != "":
|
||||||
if piece.name == win_condition_data["unit"]:
|
if piece.name == win_condition_data["unit"]:
|
||||||
if not condition_progress.has("tiles_reached"):
|
if not condition_progress.has("tiles_reached"):
|
||||||
|
|
@ -199,11 +188,9 @@ func on_piece_moved(piece, from_location, to_location):
|
||||||
"message": "Target tile reached!"
|
"message": "Target tile reached!"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check all conditions after move
|
|
||||||
check_conditions()
|
check_conditions()
|
||||||
|
|
||||||
func check_conditions():
|
func check_conditions():
|
||||||
# This allows for custom condition checking beyond the standard events
|
|
||||||
|
|
||||||
# Check board cleared condition
|
# Check board cleared condition
|
||||||
if win_condition == Utils.WinConditionType.BOARD_CLEARED:
|
if win_condition == Utils.WinConditionType.BOARD_CLEARED:
|
||||||
|
|
@ -214,23 +201,16 @@ func check_conditions():
|
||||||
"message": "Board cleared of enemy pieces!"
|
"message": "Board cleared of enemy pieces!"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Update the UI with current progress
|
|
||||||
emit_signal("condition_progress_updated", condition_progress)
|
emit_signal("condition_progress_updated", condition_progress)
|
||||||
|
|
||||||
func count_enemy_pieces() -> int:
|
func count_enemy_pieces() -> int:
|
||||||
var count = 0
|
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
|
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 y in range(chess_game.boardYSize):
|
||||||
for x in range(chess_game.boardXSize):
|
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:
|
if piece != null and piece.Item_Color == enemy_color:
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue