extends Node3D


var owner_placeholder: CharacterBody3D = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	$Body/Armature/Skeleton3D.physical_bones_start_simulation()
	owner_placeholder = _get_owner()
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass


func _on_head_collision_body_part_hit(dam: Variant) -> void:
	#if owner_placeholder.has_method("take_damage"):
	if owner_placeholder:
		owner_placeholder.take_damage(dam)
	pass # Replace with function body.

func _hit_detected(dam: Variant) -> void:
	print("hit detected")
	if owner_placeholder:
		owner_placeholder.take_damage(dam)

func _get_owner() -> CharacterBody3D:
	var owner_placeholder := find_parent("PlayerPlaceholder*")
	return owner_placeholder

func die():
	for child in $Body/Armature/Skeleton3D/PhysicalBoneSimulator3D.get_children():
		if child is PhysicalBone3D:
			child.collision_layer = 1
			child.collision_mask = 1
	$Body/Armature/Skeleton3D.physical_bones_stop_simulation()
	$Body/Armature/Skeleton3D/PhysicalBoneSimulator3D.physical_bones_start_simulation()
	
func make_invisible():
	$Body/Armature/Skeleton3D/Alpha_Joints.set_layer_mask_value(1, false)
	$Body/Armature/Skeleton3D/Alpha_Surface.set_layer_mask_value(1, false)
	$Body/Armature/Skeleton3D/Alpha_Joints.set_layer_mask_value(2, true)
	$Body/Armature/Skeleton3D/Alpha_Surface.set_layer_mask_value(2, true)