class_name RockProjectile
extends ProjectileBaseTwo

func _ready():
	lifetime_timer = Timer.new()
	add_child(lifetime_timer)
	lifetime_timer.one_shot = true
	lifetime_timer.wait_time = stats.lifetime
	lifetime_timer.connect("timeout", _on_lifetime_timeout)
	lifetime_timer.start()

	emit_signal("on_spawned", self)
	connect("body_entered", _on_body_entered)

func _physics_process(delta):
	position += direction * stats.speed * delta

func _on_body_entered(body):
	if body.is_in_group("enemies"):
		body.take_damage(stats.damage)

		## Check if the projectile is piercing
		if not get_stat("pierce_count"):
			# If not piercing, destroy the projectile
			destroy()
		else:
			# If piercing, reduce the pierce count
			set_stat("pierce_count", get_stat("pierce_count") - 1)

func _on_lifetime_timeout():
	super._on_lifetime_timeout()
