From e51fb4db20585002210ebe8c16c27f005b388aa0 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Fri, 31 Jan 2025 19:40:50 -0600 Subject: [PATCH] fixed multi move gltiches, added hopscotch card --- Systems/Cards/Doubletime.gd | 1 - Systems/Cards/Hopscotch.gd | 24 +++++++ Systems/DeckManager.gd | 4 +- Systems/Game/ChessGame.gd | 7 +- Systems/StateMachine/GameStates/Movement.gd | 71 +++++++++++++-------- 5 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 Systems/Cards/Hopscotch.gd diff --git a/Systems/Cards/Doubletime.gd b/Systems/Cards/Doubletime.gd index f5bd143..610a884 100644 --- a/Systems/Cards/Doubletime.gd +++ b/Systems/Cards/Doubletime.gd @@ -20,6 +20,5 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null): if !super.apply_effect(target_piece, board_flow, game_state): return false - # Logic to allow second move would be implemented in Game.gd attached_piece = target_piece return true \ No newline at end of file diff --git a/Systems/Cards/Hopscotch.gd b/Systems/Cards/Hopscotch.gd new file mode 100644 index 0000000..4621a3a --- /dev/null +++ b/Systems/Cards/Hopscotch.gd @@ -0,0 +1,24 @@ +class_name HopscotchCard extends Card + +func _init(): + super._init() + # id = Utils.generate_guid() + cardName = "HopScotch" + rank = Rank.RANK_0 + effectType = EffectType.MOVEMENT_MODIFIER + description = "Peice can move 5 times per turn" + duration = 2 # Lasts for 2 turns + unitWhitelist = [] + +func modify_moves() -> Dictionary: + return { + "extra_moves": 5, + "move_multiplier": 1 + } + +func apply_effect(target_piece = null, board_flow = null, game_state = null): + if !super.apply_effect(target_piece, board_flow, game_state): + return false + + attached_piece = target_piece + return true \ No newline at end of file diff --git a/Systems/DeckManager.gd b/Systems/DeckManager.gd index 195ea81..d16cbb8 100644 --- a/Systems/DeckManager.gd +++ b/Systems/DeckManager.gd @@ -2,6 +2,7 @@ extends Node class_name DeckManager const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd") +const HopscotchCard = preload("res://Systems/Cards/Hopscotch.gd") var deck: Array = [] @@ -22,8 +23,9 @@ func _init(): initializeStartingDeck() func initializeStartingDeck(): - for i in range(10): + for i in range(9): deck.append(DoubleTimeCard.new()) + deck.append(HopscotchCard.new()) shuffleDeck() drawStartingHand() diff --git a/Systems/Game/ChessGame.gd b/Systems/Game/ChessGame.gd index 01c9330..851ee61 100644 --- a/Systems/Game/ChessGame.gd +++ b/Systems/Game/ChessGame.gd @@ -357,8 +357,7 @@ func executeMove(targetLocation: String) -> void: currentlyMovingPiece = piece resetHighlights() -func resolveMoveEffects() -> void: - print("resolveMoveEffects", currentlyMovingPiece) +func togglePieceChessEffect() -> void: var piece = currentlyMovingPiece if piece.name == "Pawn": if piece.Double_Start: @@ -368,6 +367,10 @@ func resolveMoveEffects() -> void: piece.Castling = false elif piece.name == "Rook": piece.Castling = false + +func resolveMoveEffects() -> void: + print("resolveMoveEffects", currentlyMovingPiece) + togglePieceChessEffect() selectedNode = "" Turn = 1 if Turn == 0 else 0 diff --git a/Systems/StateMachine/GameStates/Movement.gd b/Systems/StateMachine/GameStates/Movement.gd index 699164a..f33892b 100644 --- a/Systems/StateMachine/GameStates/Movement.gd +++ b/Systems/StateMachine/GameStates/Movement.gd @@ -1,7 +1,7 @@ extends "res://Systems/StateMachine/ChessGameState.gd" var moves_remaining = {} -var multiMoving = false +var multiMoving = "" func _ready() -> void: print("Movement state ready") @@ -16,10 +16,10 @@ func enter(_previous: String, _data := {}) -> void: game.getMovableAreas() moves_remaining.clear() - multiMoving = false + multiMoving = "" for piece_id in game.deckManager.attached_cards: var card = game.deckManager.attached_cards[piece_id] - if card is DoubleTimeCard: + if card.effectType == Card.EffectType.MOVEMENT_MODIFIER: var effects = card.modify_moves() moves_remaining[piece_id] = effects.get("extra_moves", 0) + 1 @@ -28,18 +28,33 @@ func exit() -> void: game.boardContainer.disconnect("tile_pressed", handleMovement) func handleMovement(location: String) -> void: - # print("HANDLING MOVEMENT ", location) + # we need to prevent swapping of focus between peices after the double move process has started + # maybe once u start nmoving a peice global stat var is set + # and any moving peice needs ot match that + print("HANDLING MOVEMENT ", location, " | ", multiMoving, " | ", game.selectedNode) var node = game.get_node("Flow/" + location) + var piece = game.get_node("Flow/" + game.selectedNode).get_child(0) + var piece_id = piece.get_instance_id() + print(piece_id) + var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1 + + + if multiMoving.length() > 0: + + if node.get_child_count() > 0 and is_instance_valid(node.get_child(0)): + var attempting_piece = node.get_child(0) + print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving) + # Only block if it's a different piece of the same color + if str(attempting_piece.get_instance_id()) != multiMoving and attempting_piece.Item_Color == game.Turn: + print("early return - can't select different piece of same color during multi-move") + return if game.selectedNode == "": if node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn: + print("SELECTED NODE ", location) game.selectedNode = location game.getMovableAreas() return - var piece = game.get_node("Flow/" + game.selectedNode).get_child(0) - var piece_id = piece.get_instance_id() - var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1 - # print(moves_remaining, " | ", piece_id, " | ",is_multi_moving) var consumeMove = true; @@ -53,7 +68,7 @@ func handleMovement(location: String) -> void: # finished.emit(Constants.POST_MOVE) if game.selectedNode == location: - if !is_multi_moving and !multiMoving: + if !is_multi_moving and multiMoving == "": print("CLEAR SELECTION*************") game.clearSelection() elif isCastlingMove(node, location): @@ -64,7 +79,7 @@ func handleMovement(location: String) -> void: handleEnPassant(node) # Reselect piece elif isReselectMove(node): - if !is_multi_moving and !multiMoving: + if !is_multi_moving and multiMoving == "": print("RESELECT SELECTION*************") game.selectedNode = location game.getMovableAreas() @@ -80,24 +95,23 @@ func handleMovement(location: String) -> void: if game.isValidMove(location): # executeMove(location) handleRegularMove(node, consumeMove) - if consumeMove: - multiMoving = false - game.clearSelection() - finished.emit(Constants.POST_MOVE) - else: - multiMoving = true + if consumeMove: + multiMoving = "" + game.clearSelection() + print("Consuming move") + finished.emit(Constants.POST_MOVE) + elif is_multi_moving: + game.selectedNode = location # Keep the piece selected for another move + multiMoving = str(piece_id) - game.selectedNode = location # Keep the piece selected for another move - - # game.selectedNode = "" - game.hasMoved = false - game.currentlyMovingPiece = null - game.getMovableAreas() - print("ANOTHER MOVE") - game.resetHighlights() - if game.selectedNode != "": - game.getMovableAreas() - # finished.emit(Constants.POST_MOVE) + # game.selectedNode = "" + game.hasMoved = false + game.currentlyMovingPiece = null + print("ANOTHER MOVE") + game.resetHighlights() + if game.selectedNode != "": + game.getMovableAreas() + # finished.emit(Constants.POST_MOVE) @@ -173,6 +187,9 @@ func handleRegularMove(node: Node, consume: bool) -> void: if consume: game.currentlyMovingPiece = piece game.resolveMoveEffects() + else: + game.currentlyMovingPiece = piece + game.togglePieceChessEffect();