Fixed turn transitioning
This commit is contained in:
parent
63ab8605d0
commit
3d86f9c42e
9 changed files with 136 additions and 39 deletions
|
|
@ -32,7 +32,7 @@ func initializeStartingDeck():
|
|||
deck.append(ExplosiveBootsCard.new())
|
||||
deck.append(DoubleTimeCard.new())
|
||||
# deck.append(DrunkDrivingCard.new())
|
||||
# deck.append(SupernovaCard.new())
|
||||
deck.append(SupernovaCard.new())
|
||||
|
||||
func initializeStartingBank():
|
||||
# sample
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ var areas: PackedStringArray
|
|||
var specialArea: PackedStringArray
|
||||
var gamecheckMate: bool = false
|
||||
var gamedraw: bool = false
|
||||
var hasMoved: bool = false
|
||||
var currentlyMovingPiece = null
|
||||
var p1Points: int = 0
|
||||
var p2Points: int = 0
|
||||
|
|
@ -582,7 +581,6 @@ func executeMove(targetLocation: String) -> void:
|
|||
sourceContainer.remove_piece(true)
|
||||
targetContainer.set_piece(piece)
|
||||
|
||||
hasMoved = true
|
||||
currentlyMovingPiece = piece
|
||||
resetHighlights()
|
||||
if winConditionManager:
|
||||
|
|
@ -608,7 +606,6 @@ func is_tile_reached(location: String, piece_name: String = "") -> bool:
|
|||
# Turn = 1 if Turn == 0 else 0
|
||||
# updateTurnIndicator()
|
||||
# resetHighlights()
|
||||
# hasMoved = false
|
||||
# currentlyMovingPiece = null
|
||||
# emit_signal("turn_changed")
|
||||
|
||||
|
|
@ -619,15 +616,16 @@ func resolveMoveEffects() -> void:
|
|||
togglePieceChessEffect()
|
||||
selectedNode = ""
|
||||
resetHighlights()
|
||||
hasMoved = false
|
||||
currentlyMovingPiece = null
|
||||
check_captured_pieces_conditions()
|
||||
emit_signal("turn_changed")
|
||||
Turn = 1 if Turn == 0 else 0
|
||||
updateTurnIndicator()
|
||||
|
||||
func endTurn() -> void:
|
||||
print("turn_changed")
|
||||
emit_signal("turn_changed")
|
||||
Turn = 1 if Turn == 0 else 0
|
||||
updateTurnIndicator()
|
||||
if (isPlayerTurn()):
|
||||
updateEffectDurations()
|
||||
check_captured_pieces_conditions()
|
||||
|
||||
|
||||
func togglePieceChessEffect() -> void:
|
||||
|
|
@ -754,9 +752,9 @@ func updatePointsAndCapture(capturedPiece: Pawn, animate: bool = true) -> void:
|
|||
# Player captured an enemy piece
|
||||
print("winConditionManager and capturedPiece.Item_Color == 1")
|
||||
if winConditionManager and capturedPiece.Item_Color == 1: # Enemy piece (black)
|
||||
print("Player captured an enemy piece ")
|
||||
winConditionManager.on_piece_captured(capturedPiece)
|
||||
# captured_pieces_this_turn.append(capturedPiece.duplicate(true))
|
||||
# winConditionManager.on_piece_captured(capturedPiece)
|
||||
captured_pieces_this_turn.append(capturedPiece)
|
||||
print("Player captured an enemy piece ", captured_pieces_this_turn)
|
||||
|
||||
else: # Enemy's turn
|
||||
p2Points += capturedPiece.Points
|
||||
|
|
@ -767,12 +765,12 @@ func updatePointsAndCapture(capturedPiece: Pawn, animate: bool = true) -> void:
|
|||
# recover_cards_from_player_piece(capturedPiece)
|
||||
|
||||
# Add to player pieces lost array for loss condition checking
|
||||
# player_pieces_lost_this_turn.append(capturedPiece.duplicate(true))
|
||||
|
||||
if winConditionManager and capturedPiece.Item_Color == 0: # Player piece (white)
|
||||
player_pieces_lost_this_turn.append(capturedPiece)
|
||||
recover_cards_from_player_piece(capturedPiece)
|
||||
print("ENemy captured an player piece ")
|
||||
winConditionManager.on_piece_lost(capturedPiece)
|
||||
print("ENemy captured an player piece ", player_pieces_lost_this_turn)
|
||||
# winConditionManager.on_piece_lost(capturedPiece)
|
||||
|
||||
|
||||
if capturedPiece.name == "King":
|
||||
|
|
@ -787,13 +785,11 @@ func check_captured_pieces_conditions():
|
|||
if winConditionManager:
|
||||
winConditionManager.on_piece_captured(piece)
|
||||
print(captured_pieces_this_turn)
|
||||
captured_pieces_this_turn = []
|
||||
# Process captured player pieces (possible loss condition)
|
||||
for piece in player_pieces_lost_this_turn:
|
||||
if winConditionManager:
|
||||
winConditionManager.on_piece_lost(piece)
|
||||
print(player_pieces_lost_this_turn)
|
||||
player_pieces_lost_this_turn = []
|
||||
|
||||
func _on_win_condition_met(condition_data):
|
||||
print("Win condition met: ", condition_data)
|
||||
|
|
@ -804,6 +800,9 @@ func _on_win_condition_met(condition_data):
|
|||
"success": true,
|
||||
"condition": condition_data
|
||||
})
|
||||
if stateMachine:
|
||||
stateMachine.transitionToNextState(Constants.CLEANUP, {"endCondition": "win_condition_met"})
|
||||
|
||||
# endRound()
|
||||
|
||||
func _on_loss_condition_met(condition_data):
|
||||
|
|
@ -815,6 +814,8 @@ func _on_loss_condition_met(condition_data):
|
|||
"success": false,
|
||||
"condition": condition_data
|
||||
})
|
||||
if stateMachine:
|
||||
stateMachine.transitionToNextState(Constants.CLEANUP, {"endCondition": "win_condition_met"})
|
||||
# endRound()
|
||||
|
||||
func animatePieceCapture(capturedPiece: Pawn) -> void:
|
||||
|
|
|
|||
|
|
@ -374,9 +374,10 @@ func generate_chess_data(node):
|
|||
elif x == 1:
|
||||
fen += pawn_string + "/"
|
||||
# elif x == height - 3:
|
||||
# for y in unit_string.length() - 1:
|
||||
# fen += "*"
|
||||
# fen += "1/"
|
||||
# fen += "u"
|
||||
# # for y in unit_string.length() - 1:
|
||||
# # fen += "*"
|
||||
# fen += "u/"
|
||||
else:
|
||||
fen += str(unit_string.length()) + "/"
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ func _on_turn_changed():
|
|||
|
||||
func on_piece_captured(piece):
|
||||
print("on_piece_captured ISEnemy ", piece)
|
||||
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 == 1 else 0)
|
||||
print("on_piece_captured ISEnemy ", is_enemy_piece)
|
||||
if is_enemy_piece:
|
||||
captured_pieces.append(piece)
|
||||
|
|
@ -139,7 +139,7 @@ func on_piece_captured(piece):
|
|||
check_conditions()
|
||||
|
||||
func on_piece_lost(piece):
|
||||
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 == 1 else 1)
|
||||
print("on_piece_lost isPlayer ", is_player_piece)
|
||||
|
||||
if is_player_piece:
|
||||
|
|
|
|||
|
|
@ -3,4 +3,6 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
|
|||
func enter(_previous: String, _data := {}) -> void:
|
||||
print("ENTERING STATE ", Constants.TILE_EFFECTS)
|
||||
game.applyTileEffects()
|
||||
|
||||
game.endTurn()
|
||||
finished.emit(Constants.EVALUATE_POSITION)
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
extends "res://Systems/StateMachine/ChessGameState.gd"
|
||||
|
||||
func enter(_previous: String, data := {}) -> void:
|
||||
print("ENTERING STATE ", Constants.CLEANUP)
|
||||
game.endTurn()
|
||||
print("ENTERING STATE ", Constants.CLEANUP, data)
|
||||
|
||||
if "endCondition" in data:
|
||||
finished.emit(Constants.ROUND_END)
|
||||
|
|
|
|||
|
|
@ -2,11 +2,108 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
|
|||
|
||||
func enter(_previous: String, _data := {}) -> void:
|
||||
print("ENTERING STATE ", Constants.EVALUATE_POSITION)
|
||||
if game.isCheckmate():
|
||||
game.endGame("checkmate")
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "checkmate"})
|
||||
elif game.isDraw():
|
||||
game.endGame("draw")
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "draw"})
|
||||
else:
|
||||
|
||||
# Check if WinConditionManager exists
|
||||
if !game.winConditionManager:
|
||||
print("Warning: WinConditionManager not initialized")
|
||||
finished.emit(Constants.CLEANUP)
|
||||
return
|
||||
# Don't rely on the signal - directly check captured pieces here
|
||||
var win_condition_met = check_win_conditions()
|
||||
var loss_condition_met = check_loss_conditions()
|
||||
|
||||
# Only proceed to CLEANUP if no win/loss conditions were met
|
||||
if !win_condition_met and !loss_condition_met:
|
||||
finished.emit(Constants.CLEANUP)
|
||||
|
||||
# Check all possible win conditions
|
||||
func check_win_conditions() -> bool:
|
||||
match game.winConditionManager.win_condition:
|
||||
Utils.WinConditionType.CAPTURE_UNIT:
|
||||
# Directly check if king/target unit was captured
|
||||
var target_unit = game.winConditionManager.win_condition_data.get("unit", "King")
|
||||
|
||||
for piece in game.captured_pieces_this_turn:
|
||||
if piece.name == target_unit and piece.Item_Color == (1 if game.Turn == 0 else 0):
|
||||
# Found captured target piece - win condition met!
|
||||
var condition_data = {
|
||||
"type": Utils.WinConditionType.CAPTURE_UNIT,
|
||||
"message": "Enemy " + target_unit + " captured!"
|
||||
}
|
||||
game.winConditionManager.emit_signal("win_condition_met", condition_data)
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "target_captured"})
|
||||
return true
|
||||
game.captured_pieces_this_turn = []
|
||||
Utils.WinConditionType.BOARD_CLEARED:
|
||||
var remaining_enemy_pieces = game.winConditionManager.count_enemy_pieces()
|
||||
if remaining_enemy_pieces <= 0:
|
||||
var condition_data = {
|
||||
"type": Utils.WinConditionType.BOARD_CLEARED,
|
||||
"message": "Board cleared of enemy pieces!"
|
||||
}
|
||||
game.winConditionManager.emit_signal("win_condition_met", condition_data)
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "board_cleared"})
|
||||
return true
|
||||
|
||||
Utils.WinConditionType.TURN_NUMBER:
|
||||
var target_turn = game.winConditionManager.win_condition_data.get("target_turn", 0)
|
||||
if game.winConditionManager.turn_count >= target_turn:
|
||||
var condition_data = {
|
||||
"type": Utils.WinConditionType.TURN_NUMBER,
|
||||
"message": "Turn limit reached!"
|
||||
}
|
||||
game.winConditionManager.emit_signal("win_condition_met", condition_data)
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "turn_limit_reached"})
|
||||
return true
|
||||
|
||||
Utils.WinConditionType.TILE_REACHED:
|
||||
var target_tiles = game.winConditionManager.target_tiles
|
||||
var required_unit = game.winConditionManager.win_condition_data.get("unit", "")
|
||||
var all_targets_reached = true
|
||||
|
||||
for tile_loc in target_tiles:
|
||||
if !game.is_tile_reached(tile_loc, required_unit):
|
||||
all_targets_reached = false
|
||||
break
|
||||
|
||||
if all_targets_reached and target_tiles.size() > 0:
|
||||
var condition_data = {
|
||||
"type": Utils.WinConditionType.TILE_REACHED,
|
||||
"message": "All target tiles reached!"
|
||||
}
|
||||
game.winConditionManager.emit_signal("win_condition_met", condition_data)
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "tile_reached"})
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
# Check all possible loss conditions
|
||||
func check_loss_conditions() -> bool:
|
||||
match game.winConditionManager.loss_condition:
|
||||
Utils.LossConditionType.UNIT_LOST:
|
||||
# Directly check if king/target unit was lost
|
||||
var target_unit = game.winConditionManager.loss_condition_data.get("unit", "King")
|
||||
|
||||
for piece in game.player_pieces_lost_this_turn:
|
||||
if piece.name == target_unit and piece.Item_Color == (0 if game.Turn == 0 else 1):
|
||||
# Found lost target piece - loss condition met!
|
||||
var condition_data = {
|
||||
"type": Utils.LossConditionType.UNIT_LOST,
|
||||
"message": "Your " + target_unit + " was captured!"
|
||||
}
|
||||
game.winConditionManager.emit_signal("loss_condition_met", condition_data)
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "unit_lost"})
|
||||
return true
|
||||
game.player_pieces_lost_this_turn = []
|
||||
Utils.WinConditionType.TURN_NUMBER:
|
||||
var turn_limit = game.winConditionManager.loss_condition_data.get("turn_limit", 0)
|
||||
if game.winConditionManager.turn_count >= turn_limit:
|
||||
var condition_data = {
|
||||
"type": Utils.WinConditionType.TURN_NUMBER,
|
||||
"message": "Turn limit exceeded!"
|
||||
}
|
||||
game.winConditionManager.emit_signal("loss_condition_met", condition_data)
|
||||
finished.emit(Constants.CLEANUP, {"endCondition": "turn_limit_exceeded"})
|
||||
return true
|
||||
|
||||
return false
|
||||
|
|
@ -201,7 +201,6 @@ func handleMovement(location: String, generated: bool = false) -> void:
|
|||
moves_remaining.erase(piece_id)
|
||||
finished.emit(Constants.POST_MOVE)
|
||||
else:
|
||||
game.hasMoved = false
|
||||
game.currentlyMovingPiece = null
|
||||
# game.applyTileEffects()
|
||||
# finished.emit(Constants.POST_MOVE)
|
||||
|
|
@ -291,14 +290,15 @@ func handleCapture(node: PieceContainer, generated: bool = false) -> void:
|
|||
|
||||
func handleCaptureMovement(node: PieceContainer) -> void:
|
||||
var source_container = game.get_node("Flow/" + game.selectedNode) as PieceContainer
|
||||
|
||||
print("handleCaptureMovement")
|
||||
|
||||
var moving_piece = source_container.get_piece()
|
||||
var captured_piece = node.get_piece()
|
||||
|
||||
if moving_piece && captured_piece:
|
||||
await game.animatePieceCapture(captured_piece)
|
||||
game.updatePointsAndCapture(captured_piece, false)
|
||||
print("handleCapturingMovement")
|
||||
# await game.animatePieceCapture(captured_piece)
|
||||
game.updatePointsAndCapture(captured_piece, true)
|
||||
node.animate_movement(source_container, moving_piece);
|
||||
var tile = game.tileManager.get_tile(node.name)
|
||||
if tile:
|
||||
|
|
@ -351,6 +351,5 @@ func executeMove(targetLocation: String) -> void:
|
|||
sourceContainer.remove_piece(true)
|
||||
targetContainer.set_piece(piece)
|
||||
|
||||
game.hasMoved = true
|
||||
game.currentlyMovingPiece = piece
|
||||
game.resetHighlights()
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
|
|||
func enter(_previous: String, _data := {}) -> void:
|
||||
print("ENTERING STATE ", Constants.POST_MOVE)
|
||||
|
||||
if (game.isPlayerTurn()):
|
||||
game.updateEffectDurations()
|
||||
# if (game.isPlayerTurn()):
|
||||
# game.deckManager.updateCardDurations()
|
||||
finished.emit(Constants.TILE_EFFECTS)
|
||||
|
|
|
|||
Loading…
Reference in a new issue