From 5d04deae9fd8f1ba041db875ebe5da4ac4402864 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sat, 8 Mar 2025 20:10:47 -0600 Subject: [PATCH] fixed eice selection bug with invalid location --- Systems/Game/Map/MapGenerator.gd | 2 +- Systems/StateMachine/GameStates/Movement.gd | 26 +++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Systems/Game/Map/MapGenerator.gd b/Systems/Game/Map/MapGenerator.gd index 3c5628d..3807fd7 100644 --- a/Systems/Game/Map/MapGenerator.gd +++ b/Systems/Game/Map/MapGenerator.gd @@ -198,7 +198,7 @@ func _get_random_room_type(level, total_levels): return Utils.RoomType.BOSS elif roll < boss_chance + shop_chance: return Utils.RoomType.SHOP - elif roll < boss_chance + shop_chance + event_chance: + elif roll < boss_chance + shop_chance + event_chance and level > 5: return Utils.RoomType.EVENT else: return Utils.RoomType.NORMAL diff --git a/Systems/StateMachine/GameStates/Movement.gd b/Systems/StateMachine/GameStates/Movement.gd index 2048d83..f792b09 100644 --- a/Systems/StateMachine/GameStates/Movement.gd +++ b/Systems/StateMachine/GameStates/Movement.gd @@ -2,6 +2,7 @@ extends "res://Systems/StateMachine/ChessGameState.gd" var moves_remaining = {} var multiMoving = "" +var last_selected = null func _ready() -> void: print("Movement state ready") @@ -16,7 +17,7 @@ func _setup_movement_modifiers() -> void: func enter(_previous: String, _data := {}) -> void: print("ENTERING STATE ", Constants.MOVEMENT, " ", game.currentPlayer) - + last_selected = null _setup_movement_modifiers() if !game.boardContainer.is_connected("tile_pressed", handleMovement): @@ -75,9 +76,16 @@ func handleMovement(location: String, generated: bool = false) -> void: # 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) + print("HANDLING MOVEMENT ", location, " | ", last_selected, " | ", game.selectedNode) var node = game.get_node("Flow/" + location) as PieceContainer - + var prev_last_selected = last_selected + if !generated : + if last_selected == null: + last_selected = location + else: + if game.selectedNode == location: + last_selected = null + var moves = null; # Only try to get piece if we have a selected node if game.selectedNode == "": # print("No Node") @@ -86,12 +94,20 @@ func handleMovement(location: String, generated: bool = false) -> void: if piece != null && piece.Item_Color == game.Turn: game.selectedNode = location game.getMovableAreas() + last_selected = location return + # else: + # moves = (game.get_node("Flow/" + game.selectedNode) as PieceContainer).get_piece().getValidMoves(game.boardContainer, location) var sourcePiece = node.get_piece() - var moves = null; if sourcePiece: moves = sourcePiece.getValidMoves(game.boardContainer, location) + + if !(location == game.selectedNode): + if !generated and moves != null and !moves.regular_moves.has(game.selectedNode) and !moves.special_moves.has(game.selectedNode): + last_selected = prev_last_selected + print("Invalid Choice") + return # Now we know we have a selected node, get its piece var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer @@ -144,12 +160,12 @@ func handleMovement(location: String, generated: bool = false) -> void: return return elif moves != null and !moves.regular_moves.has(game.selectedNode) and !moves.special_moves.has(game.selectedNode): - # print(moves, sourcePiece.Item_Color, piece.Item_Color) if sourcePiece and sourcePiece.Item_Color == piece.Item_Color: # print("Set Location*************") game.selectedNode = location game.getMovableAreas() return + print("Movemnet ", moves) if isCastlingMove(node, location): handleCastling(node, generated) finished.emit(Constants.POST_MOVE)