class_name DrunkDrivingCard extends Card func _init(): super._init() cardName = "Drunk Driving" rank = Rank.RANK_1 duration = 1 effectType = EffectType.SPECIAL_ACTION description = "Force peice to careen towards the enemy side, capturing all pieces in its path" unitWhitelist = ["Rook", "Queen"] func apply_effect(target_piece = null, board_flow = null, game_state = null): if !super.apply_effect(target_piece, board_flow, game_state): return false if !target_piece or !board_flow or !game_state: return false # Get current container and position var current_container = target_piece.get_parent() as PieceContainer var current_pos = current_container.name.split("-") var current_x = int(current_pos[0]) var current_y = int(current_pos[1]) # Calculate target position var target_y = 7 if target_piece.Item_Color == 1 else 0 var y_direction = 1 if target_y > current_y else -1 # Generate tiles to check var tiles_to_check = [] var y = current_y + y_direction while y != target_y + y_direction: tiles_to_check.append(str(current_x) + "-" + str(y)) y += y_direction # Find final position (stop before any impassable tile) var final_y = target_y for tile_name in tiles_to_check: var tile = game_state.tileManager.get_tile(tile_name) if tile && !tile.passable: # Stop at the tile before this one var tile_y = int(tile_name.split("-")[1]) final_y = tile_y - y_direction break # Process pieces in path for tile_name in tiles_to_check: var tile_y = int(tile_name.split("-")[1]) # Only process tiles up to where we're stopping if (y_direction > 0 && tile_y > final_y) || (y_direction < 0 && tile_y < final_y): break var container = board_flow.get_node(tile_name) as PieceContainer if container.has_piece(): var piece_to_capture = container.get_piece() game_state.updatePoints(piece_to_capture) container.remove_piece() # Move piece to final position var final_container = board_flow.get_node(str(current_x) + "-" + str(final_y)) as PieceContainer # Important: Need to remove the piece from its current container first # AND keep a reference to it target_piece = current_container.get_piece() # Get reference before removing # current_container.remove_piece(true) # Remove from current container # final_container.set_piece(target_piece) # Set in new container final_container.animate_movement(current_container, target_piece) game_state.currentlyMovingPiece = target_piece burned = true game_state.resolveMoveEffects() game_state.stateMachine.transitionToNextState(Constants.POST_MOVE) return true