class_name FieryCapeCard extends Card var previous_position: String = "" var fire_tiles: Array[String] = [] func _init(): super._init() cardName = "Fiery Cape" rank = Rank.RANK_2 effectType = EffectType.PIECE_EFFECT description = "The tile behind the attached peice is on fire, all peices on the tile are captured" duration = 5 # Card effect lasts 3 turns unitWhitelist = ["Pawn", "Bishop", "Queen", "King", "Rook", "Knight"] func apply_effect(target_piece = null, board_flow = null, game_state = null): if !super.apply_effect(target_piece, board_flow, game_state): return false # Store the current position as previous position previous_position = target_piece.get_parent().name setup_persistent_effect(game_state) return true func setup_persistent_effect(game_state): if !game_state.is_connected("turn_changed", on_turn_changed): game_state.connect("turn_changed", on_turn_changed) func on_turn_changed(): if !attached_piece || remaining_turns <= 0: return var piece = attached_piece var board_flow = stored_board_flow var current_pos = piece.get_parent().name # If the piece has moved, place fire tiles if current_pos != previous_position: var current_coords = current_pos.split("-") var prev_coords = previous_position.split("-") var current_x = int(current_coords[0]) var current_y = int(current_coords[1]) var prev_x = int(prev_coords[0]) var prev_y = int(prev_coords[1]) # Calculate all positions between previous and current (excluding current) var positions_to_mark = [] var dx = sign(current_x - prev_x) var dy = sign(current_y - prev_y) var x = prev_x var y = prev_y # Start with the previous position positions_to_mark.append(previous_position) # Add intermediate positions while (x + dx != current_x || y + dy != current_y): x += dx y += dy positions_to_mark.append(str(x) + "-" + str(y)) # Place fire tiles var tile_owner = Tile.TileOwner.PLAYER if piece.Item_Color == 0 else Tile.TileOwner.ENEMY # only place on last tile var pos = positions_to_mark[positions_to_mark.size() - 1] var container = board_flow.get_node(pos) as PieceContainer if container: var is_white = (int(pos.split("-")[0]) + int(pos.split("-")[1])) % 2 == 0 var fire_tile = FireWallTile.new(container, is_white, 2, tile_owner) board_flow.get_parent().tileManager.add_tile(pos, fire_tile) fire_tiles.append(pos) previous_position = current_pos func remove_effect(): if attached_piece: var game_state = stored_game_state if game_state.is_connected("turn_changed", on_turn_changed): game_state.disconnect("turn_changed", on_turn_changed) super.remove_effect()