extends "res://scripts/Tower.gd"
## Tower Defense — Lecture 27 (Final)
##
## Instant-hit tower that deals damage directly to target
## without projectiles. Cheaper and faster attacks.

# ============================================================
# CONSTANTS
# ============================================================

func _ready() -> void:
	tower_cost = 100
	tower_damage = 15
	tower_range = 8.0
	attack_cooldown = 1.0
	
	super._ready()


# ============================================================
# ATTACK
# ============================================================

func _perform_attack() -> void:
	if not current_target:
		return
	
	# Deal instant damage
	current_target.take_damage(tower_damage)
	
	# Visual feedback: create beam effect
	_create_beam_effect()


func _create_beam_effect() -> void:
	# Simple line to show attack
	var cylinder := CylinderMesh.new()
	cylinder.height = global_position.distance_to(current_target.global_position)
	cylinder.top_radius = 0.05
	cylinder.bottom_radius = 0.05
	
	var line := MeshInstance3D.new()
	line.mesh = cylinder
	
	# Position line between tower and target
	line.global_position = global_position.lerp(current_target.global_position, 0.5)
	line.look_at(current_target.global_position, Vector3.UP)
	line.rotate_object_local(Vector3.RIGHT, PI / 2)
	
	# Set color
	var material := StandardMaterial3D.new()
	material.albedo_color = Color.YELLOW
	material.emission_enabled = true
	material.emission = Color.YELLOW
	line.set_surface_override_material(0, material)
	
	get_tree().root.add_child(line)
	
	# Remove after short delay
	await get_tree().create_timer(0.1).timeout
	line.queue_free()
